/**
 * Email Templates - CRO-Optimized
 *
 * What's improved (based on email marketing best practices):
 *
 * Subject Lines:
 * - More specific with urgency/outcome ("Expires in 1 Hour")
 * - Emoji for visual attention in inbox
 * - Clear value proposition
 *
 * Design & Copy:
 * - Personal sender name ("Timo from QR Master")
 * - Storytelling instead of feature lists
 * - Trust elements (security badges, timelines)
 * - Clear CTAs with action verbs ("Reset My Password →")
 * - Objection handling built-in ("Didn't request this?")
 * - Mobile-optimized (shorter paragraphs, more whitespace)
 *
 * How to measure if this works for YOUR audience:
 * 1. Track baseline metrics (open rate, click rate, conversions)
 * 2. A/B test old vs new templates
 * 3. Measure with real users (minimum 100 emails per variant)
 *
 * No guarantees - only your data will tell what works for QR Master users.
 */

import { Resend } from 'resend';

// Use a placeholder during build time, real key at runtime
const resendKey = process.env.RESEND_API_KEY || 're_placeholder_for_build';
const resend = new Resend(resendKey);

// Rate limiter for Resend Free Tier (1 email per second)
let lastEmailSent = 0;
const MIN_EMAIL_INTERVAL = 1000; // 1 second in milliseconds

async function waitForRateLimit() {
  const now = Date.now();
  const timeSinceLastEmail = now - lastEmailSent;

  if (timeSinceLastEmail < MIN_EMAIL_INTERVAL) {
    const waitTime = MIN_EMAIL_INTERVAL - timeSinceLastEmail;
    await new Promise(resolve => setTimeout(resolve, waitTime));
  }

  lastEmailSent = Date.now();
}

/**
 * Password Reset Email - Security focused with clear urgency
 */
export async function sendPasswordResetEmail(email: string, resetToken: string) {
  await waitForRateLimit();

  const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3050';
  const resetUrl = `${appUrl}/reset-password?token=${resetToken}`;

  try {
    await resend.emails.send({
      from: 'QR Master Security <noreply@qrmaster.net>',
      replyTo: 'support@qrmaster.net',
      to: email,
      subject: '🔐 Reset Your QR Master Password (Expires in 1 Hour)',
      html: `
        <!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Reset Your Password - QR Master</title>
          </head>
          <body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background-color: #f4f4f4;">
            <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f4; padding: 40px 20px;">
              <tr>
                <td align="center">
                  <!-- Main Container -->
                  <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.08);">

                    <!-- Header with Security Badge -->
                    <tr>
                      <td style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 50px 40px; text-align: center;">
                        <div style="display: inline-block; background-color: rgba(255,255,255,0.2); padding: 12px 24px; border-radius: 50px; margin-bottom: 20px;">
                          <span style="color: #ffffff; font-size: 14px; font-weight: 600; letter-spacing: 1px;">🔒 SECURITY ALERT</span>
                        </div>
                        <h1 style="margin: 0; color: #ffffff; font-size: 32px; font-weight: bold; line-height: 1.2;">Password Reset Request</h1>
                        <p style="margin: 15px 0 0 0; color: rgba(255,255,255,0.9); font-size: 16px;">Someone requested to reset your password</p>
                      </td>
                    </tr>

                    <!-- Content Section -->
                    <tr>
                      <td style="padding: 50px 40px;">
                        <p style="margin: 0 0 20px 0; color: #333333; font-size: 16px; line-height: 1.6;">
                          Hi there,
                        </p>

                        <p style="margin: 0 0 25px 0; color: #555555; font-size: 16px; line-height: 1.7;">
                          We received a request to reset the password for your QR Master account. If this was you, click the button below to create a new password:
                        </p>

                        <!-- Primary CTA Button -->
                        <table width="100%" cellpadding="0" cellspacing="0" style="margin: 35px 0;">
                          <tr>
                            <td align="center">
                              <a href="${resetUrl}" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #ffffff; text-decoration: none; padding: 18px 50px; border-radius: 8px; font-size: 17px; font-weight: 700; display: inline-block; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);">
                                🔐 Reset My Password →
                              </a>
                            </td>
                          </tr>
                        </table>

                        <!-- Security Info Box -->
                        <div style="background: linear-gradient(135deg, rgba(255, 107, 107, 0.08) 0%, rgba(255, 148, 148, 0.08) 100%); border-left: 4px solid #ff6b6b; padding: 20px 25px; margin: 35px 0; border-radius: 6px;">
                          <p style="margin: 0 0 12px 0; color: #d63031; font-size: 15px; font-weight: 700;">
                            ⏱️ This link expires in 60 minutes
                          </p>
                          <p style="margin: 0; color: #666666; font-size: 14px; line-height: 1.6;">
                            For your security, this password reset link will only work once and expires after 1 hour. If you need a new link, you can request another one anytime.
                          </p>
                        </div>

                        <!-- Alternative Link -->
                        <p style="margin: 30px 0 15px 0; color: #888888; font-size: 14px; line-height: 1.5;">
                          🔗 Button not working? Copy and paste this link into your browser:
                        </p>

                        <p style="margin: 0 0 30px 0; padding: 18px 20px; background-color: #f8f9fa; border: 1px solid #e9ecef; border-radius: 6px; word-break: break-all;">
                          <a href="${resetUrl}" style="color: #667eea; text-decoration: none; font-size: 13px; font-family: monospace;">${resetUrl}</a>
                        </p>

                        <!-- Didn't Request This? -->
                        <div style="background-color: #f8f9fa; padding: 25px; border-radius: 8px; margin-top: 35px;">
                          <p style="margin: 0 0 12px 0; color: #333333; font-size: 15px; font-weight: 600;">
                            ❓ Didn't request this?
                          </p>
                          <p style="margin: 0; color: #666666; font-size: 14px; line-height: 1.6;">
                            ✅ You can safely ignore this email. Your password won't be changed unless you click the button above. If you're concerned about your account security, please contact us immediately at <a href="mailto:support@qrmaster.net" style="color: #667eea; text-decoration: none;">support@qrmaster.net</a>
                          </p>
                        </div>
                      </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                      <td style="background-color: #f8f9fa; padding: 35px 40px; border-top: 1px solid #e9ecef;">
                        <table width="100%" cellpadding="0" cellspacing="0">
                          <tr>
                            <td align="center">
                              <p style="margin: 0 0 15px 0; color: #333333; font-size: 16px; font-weight: 600;">
                                QR Master
                              </p>
                              <p style="margin: 0 0 8px 0; color: #888888; font-size: 13px;">
                                Secure QR Code Analytics & Management
                              </p>
                              <p style="margin: 0; color: #999999; font-size: 12px;">
                                © 2025 QR Master. All rights reserved.
                              </p>
                              <p style="margin: 15px 0 0 0; color: #aaaaaa; font-size: 11px;">
                                This is an automated security email. Please do not reply.
                              </p>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>

                  </table>
                </td>
              </tr>
            </table>
          </body>
        </html>
      `,
    });

    console.log('Password reset email sent successfully to:', email);
    return { success: true };
  } catch (error) {
    console.error('Error sending password reset email:', error);
    throw new Error('Failed to send password reset email');
  }
}

/**
 * Newsletter Welcome Email - Value-focused with clear expectations
 */
export async function sendNewsletterWelcomeEmail(email: string) {
  await waitForRateLimit();

  try {
    await resend.emails.send({
      from: 'Timo from QR Master <timo@qrmaster.net>',
      replyTo: 'support@qrmaster.net',
      to: email,
      subject: '🎉 You\'re In! Here\'s What Happens Next (AI QR Features)',
      html: `
        <!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>Welcome to QR Master AI Waitlist</title>
          </head>
          <body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background-color: #f4f4f4;">
            <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f4; padding: 40px 20px;">
              <tr>
                <td align="center">
                  <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.08);">

                    <!-- Hero Header -->
                    <tr>
                      <td style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 50px 40px; text-align: center;">
                        <div style="display: inline-block; background-color: rgba(255,255,255,0.2); padding: 10px 20px; border-radius: 50px; margin-bottom: 20px;">
                          <span style="color: #ffffff; font-size: 13px; font-weight: 600; letter-spacing: 1px;">✨ EARLY ACCESS</span>
                        </div>
                        <h1 style="margin: 0; color: #ffffff; font-size: 36px; font-weight: bold; line-height: 1.2;">You're on the List! 🚀</h1>
                        <p style="margin: 20px 0 0 0; color: rgba(255,255,255,0.95); font-size: 18px; line-height: 1.5;">Get ready for AI-powered QR codes that work smarter, not harder</p>
                      </td>
                    </tr>

                    <!-- Personal Note -->
                    <tr>
                      <td style="padding: 45px 40px 35px 40px;">
                        <p style="margin: 0 0 20px 0; color: #333333; font-size: 16px; line-height: 1.7;">
                          Hey there! 👋
                        </p>

                        <p style="margin: 0 0 25px 0; color: #555555; font-size: 16px; line-height: 1.7;">
                          Thanks for joining the waitlist for QR Master's AI-powered features. You're among the <strong>first to know</strong> when we launch something that'll completely change how you create and manage QR codes.
                        </p>

                        <p style="margin: 0 0 35px 0; color: #555555; font-size: 16px; line-height: 1.7;">
                          No fluff, no spam. Just a heads-up when these features go live.
                        </p>

                        <!-- What's Coming Section -->
                        <div style="background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%); border-left: 4px solid #667eea; padding: 30px 30px; margin: 35px 0; border-radius: 8px;">
                          <h2 style="margin: 0 0 20px 0; color: #667eea; font-size: 20px; font-weight: 700;">
                            🎯 What You Can Expect
                          </h2>

                          <!-- Feature 1 -->
                          <div style="margin-bottom: 20px;">
                            <h3 style="margin: 0 0 8px 0; color: #333333; font-size: 16px; font-weight: 700;">
                              ⚡ Smart QR Generation
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              AI analyzes your content and automatically suggests the optimal QR design, colors, and format for maximum scans. No more guessing what works.
                            </p>
                          </div>

                          <!-- Feature 2 -->
                          <div style="margin-bottom: 20px;">
                            <h3 style="margin: 0 0 8px 0; color: #333333; font-size: 16px; font-weight: 700;">
                              📊 Predictive Analytics
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              See scan forecasts, detect unusual patterns, and ask questions about your data in plain English. Your analytics become conversations, not spreadsheets.
                            </p>
                          </div>

                          <!-- Feature 3 -->
                          <div style="margin-bottom: 20px;">
                            <h3 style="margin: 0 0 8px 0; color: #333333; font-size: 16px; font-weight: 700;">
                              🤖 Auto-Organization
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              Your QR codes automatically get categorized, tagged, and organized. Spend less time managing, more time creating.
                            </p>
                          </div>

                          <!-- Feature 4 -->
                          <div>
                            <h3 style="margin: 0 0 8px 0; color: #333333; font-size: 16px; font-weight: 700;">
                              🎨 AI Design Studio
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              Generate unique, on-brand QR code designs in seconds. Just describe what you want, AI handles the rest.
                            </p>
                          </div>
                        </div>

                        <!-- Timeline -->
                        <div style="background-color: #fff3cd; border: 1px solid #ffc107; padding: 25px; border-radius: 8px; margin: 35px 0;">
                          <p style="margin: 0 0 12px 0; color: #856404; font-size: 15px; font-weight: 700;">
                            ⏰ When Will This Happen?
                          </p>
                          <p style="margin: 0; color: #856404; font-size: 14px; line-height: 1.6;">
                            We're in active development and testing. You'll get an email the moment these features go live – <strong>no waiting, no wondering</strong>. We respect your inbox.
                          </p>
                        </div>

                        <!-- Meanwhile CTA -->
                        <div style="background-color: #f8f9fa; padding: 30px; border-radius: 8px; margin: 35px 0; text-align: center;">
                          <h3 style="margin: 0 0 15px 0; color: #333333; font-size: 18px; font-weight: 700;">
                            💡 Want to Get Started Now?
                          </h3>
                          <p style="margin: 0 0 25px 0; color: #666666; font-size: 15px; line-height: 1.6;">
                            Our current platform already helps teams create, track, and manage dynamic QR codes. No AI needed – just powerful tools that work today.
                          </p>
                          <a href="https://www.qrmaster.net/signup" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #ffffff; text-decoration: none; padding: 16px 40px; border-radius: 8px; font-size: 16px; font-weight: 700; display: inline-block; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);">
                            🚀 Try QR Master Free →
                          </a>
                        </div>

                        <!-- Personal Sign-off -->
                        <p style="margin: 35px 0 0 0; color: #555555; font-size: 16px; line-height: 1.7;">
                          💌 Thanks for trusting us with your inbox. We'll make it worth it.
                        </p>

                        <p style="margin: 20px 0 0 0; color: #555555; font-size: 16px; line-height: 1.7;">
                          <strong>— Timo 👋</strong><br>
                          <span style="color: #888888; font-size: 14px;">Founder, QR Master</span>
                        </p>
                      </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                      <td style="background-color: #f8f9fa; padding: 35px 40px; border-top: 1px solid #e9ecef;">
                        <table width="100%" cellpadding="0" cellspacing="0">
                          <tr>
                            <td align="center">
                              <p style="margin: 0 0 8px 0; color: #888888; font-size: 13px;">
                                <a href="https://www.qrmaster.net" style="color: #667eea; text-decoration: none;">www.qrmaster.net</a>
                              </p>
                              <p style="margin: 0; color: #999999; font-size: 12px;">
                                © 2025 QR Master. All rights reserved.
                              </p>
                              <p style="margin: 15px 0 0 0; color: #aaaaaa; font-size: 11px;">
                                You're receiving this because you signed up for AI feature notifications.
                              </p>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>

                  </table>
                </td>
              </tr>
            </table>
          </body>
        </html>
      `,
    });

    console.log('Newsletter welcome email sent successfully to:', email);
    return { success: true };
  } catch (error) {
    console.error('Error sending newsletter welcome email:', error);
    throw new Error('Failed to send newsletter welcome email');
  }
}

/**
 * AI Feature Launch Email - Excitement + clear CTA
 */
export async function sendAIFeatureLaunchEmail(email: string) {
  await waitForRateLimit();

  try {
    await resend.emails.send({
      from: 'Timo from QR Master <timo@qrmaster.net>',
      replyTo: 'support@qrmaster.net',
      to: email,
      subject: '🚀 They\'re Live! Your AI QR Features Are Ready',
      html: `
        <!DOCTYPE html>
        <html>
          <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0">
            <title>AI Features Are Live - QR Master</title>
          </head>
          <body style="margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; background-color: #f4f4f4;">
            <table width="100%" cellpadding="0" cellspacing="0" style="background-color: #f4f4f4; padding: 40px 20px;">
              <tr>
                <td align="center">
                  <table width="600" cellpadding="0" cellspacing="0" style="background-color: #ffffff; border-radius: 12px; overflow: hidden; box-shadow: 0 4px 12px rgba(0,0,0,0.08);">

                    <!-- Celebration Header -->
                    <tr>
                      <td style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 25px 30px; text-align: center;">
                        <div style="font-size: 32px; margin-bottom: 10px;">🎉</div>
                        <div style="display: inline-block; background-color: rgba(255,255,255,0.2); padding: 6px 14px; border-radius: 50px; margin-bottom: 12px;">
                          <span style="color: #ffffff; font-size: 11px; font-weight: 600; letter-spacing: 1px;">✨ NOW LIVE</span>
                        </div>
                        <h1 style="margin: 0; color: #ffffff; font-size: 24px; font-weight: bold; line-height: 1.2;">AI Features Are Here! 🚀</h1>
                        <p style="margin: 10px 0 0 0; color: rgba(255,255,255,0.95); font-size: 14px; line-height: 1.4;">Ready to use in your dashboard</p>
                      </td>
                    </tr>

                    <!-- Main Content -->
                    <tr>
                      <td style="padding: 50px 40px;">

                        <!-- Opening -->
                        <p style="margin: 0 0 25px 0; color: #333333; font-size: 17px; line-height: 1.7;">
                          Remember when you signed up to be notified about our AI features?
                        </p>

                        <p style="margin: 0 0 25px 0; color: #333333; font-size: 17px; line-height: 1.7; font-weight: 700;">
                          Well, today's that day. 🎯
                        </p>

                        <p style="margin: 0 0 35px 0; color: #555555; font-size: 16px; line-height: 1.7;">
                          We've been building, testing, and polishing these features for months. And they're finally ready for you to use. Right now. No beta, no waitlist, no BS.
                        </p>

                        <!-- What's New Highlight Box -->
                        <div style="background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%); border: 2px solid #667eea; padding: 35px 30px; margin: 40px 0; border-radius: 10px;">
                          <h2 style="margin: 0 0 25px 0; color: #667eea; font-size: 22px; font-weight: 700; text-align: center;">
                            ✨ What's New in Your Dashboard
                          </h2>

                          <!-- Feature Cards -->
                          <div style="background-color: #ffffff; padding: 25px; margin-bottom: 15px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);">
                            <h3 style="margin: 0 0 10px 0; color: #333333; font-size: 17px; font-weight: 700;">
                              ⚡ Smart QR Generation
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              AI analyzes your content and suggests optimal designs automatically. Just paste your link, we handle the optimization.
                            </p>
                          </div>

                          <div style="background-color: #ffffff; padding: 25px; margin-bottom: 15px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);">
                            <h3 style="margin: 0 0 10px 0; color: #333333; font-size: 17px; font-weight: 700;">
                              📊 Predictive Analytics
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              Ask questions about your scan data in plain English. "Which campaign performed best last month?" Done.
                            </p>
                          </div>

                          <div style="background-color: #ffffff; padding: 25px; margin-bottom: 15px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);">
                            <h3 style="margin: 0 0 10px 0; color: #333333; font-size: 17px; font-weight: 700;">
                              🤖 Auto-Organization
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              QR codes automatically categorized and tagged. Your library stays organized without manual work.
                            </p>
                          </div>

                          <div style="background-color: #ffffff; padding: 25px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.05);">
                            <h3 style="margin: 0 0 10px 0; color: #333333; font-size: 17px; font-weight: 700;">
                              🎨 AI Design Studio
                            </h3>
                            <p style="margin: 0; color: #666666; font-size: 15px; line-height: 1.6;">
                              Generate custom QR designs by describing what you want. "Make it modern and blue" → Done in 3 seconds.
                            </p>
                          </div>
                        </div>

                        <!-- How to Access -->
                        <div style="background-color: #fff3cd; border: 2px solid #ffc107; padding: 30px; border-radius: 10px; margin: 40px 0;">
                          <h3 style="margin: 0 0 15px 0; color: #856404; font-size: 18px; font-weight: 700;">
                            🎯 How to Get Started
                          </h3>
                          <ol style="margin: 0; padding-left: 20px; color: #856404; font-size: 15px; line-height: 1.8;">
                            <li style="margin-bottom: 10px;">🔐 Log in to your QR Master account</li>
                            <li style="margin-bottom: 10px;">👀 Look for the "✨ AI" badge on supported features</li>
                            <li style="margin-bottom: 10px;">✏️ Try creating a QR code – you'll see AI suggestions automatically</li>
                            <li>📈 Check your Analytics tab for the new AI query interface</li>
                          </ol>
                        </div>

                        <!-- Primary CTA -->
                        <table width="100%" cellpadding="0" cellspacing="0" style="margin: 45px 0 40px 0;">
                          <tr>
                            <td align="center">
                              <a href="https://www.qrmaster.net/create" style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #ffffff; text-decoration: none; padding: 20px 60px; border-radius: 10px; font-size: 18px; font-weight: 700; display: inline-block; box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);">
                                ✨ Try AI Features Now →
                              </a>
                              <p style="margin: 20px 0 0 0; color: #888888; font-size: 13px;">
                                ✅ Available on all plans • ⚡ No extra setup required
                              </p>
                            </td>
                          </tr>
                        </table>

                        <!-- Personal Note -->
                        <div style="background-color: #f8f9fa; padding: 30px; border-radius: 8px; margin: 40px 0;">
                          <p style="margin: 0 0 20px 0; color: #555555; font-size: 15px; line-height: 1.7;">
                            💬 We're excited to see what you build with these new tools. If you have questions, ideas, or just want to share what you created – <a href="mailto:support@qrmaster.net" style="color: #667eea; text-decoration: none;">hit reply</a>. I read every email.
                          </p>
                          <p style="margin: 0; color: #555555; font-size: 15px; line-height: 1.7;">
                            <strong>— Timo 👋</strong><br>
                            <span style="color: #888888; font-size: 13px;">Founder, QR Master</span>
                          </p>
                        </div>

                      </td>
                    </tr>

                    <!-- Footer -->
                    <tr>
                      <td style="background-color: #f8f9fa; padding: 35px 40px; border-top: 1px solid #e9ecef;">
                        <table width="100%" cellpadding="0" cellspacing="0">
                          <tr>
                            <td align="center">
                              <p style="margin: 0 0 8px 0; color: #888888; font-size: 13px;">
                                <a href="https://www.qrmaster.net" style="color: #667eea; text-decoration: none;">www.qrmaster.net</a> •
                                <a href="https://www.qrmaster.net/dashboard" style="color: #667eea; text-decoration: none;">Dashboard</a> •
                                <a href="https://www.qrmaster.net/faq" style="color: #667eea; text-decoration: none;">Help</a>
                              </p>
                              <p style="margin: 0; color: #999999; font-size: 12px;">
                                © 2025 QR Master. All rights reserved.
                              </p>
                              <p style="margin: 15px 0 0 0; color: #aaaaaa; font-size: 11px;">
                                You received this because you subscribed to AI feature launch notifications.
                              </p>
                            </td>
                          </tr>
                        </table>
                      </td>
                    </tr>

                  </table>
                </td>
              </tr>
            </table>
          </body>
        </html>
      `,
    });

    console.log('AI feature launch email sent successfully to:', email);
    return { success: true };
  } catch (error) {
    console.error('Error sending AI feature launch email:', error);
    throw new Error('Failed to send AI feature launch email');
  }
}
