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

export interface BaseJobProps {
    employerName: string;
    jobTitle: string;
    companyName: string;
    jobId: string;
}

export function JobApprovedTemplate({ employerName, jobTitle, companyName, jobId }: BaseJobProps) {
    const jobUrl = `${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/jobs/${jobId}`;

    const content = `
    <span class="badge" style="display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background-color: #dcfce7; color: #166534; margin-bottom: 16px;">
      ✅ JOB APPROVED
    </span>

    <h1 style="font-size: 24px; font-weight: 700; margin-bottom: 16px; color: ${colors.foreground}; letter-spacing: -0.02em;">
      Your job posting is live!
    </h1>
    
    <p style="margin-bottom: 16px;">Hi ${employerName},</p>
    
    <p style="margin-bottom: 24px;">Great news! Your job posting <strong>"${jobTitle}"</strong> at <strong>${companyName}</strong> has been reviewed and approved by our team. It is now live and visible to thousands of qualified candidates on the platform.</p>

    ${Button({ text: 'View Live Job Posting →', url: jobUrl, variant: 'primary' })}

    <p style="margin-top: 32px; color: ${colors.textMuted}; font-size: 14px; margin-bottom: 0;">
      If you have any questions or would like to make edits to your listing, please visit your <a href="${process.env.NEXT_PUBLIC_APP_URL}/dashboard/jobs" style="color: ${colors.primary}; text-decoration: underline;">employer dashboard</a>.
    </p>
  `;

    return Layout({
        title: `✅ Approved: ${jobTitle}`,
        previewText: `Your job posting for ${jobTitle} has been approved and is now live!`,
        content
    });
}

export interface JobRejectedProps extends BaseJobProps {
    reason: string;
    details?: string;
}

export function JobRejectedTemplate({ employerName, jobTitle, companyName, reason, details }: JobRejectedProps) {
    const dashboardUrl = `${process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'}/dashboard/jobs`;

    const content = `
    <span class="badge" style="display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; background-color: #fee2e2; color: #991b1b; margin-bottom: 16px;">
      ❌ JOB NOT APPROVED
    </span>

    <h1 style="font-size: 24px; font-weight: 700; margin-bottom: 16px; color: ${colors.foreground}; letter-spacing: -0.02em;">
      Posting Requires Revision
    </h1>
    
    <p style="margin-bottom: 16px;">Hi ${employerName},</p>
    
    <p style="margin-bottom: 24px;">Unfortunately, your job posting <strong>"${jobTitle}"</strong> at <strong>${companyName}</strong> did not meet our content guidelines and has not been approved at this time.</p>

    <div class="box" style="background-color: #fef2f2; border: 1px solid #f87171; border-left: 4px solid #ef4444; border-radius: 6px; padding: 20px; margin-bottom: 24px;">
      <h3 style="font-size: 15px; font-weight: 700; color: #991b1b; margin-top: 0; margin-bottom: 8px;">Resolution Details</h3>
      <p style="margin-bottom: ${details ? '12px' : '0'}; color: #7f1d1d; font-size: 14px;"><strong>Reason:</strong> ${reason}</p>
      ${details ? `<p style="margin-bottom: 0; color: #7f1d1d; font-size: 14px; white-space: pre-wrap;"><strong>Admin Note:</strong><br/>${details}</p>` : ''}
    </div>

    ${Button({ text: 'Go to Dashboard to Fix →', url: dashboardUrl, variant: 'destructive' })}

    <p style="margin-top: 32px; color: ${colors.textMuted}; font-size: 14px; margin-bottom: 0;">
      You are welcome to revise your posting and resubmit it for review. If you believe this decision was made in error, please contact our support team.
    </p>
  `;

    return Layout({
        title: `Action Required: ${jobTitle} was not approved`,
        previewText: `Your job posting requires some revisions before it can be published.`,
        content
    });
}
