import * as React from 'react';
import {
    Body,
    Container,
    Head,
    Heading,
    Hr,
    Html,
    Link,
    Preview,
    Section,
    Text,
} from '@react-email/components';

const main = {
    backgroundColor: '#f6f9fc',
    fontFamily: '-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Ubuntu,sans-serif',
};

const container = {
    backgroundColor: '#ffffff',
    margin: '0 auto',
    padding: '20px 0 48px',
    marginBottom: '64px',
    borderRadius: '12px',
    overflow: 'hidden',
    boxShadow: '0 4px 6px rgba(0, 0, 0, 0.05)',
};

const heading = {
    fontSize: '24px',
    fontWeight: '700',
    color: '#1a1a1a',
    margin: '30px 48px 18px',
};

const paragraph = {
    fontSize: '16px',
    lineHeight: '26px',
    color: '#4a4a4a',
    margin: '0 48px 15px',
};

const summaryBox = {
    backgroundColor: '#f8fafc',
    borderRadius: '8px',
    padding: '24px',
    margin: '0 48px 24px',
    border: '1px solid #e2e8f0',
};

const button = {
    backgroundColor: '#2563eb',
    borderRadius: '8px',
    color: '#fff',
    fontSize: '16px',
    fontWeight: '600',
    textDecoration: 'none',
    textAlign: 'center' as const,
    display: 'block',
    padding: '14px 24px',
    margin: '10px 48px',
};

const hr = {
    borderColor: '#e2e8f0',
    margin: '30px 0',
};

interface InterviewReminderProps {
    candidateName: string;
    jobTitle: string;
    companyName: string;
    scheduledAt: string; // Formatted date string
    interviewType: string;
    meetingLink?: string;
    location?: string;
    dashboardUrl: string;
    reminderType: '24h' | '1h' | '15m' | 'rescheduled' | 'cancelled';
}

export const InterviewReminderTemplate = ({
    candidateName = "Candidate",
    jobTitle = "Software Engineer",
    companyName = "TechCorp",
    scheduledAt = "Monday, Jan 1 at 10:00 AM",
    interviewType = "Video Call",
    meetingLink,
    location,
    dashboardUrl = "#",
    reminderType = '24h'
}: InterviewReminderProps) => {
    let preview = "";
    let title = "";
    let intro = "";

    switch (reminderType) {
        case '24h':
            preview = `Interview Reminder: Tomorrow for ${jobTitle}`;
            title = "Interview Tomorrow";
            intro = "This is a reminder about your upcoming interview tomorrow.";
            break;
        case '1h':
            preview = `Interview starting in 1 hour: ${jobTitle}`;
            title = "Interview in 1 Hour";
            intro = "Your interview is starting soon. Make sure you're ready!";
            break;
        case '15m':
            preview = `Interview starting now: ${jobTitle}`;
            title = "Interview Starting Soon";
            intro = "Your interview begins in 15 minutes. Check your connection now.";
            break;
        case 'rescheduled':
            preview = `Interview Rescheduled: ${jobTitle}`;
            title = "Interview Rescheduled";
            intro = "Your interview has been rescheduled to a new time.";
            break;
        case 'cancelled':
            preview = `Interview Cancelled: ${jobTitle}`;
            title = "Interview Cancelled";
            intro = "We are writing to inform you that your interview has been cancelled.";
            break;
    }

    return (
        <Html>
            <Head />
            <Preview>{preview}</Preview>
            <Body style={main}>
                <Container style={container}>
                    <Heading style={heading}>{title}</Heading>
                    <Text style={paragraph}>Hi {candidateName},</Text>
                    <Text style={paragraph}>{intro}</Text>

                    {reminderType !== 'cancelled' && (
                        <Section style={summaryBox}>
                            <Text style={{ margin: '0 0 8px 0', fontSize: '15px' }}>
                                <strong>Position:</strong> {jobTitle}
                            </Text>
                            <Text style={{ margin: '0 0 8px 0', fontSize: '15px' }}>
                                <strong>Company:</strong> {companyName}
                            </Text>
                            <Text style={{ margin: '0 0 8px 0', fontSize: '15px' }}>
                                <strong>Time:</strong> {scheduledAt}
                            </Text>
                            <Text style={{ margin: '0 0 8px 0', fontSize: '15px' }}>
                                <strong>Type:</strong> {interviewType.replace(/_/g, ' ')}
                            </Text>
                            {meetingLink && (
                                <Text style={{ margin: '0 0 8px 0', fontSize: '15px' }}>
                                    <strong>Meeting Link:</strong> <Link href={meetingLink}>{meetingLink}</Link>
                                </Text>
                            )}
                            {location && (
                                <Text style={{ margin: 0, fontSize: '15px' }}>
                                    <strong>Location:</strong> {location}
                                </Text>
                            )}
                        </Section>
                    )}

                    {reminderType !== 'cancelled' ? (
                        <Link href={dashboardUrl} style={button}>
                            {meetingLink ? "Join Meeting" : "View Interview Details"}
                        </Link>
                    ) : (
                        <Link href={dashboardUrl} style={{ ...button, backgroundColor: '#475569' }}>
                            Visit Dashboard
                        </Link>
                    )}

                    <Hr style={hr} />
                    <Text style={{ fontSize: '12px', color: '#94a3b8', margin: '0 48px', textAlign: 'center' as const }}>
                        © {new Date().getFullYear()} Jobzio Platform
                    </Text>
                </Container>
            </Body>
        </Html>
    );
};
