/**
 * Affiliate Onboarding System
 * Welcome sequence, tutorials, and best practices for new affiliates
 */

export interface OnboardingStep {
  id: string;
  title: string;
  description: string;
  content: string;
  videoUrl?: string;
  duration: number; // minutes
  completed: boolean;
}

export interface AffiliateOnboardingSequence {
  affiliateId: number;
  steps: OnboardingStep[];
  currentStep: number;
  completedAt?: Date;
  progress: number; // percentage
}

/**
 * Onboarding Steps Configuration
 */
export const ONBOARDING_STEPS: OnboardingStep[] = [
  {
    id: 'welcome',
    title: 'Welcome to CoinKrazy Affiliate Program',
    description: 'Get started with your affiliate journey',
    content: `
Welcome to the CoinKrazy Affiliate Program! 🎉

You're now part of a growing community of affiliates earning commissions by promoting CoinKrazy.

In this onboarding sequence, you'll learn:
- How to get started with your affiliate account
- Best practices for promoting CoinKrazy
- How to use marketing materials and assets
- Tips for maximizing your earnings
- How to track your performance

Let's get started!
    `,
    duration: 5,
    completed: false,
  },
  {
    id: 'account_setup',
    title: 'Set Up Your Affiliate Account',
    description: 'Configure your account settings and payment details',
    content: `
Setting Up Your Affiliate Account

1. **Affiliate Code**: Your unique code is: [AFFILIATE_CODE]
   - Share this code with your audience
   - Use it in your referral links
   - Track conversions with this code

2. **Payment Method**:
   - Add your payment details in Settings
   - Choose your preferred payout frequency
   - Verify your bank account

3. **Profile Information**:
   - Complete your affiliate profile
   - Add a profile picture
   - Write a bio about yourself

4. **Notification Preferences**:
   - Set up email notifications
   - Choose notification frequency
   - Select which events to track
    `,
    duration: 10,
    completed: false,
  },
  {
    id: 'promotion_strategies',
    title: 'Promotion Strategies & Best Practices',
    description: 'Learn proven strategies to maximize conversions',
    content: `
Top Promotion Strategies

1. **Email Marketing**:
   - Build an email list
   - Send personalized referral invites
   - Share exclusive offers
   - Track open rates and clicks

2. **Social Media**:
   - Share your referral link on Facebook, Twitter, Instagram
   - Create engaging posts about CoinKrazy
   - Use relevant hashtags
   - Engage with your followers

3. **Content Marketing**:
   - Write blog posts about CoinKrazy
   - Create YouTube reviews
   - Share gaming tips and strategies
   - Provide value to your audience

4. **Community Engagement**:
   - Participate in gaming forums
   - Join Discord communities
   - Answer questions about CoinKrazy
   - Build trust with your audience

5. **Paid Advertising**:
   - Use Google Ads
   - Facebook/Instagram ads
   - TikTok promotions
   - Set realistic budgets

Pro Tips:
✓ Be authentic in your promotions
✓ Focus on benefits, not just features
✓ Build relationships with your audience
✓ Test different strategies
✓ Track what works best
    `,
    duration: 15,
    completed: false,
  },
  {
    id: 'marketing_materials',
    title: 'Marketing Materials & Assets',
    description: 'Access ready-to-use promotional materials',
    content: `
Marketing Materials Available

1. **Banners**:
   - 728x90 (Leaderboard)
   - 300x250 (Medium Rectangle)
   - 160x600 (Wide Skyscraper)
   - 1200x628 (Social Media)

2. **Email Templates**:
   - Welcome email
   - Referral invitation
   - Bonus announcement
   - Contest promotion

3. **Landing Pages**:
   - Pre-built landing pages
   - Customizable templates
   - High-converting designs
   - Mobile-optimized

4. **Social Media Content**:
   - Instagram posts
   - Twitter tweets
   - Facebook posts
   - TikTok video ideas

5. **Video Assets**:
   - Product demo videos
   - Testimonial videos
   - How-to guides
   - Gameplay highlights

All materials are available in your Affiliate Dashboard under "Marketing Assets"
    `,
    duration: 10,
    completed: false,
  },
  {
    id: 'tracking_analytics',
    title: 'Tracking & Analytics',
    description: 'Monitor your performance and optimize campaigns',
    content: `
Understanding Your Analytics

1. **Dashboard Metrics**:
   - Total Clicks: How many people clicked your link
   - Conversions: How many signed up
   - Conversion Rate: Percentage of clicks that converted
   - Total Earnings: Your commission earnings

2. **Performance Reports**:
   - Daily/Weekly/Monthly reports
   - Source performance breakdown
   - Top performing campaigns
   - Trend analysis

3. **Optimization Tips**:
   - Focus on high-converting sources
   - A/B test different messages
   - Track which audiences respond best
   - Adjust your strategy based on data

4. **Tier Progression**:
   - Track your referral count
   - Monitor your tier status
   - See commission rate
   - View tier benefits

Access your analytics in the Affiliate Dashboard
    `,
    duration: 10,
    completed: false,
  },
  {
    id: 'commission_payouts',
    title: 'Commission & Payouts',
    description: 'Understand how you earn and get paid',
    content: `
How You Earn & Get Paid

1. **Commission Structure**:
   - Bronze (0-49 referrals): 5% commission
   - Silver (50-199 referrals): 10% commission
   - Gold (200-499 referrals): 15% commission
   - Platinum (500-999 referrals): 17.5% commission
   - Diamond (1000+ referrals): 20% commission

2. **Monthly Bonuses**:
   - Bronze: No bonus
   - Silver: 50 SC bonus
   - Gold: 200 SC bonus
   - Platinum: 500 SC bonus
   - Diamond: 1000 SC bonus

3. **Payout Schedule**:
   - Bronze: Monthly payouts
   - Silver: Weekly payouts
   - Gold: Bi-weekly payouts
   - Platinum: Weekly payouts
   - Diamond: Daily payouts

4. **Payout Methods**:
   - Bank transfer
   - PayPal
   - Cryptocurrency
   - Store credit

5. **Minimum Payout**:
   - Minimum: 100 SC
   - No maximum limit
   - Automatic processing
   - Instant notifications

Track your earnings in the Affiliate Dashboard
    `,
    duration: 10,
    completed: false,
  },
  {
    id: 'support_resources',
    title: 'Support & Resources',
    description: 'Get help and access additional resources',
    content: `
Support & Resources

1. **Help Center**:
   - FAQs
   - Video tutorials
   - Knowledge base
   - Troubleshooting guides

2. **Contact Support**:
   - Email: affiliates@coinkrazy.com
   - Live chat (available during business hours)
   - Discord community
   - Dedicated account manager (Diamond tier)

3. **Community**:
   - Join our affiliate Discord
   - Share strategies with other affiliates
   - Get tips and advice
   - Network with top performers

4. **Resources**:
   - Affiliate handbook
   - Best practices guide
   - Marketing templates
   - Video tutorials

5. **Contests & Incentives**:
   - Monthly contests
   - Bonus rewards
   - Leaderboard competitions
   - Special promotions

Don't hesitate to reach out if you have questions!
    `,
    duration: 10,
    completed: false,
  },
  {
    id: 'launch_campaign',
    title: 'Launch Your First Campaign',
    description: 'Start promoting and earning commissions',
    content: `
Ready to Launch Your Campaign?

1. **Choose Your Strategy**:
   - Email marketing
   - Social media
   - Content marketing
   - Paid advertising
   - Community engagement

2. **Prepare Your Materials**:
   - Download marketing assets
   - Customize with your style
   - Test your links
   - Set up tracking

3. **Start Promoting**:
   - Share your referral link
   - Post on social media
   - Send emails
   - Engage with your audience

4. **Monitor Performance**:
   - Check your dashboard daily
   - Track conversions
   - Monitor earnings
   - Adjust strategy as needed

5. **Optimize & Scale**:
   - Focus on what works
   - Test new strategies
   - Increase your reach
   - Aim for the next tier

Remember: Success takes time. Start small, test, learn, and scale!

Good luck! 🚀
    `,
    duration: 10,
    completed: false,
  },
];

/**
 * Get onboarding step by ID
 */
export function getOnboardingStep(id: string): OnboardingStep | undefined {
  return ONBOARDING_STEPS.find(step => step.id === id);
}

/**
 * Calculate onboarding progress
 */
export function calculateOnboardingProgress(completedSteps: number): number {
  return Math.round((completedSteps / ONBOARDING_STEPS.length) * 100);
}

/**
 * Get next onboarding step
 */
export function getNextOnboardingStep(currentStep: number): OnboardingStep | null {
  if (currentStep >= ONBOARDING_STEPS.length - 1) return null;
  return ONBOARDING_STEPS[currentStep + 1];
}

/**
 * Mark step as completed
 */
export function markStepAsCompleted(steps: OnboardingStep[], stepId: string): OnboardingStep[] {
  return steps.map(step =>
    step.id === stepId ? { ...step, completed: true } : step
  );
}

/**
 * Get onboarding email template
 */
export function getOnboardingEmailTemplate(affiliateName: string, affiliateCode: string): {
  subject: string;
  htmlContent: string;
} {
  return {
    subject: 'Welcome to CoinKrazy Affiliate Program! 🎉',
    htmlContent: `
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    body { font-family: Arial, sans-serif; background-color: #f5f5f5; }
    .container { max-width: 600px; margin: 0 auto; background-color: white; padding: 20px; border-radius: 8px; }
    .header { text-align: center; padding: 20px 0; border-bottom: 2px solid #6366f1; }
    .logo { font-size: 28px; font-weight: bold; color: #6366f1; }
    .content { padding: 20px 0; }
    .cta-button { display: inline-block; background-color: #6366f1; color: white; padding: 12px 30px; text-decoration: none; border-radius: 4px; margin: 20px 0; }
    .code-box { background-color: #f0f4ff; border-left: 4px solid #6366f1; padding: 15px; margin: 20px 0; font-family: monospace; }
    .footer { text-align: center; padding: 20px 0; border-top: 1px solid #e0e0e0; color: #666; font-size: 12px; }
  </style>
</head>
<body>
  <div class="container">
    <div class="header">
      <div class="logo">CoinKrazy</div>
    </div>
    
    <div class="content">
      <h2>Welcome, ${affiliateName}! 🎉</h2>
      
      <p>Congratulations on joining the CoinKrazy Affiliate Program!</p>
      
      <p>You're now part of a growing community of affiliates earning commissions by promoting CoinKrazy.</p>
      
      <h3>Your Affiliate Code</h3>
      <div class="code-box">
        ${affiliateCode}
      </div>
      
      <p>Use this code in your referral links and promotions to track your conversions and earnings.</p>
      
      <h3>What's Next?</h3>
      <ol>
        <li>Complete your onboarding tutorial (7 steps, ~60 minutes)</li>
        <li>Set up your payment details</li>
        <li>Download marketing materials</li>
        <li>Start promoting CoinKrazy</li>
        <li>Track your earnings in the dashboard</li>
      </ol>
      
      <center>
        <a href="https://coinkrazy.com/affiliate/onboarding" class="cta-button">Start Onboarding</a>
      </center>
      
      <h3>Key Benefits</h3>
      <ul>
        <li>Earn 5-20% commission on referrals</li>
        <li>Monthly bonuses up to 1000 SC</li>
        <li>Daily payouts for top affiliates</li>
        <li>Marketing materials provided</li>
        <li>Dedicated support</li>
      </ul>
      
      <p>If you have any questions, don't hesitate to reach out to our affiliate support team.</p>
      
      <p>Good luck! 🚀</p>
    </div>
    
    <div class="footer">
      <p>© 2026 CoinKrazy. All rights reserved.</p>
    </div>
  </div>
</body>
</html>
    `,
  };
}
