import { Layout } from './Layout';
import { Button } from './components/Button';
import { colors, fonts } from './components/theme';

export function PasswordResetTemplate({
  firstName,
  resetUrl,
}: {
  firstName: string;
  resetUrl: string;
}) {
  const content = `
    <h2 style="font-size: 20px; font-weight: 600; margin-top: 0; margin-bottom: 16px; color: ${colors.foreground};">Password Reset Request</h2>
    <p style="margin: 0 0 16px;">Hi ${firstName},</p>
    <p style="margin: 0 0 24px;">We received a request to reset the password for your Proten Job Board account. If this was you, please click the button below to set a new password.</p>
    
    <div style="text-align: center; margin-bottom: 24px;">
      ${Button({ text: 'Reset Password', url: resetUrl })}
    </div>
    
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">This link will expire in 1 hour.</p>
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">If you did not request a password reset, you can safely ignore this email. Your password will remain unchanged.</p>
  `;

  return Layout({
    title: 'Password Reset Request',
    previewText: 'Reset your Proten Job Board password',
    content,
  });
}

export function ActionConfirmationTemplate({
  firstName,
  title,
  message,
}: {
  firstName: string;
  title: string;
  message: string;
}) {
  const content = `
    <h2 style="font-size: 20px; font-weight: 600; margin-top: 0; margin-bottom: 16px; color: ${colors.foreground};">${title}</h2>
    <p style="margin: 0 0 16px;">Hi ${firstName},</p>
    <p style="margin: 0 0 24px;">${message}</p>
    
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">If you made this change, no further action is required.</p>
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">If you did not make this change, please contact our support team immediately to secure your account.</p>
  `;

  return Layout({
    title: title,
    previewText: title,
    content,
  });
}

export function SecurityAlertTemplate({
  firstName,
  device,
  location,
  ipAddress,
  time,
}: {
  firstName: string;
  device: string;
  location: string;
  ipAddress: string;
  time: string;
}) {
  const content = `
    <h2 style="font-size: 20px; font-weight: 600; margin-top: 0; margin-bottom: 16px; color: ${colors.foreground};">New Login Detected</h2>
    <p style="margin: 0 0 16px;">Hi ${firstName},</p>
    <p style="margin: 0 0 16px;">We noticed a new login to your Proten Job Board account from an unrecognized device.</p>
    
    <div style="background-color: ${colors.muted}; padding: 16px; border-radius: 8px; margin-bottom: 24px;">
      <p style="margin: 0 0 8px; font-size: 14px;"><strong>Device:</strong> ${device}</p>
      <p style="margin: 0 0 8px; font-size: 14px;"><strong>Location:</strong> ${location}</p>
      <p style="margin: 0 0 8px; font-size: 14px;"><strong>IP Address:</strong> ${ipAddress}</p>
      <p style="margin: 0; font-size: 14px;"><strong>Time:</strong> ${time}</p>
    </div>
    
    <p style="margin: 0 0 16px; font-size: 14px;">If this was you, you can safely ignore this email.</p>
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">If you don't recognize this activity, please change your password immediately to secure your account.</p>
    
    <div style="text-align: center; margin-top: 24px;">
      ${Button({ text: 'Change Password', url: process.env.NEXT_PUBLIC_APP_URL + '/forgot-password' })}
    </div>
  `;

  return Layout({
    title: 'New Login Detected',
    previewText: 'Security Alert: New login detected on your account',
    content,
  });
}

export function TwoFactorCodeTemplate({
  firstName,
  code,
  ipAddress,
}: {
  firstName: string;
  code: string;
  ipAddress?: string;
}) {
  const content = `
    <h2 style="font-size: 20px; font-weight: 600; margin-top: 0; margin-bottom: 16px; color: ${colors.foreground};">Your Login Code</h2>
    <p style="margin: 0 0 16px;">Hi ${firstName},</p>
    <p style="margin: 0 0 24px;">Use the following verification code to complete your secure login:</p>
    
    <div style="text-align: center; margin-bottom: 24px;">
      <div style="display: inline-block; background-color: ${colors.muted}; padding: 12px 24px; border-radius: 6px; border: 1px solid ${colors.border}; font-family: monospace; font-size: 24px; font-weight: bold; letter-spacing: 4px;">
        ${code}
      </div>
    </div>
    
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">This code will expire in 5 minutes.</p>
    ${ipAddress ? '<p style="margin: 0 0 16px; font-size: 14px; color: ' + colors.textMuted + ';">Login attempt from IP: ' + ipAddress + '</p>' : ''}
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">If you didn't request this code, please secure your account immediately.</p>
  `;

  return Layout({
    title: 'Your Login Code',
    previewText: 'Your 2FA Login Code is ' + code,
    content,
  });
}

export function EmailVerificationTemplate({
  firstName,
  verifyUrl,
}: {
  firstName: string;
  verifyUrl: string;
}) {
  const content = `
    <h2 style="font-size: 20px; font-weight: 600; margin-top: 0; margin-bottom: 16px; color: ${colors.foreground};">Verify your Email Address</h2>
    <p style="margin: 0 0 16px;">Hi ${firstName},</p>
    <p style="margin: 0 0 24px;">Thank you for registering on Proten Job Board! Please verify your email address to activate your account and access all features.</p>
    
    <div style="text-align: center; margin-bottom: 24px;">
      ${Button({ text: 'Verify Email Address', url: verifyUrl })}
    </div>
    
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">This link will expire in 24 hours.</p>
    <p style="margin: 0 0 16px; font-size: 14px; color: ${colors.textMuted};">If you didn't create an account, you can safely ignore this email.</p>
  `;

  return Layout({
    title: 'Verify Email Address',
    previewText: 'Action Required: Verify your email address',
    content,
  });
}
