"use client";

import { useState } from "react";
import { useRouter } from "next/navigation";
import {
    Phone, Video, MapPin, Code2, Users, Award,
    ArrowRight, ArrowLeft, Clock, Calendar, Globe,
    CheckCircle2, Loader2, FileText, MessageSquare
} from "lucide-react";
import { scheduleInterview } from "@/app/actions/interviewActions";

// ─── Types ───
type InterviewType = "phone_screen" | "video" | "in_person" | "technical" | "panel" | "final";
type WizardStep = 1 | 2 | 3 | 4;

interface InterviewTypeOption {
    key: InterviewType;
    label: string;
    icon: any;
    description: string;
    duration: number;
    participants: string;
    color: string;
    gradient: string;
}

const INTERVIEW_TYPES: InterviewTypeOption[] = [
    {
        key: "phone_screen",
        label: "Phone Screen",
        icon: Phone,
        description: "Quick initial conversation to verify basics and gauge interest",
        duration: 30,
        participants: "1 interviewer (recruiter)",
        color: "text-emerald-600",
        gradient: "from-emerald-50 to-emerald-100/50 border-emerald-200 hover:border-emerald-400",
    },
    {
        key: "video",
        label: "Video Interview",
        icon: Video,
        description: "Remote interview via video call, most common for remote positions",
        duration: 60,
        participants: "1-3 interviewers",
        color: "text-blue-600",
        gradient: "from-blue-50 to-blue-100/50 border-blue-200 hover:border-blue-400",
    },
    {
        key: "in_person",
        label: "In-Person Interview",
        icon: MapPin,
        description: "Candidate visits office, may include office tour",
        duration: 60,
        participants: "1-3 interviewers",
        color: "text-violet-600",
        gradient: "from-violet-50 to-violet-100/50 border-violet-200 hover:border-violet-400",
    },
    {
        key: "technical",
        label: "Technical Assessment",
        icon: Code2,
        description: "Hands-on coding or problem-solving, may include live coding",
        duration: 90,
        participants: "1-2 technical assessors",
        color: "text-orange-600",
        gradient: "from-orange-50 to-orange-100/50 border-orange-200 hover:border-orange-400",
    },
    {
        key: "panel",
        label: "Panel Interview",
        icon: Users,
        description: "Multiple interviewers simultaneously, common for senior roles",
        duration: 75,
        participants: "3-5 panelists",
        color: "text-pink-600",
        gradient: "from-pink-50 to-pink-100/50 border-pink-200 hover:border-pink-400",
    },
    {
        key: "final",
        label: "Final Interview",
        icon: Award,
        description: "Last stage before offer, often with senior leadership",
        duration: 45,
        participants: "1-2 senior leaders",
        color: "text-amber-600",
        gradient: "from-amber-50 to-amber-100/50 border-amber-200 hover:border-amber-400",
    },
];

const ROUND_OPTIONS = [
    { value: "initial_screen", label: "Initial Screen" },
    { value: "first_round", label: "First Round" },
    { value: "second_round", label: "Second Round" },
    { value: "technical", label: "Technical Assessment" },
    { value: "final", label: "Final Interview" },
];

const DURATION_OPTIONS = [
    { value: 15, label: "15 min" },
    { value: 30, label: "30 min" },
    { value: 45, label: "45 min" },
    { value: 60, label: "1 hour" },
    { value: 90, label: "1.5 hours" },
    { value: 120, label: "2 hours" },
];

interface WizardProps {
    applicationId: string;
    jobTitle: string;
    candidateName: string;
    interviewCount: number;
    onClose: () => void;
}

export function InterviewSchedulingWizard({
    applicationId,
    jobTitle,
    candidateName,
    interviewCount,
    onClose,
}: WizardProps) {
    const router = useRouter();
    const [step, setStep] = useState<WizardStep>(1);
    const [isSubmitting, setIsSubmitting] = useState(false);
    const [success, setSuccess] = useState(false);

    // Form state
    const [interviewType, setInterviewType] = useState<InterviewType | null>(null);
    const [formData, setFormData] = useState({
        title: "",
        scheduled_start_datetime: "",
        duration_minutes: 60,
        format: "video",
        meeting_link: "",
        location: "",
        timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "Africa/Lagos",
        round: "",
        interviewer_name: "",
        interviewer_instructions: "",
        preparation_notes: "",
        notes: "",
    });

    const selectedType = INTERVIEW_TYPES.find((t) => t.key === interviewType);

    // Auto-fill when type changes
    const handleTypeSelect = (type: InterviewType) => {
        const typeOption = INTERVIEW_TYPES.find((t) => t.key === type)!;
        setInterviewType(type);
        setFormData((prev) => ({
            ...prev,
            duration_minutes: typeOption.duration,
            format: type === "phone_screen" ? "phone" : type === "in_person" ? "in_person" : "video",
            title: `${typeOption.label} — ${jobTitle}`,
        }));
    };

    const canProceed = (s: WizardStep): boolean => {
        switch (s) {
            case 1: return !!interviewType;
            case 2: return !!formData.scheduled_start_datetime;
            case 3: return true; // Optional
            case 4: return true;
            default: return false;
        }
    };

    const handleSchedule = async () => {
        if (!interviewType) return;
        setIsSubmitting(true);
        try {
            const result = await scheduleInterview(applicationId, {
                ...formData,
                interview_type: interviewType,
            });
            if (result.success) {
                setSuccess(true);
                setTimeout(() => {
                    router.refresh();
                    onClose();
                }, 2000);
            }
        } catch (error) {
            console.error("Schedule failed:", error);
        } finally {
            setIsSubmitting(false);
        }
    };

    // Calculate end time
    const getEndTime = (): string => {
        if (!formData.scheduled_start_datetime) return "";
        const start = new Date(formData.scheduled_start_datetime);
        const end = new Date(start.getTime() + formData.duration_minutes * 60000);
        return end.toLocaleTimeString("en-US", { hour: "2-digit", minute: "2-digit" });
    };

    // ─── Success State ───
    if (success) {
        return (
            <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
                <div className="bg-white rounded-3xl p-10 max-w-md mx-4 shadow-2xl text-center space-y-4 animate-[fadeIn_0.3s_ease-out]">
                    <div className="w-16 h-16 mx-auto rounded-full bg-emerald-100 flex items-center justify-center">
                        <CheckCircle2 className="w-8 h-8 text-emerald-600" />
                    </div>
                    <h3 className="text-2xl font-extrabold text-slate-900">Interview Scheduled!</h3>
                    <p className="text-sm text-slate-500">
                        Interview with <strong>{candidateName}</strong> has been scheduled.
                        The candidate will be notified.
                    </p>
                </div>
            </div>
        );
    }

    return (
        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm">
            <div className="bg-white rounded-3xl w-full max-w-3xl mx-4 shadow-2xl overflow-hidden max-h-[90vh] flex flex-col animate-[fadeIn_0.2s_ease-out]">
                {/* Header */}
                <div className="bg-gradient-to-r from-primary to-indigo-600 px-8 py-5">
                    <div className="flex items-center justify-between">
                        <div>
                            <p className="text-xs font-bold text-white/70 uppercase tracking-widest">
                                Schedule Interview
                            </p>
                            <h2 className="text-lg font-extrabold text-white mt-0.5">
                                {candidateName} — {jobTitle}
                            </h2>
                        </div>
                        <button
                            onClick={onClose}
                            className="text-white/60 hover:text-white text-2xl font-bold transition-colors"
                        >
                            ×
                        </button>
                    </div>
                    {/* Step indicator */}
                    <div className="flex items-center gap-2 mt-4">
                        {[1, 2, 3, 4].map((s) => (
                            <div key={s} className="flex items-center gap-2 flex-1">
                                <div
                                    className={`h-1.5 flex-1 rounded-full transition-all ${s <= step ? "bg-white" : "bg-white/20"
                                        }`}
                                />
                            </div>
                        ))}
                    </div>
                    <div className="flex justify-between mt-1.5">
                        <span className="text-[10px] text-white/60 font-semibold">Type</span>
                        <span className="text-[10px] text-white/60 font-semibold">Details</span>
                        <span className="text-[10px] text-white/60 font-semibold">Interviewers</span>
                        <span className="text-[10px] text-white/60 font-semibold">Review</span>
                    </div>
                </div>

                {/* Body */}
                <div className="flex-1 overflow-y-auto p-6 md:p-8">
                    {/* ─── Step 1: Interview Type ─── */}
                    {step === 1 && (
                        <div className="space-y-4">
                            <div>
                                <h3 className="text-lg font-bold text-slate-900">Select Interview Type</h3>
                                <p className="text-sm text-slate-500 mt-0.5">
                                    Choose the type of interview to schedule with this candidate.
                                </p>
                            </div>
                            <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
                                {INTERVIEW_TYPES.map((type) => {
                                    const Icon = type.icon;
                                    const isSelected = interviewType === type.key;
                                    return (
                                        <button
                                            key={type.key}
                                            onClick={() => handleTypeSelect(type.key)}
                                            className={`relative p-4 rounded-2xl border-2 text-left transition-all ${isSelected
                                                    ? `bg-gradient-to-br ${type.gradient} ring-2 ring-offset-1 ring-primary/30 scale-[1.02]`
                                                    : "bg-white border-slate-200 hover:border-slate-300 hover:shadow-sm"
                                                }`}
                                        >
                                            {isSelected && (
                                                <CheckCircle2 className="absolute top-3 right-3 w-5 h-5 text-primary" />
                                            )}
                                            <div className={`w-10 h-10 rounded-xl flex items-center justify-center mb-3 ${isSelected ? "bg-white shadow-sm" : "bg-slate-100"
                                                }`}>
                                                <Icon className={`w-5 h-5 ${type.color}`} />
                                            </div>
                                            <p className="font-bold text-slate-900 text-sm">{type.label}</p>
                                            <p className="text-xs text-slate-500 mt-1 leading-relaxed">
                                                {type.description}
                                            </p>
                                            <div className="flex items-center gap-3 mt-3 text-[10px] text-slate-400 font-semibold uppercase">
                                                <span className="flex items-center gap-0.5">
                                                    <Clock className="w-3 h-3" /> {type.duration}min
                                                </span>
                                                <span>{type.participants}</span>
                                            </div>
                                        </button>
                                    );
                                })}
                            </div>
                        </div>
                    )}

                    {/* ─── Step 2: Interview Details ─── */}
                    {step === 2 && (
                        <div className="space-y-5">
                            <div>
                                <h3 className="text-lg font-bold text-slate-900">Interview Details</h3>
                                <p className="text-sm text-slate-500 mt-0.5">
                                    Set the specifics for this {selectedType?.label || "interview"}.
                                </p>
                            </div>

                            {/* Title */}
                            <div>
                                <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                    Interview Title
                                </label>
                                <input
                                    type="text"
                                    value={formData.title}
                                    onChange={(e) => setFormData({ ...formData, title: e.target.value })}
                                    placeholder={`${selectedType?.label} — ${jobTitle}`}
                                    className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                />
                            </div>

                            <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
                                {/* Date & Time */}
                                <div>
                                    <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                        <Calendar className="w-3.5 h-3.5 inline mr-1" /> Date & Time *
                                    </label>
                                    <input
                                        type="datetime-local"
                                        required
                                        value={formData.scheduled_start_datetime}
                                        onChange={(e) => setFormData({ ...formData, scheduled_start_datetime: e.target.value })}
                                        className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                    />
                                    {formData.scheduled_start_datetime && (
                                        <p className="text-xs text-slate-400 mt-1">
                                            Ends at {getEndTime()}
                                        </p>
                                    )}
                                </div>

                                {/* Duration */}
                                <div>
                                    <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                        <Clock className="w-3.5 h-3.5 inline mr-1" /> Duration
                                    </label>
                                    <select
                                        value={formData.duration_minutes}
                                        onChange={(e) =>
                                            setFormData({ ...formData, duration_minutes: parseInt(e.target.value) })
                                        }
                                        className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                    >
                                        {DURATION_OPTIONS.map((d) => (
                                            <option key={d.value} value={d.value}>{d.label}</option>
                                        ))}
                                    </select>
                                </div>

                                {/* Timezone */}
                                <div>
                                    <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                        <Globe className="w-3.5 h-3.5 inline mr-1" /> Timezone
                                    </label>
                                    <input
                                        type="text"
                                        value={formData.timezone}
                                        onChange={(e) => setFormData({ ...formData, timezone: e.target.value })}
                                        className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                    />
                                </div>

                                {/* Round */}
                                <div>
                                    <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                        Interview Stage
                                    </label>
                                    <select
                                        value={formData.round}
                                        onChange={(e) => setFormData({ ...formData, round: e.target.value })}
                                        className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                    >
                                        <option value="">Select stage...</option>
                                        {ROUND_OPTIONS.map((r) => (
                                            <option key={r.value} value={r.value}>{r.label}</option>
                                        ))}
                                    </select>
                                    {interviewCount > 0 && (
                                        <p className="text-xs text-amber-600 mt-1">
                                            This will be interview #{interviewCount + 1} for this candidate
                                        </p>
                                    )}
                                </div>
                            </div>

                            {/* Meeting Link or Location */}
                            {(formData.format === "video" || formData.format === "phone") && (
                                <div>
                                    <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                        Meeting Link
                                    </label>
                                    <input
                                        type="url"
                                        value={formData.meeting_link}
                                        onChange={(e) => setFormData({ ...formData, meeting_link: e.target.value })}
                                        placeholder="https://meet.google.com/... or zoom link"
                                        className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                    />
                                </div>
                            )}

                            {formData.format === "in_person" && (
                                <div>
                                    <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                        <MapPin className="w-3.5 h-3.5 inline mr-1" /> Location
                                    </label>
                                    <input
                                        type="text"
                                        value={formData.location}
                                        onChange={(e) => setFormData({ ...formData, location: e.target.value })}
                                        placeholder="Office address, conference room..."
                                        className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                    />
                                </div>
                            )}
                        </div>
                    )}

                    {/* ─── Step 3: Interviewers & Instructions ─── */}
                    {step === 3 && (
                        <div className="space-y-5">
                            <div>
                                <h3 className="text-lg font-bold text-slate-900">Interviewers & Preparation</h3>
                                <p className="text-sm text-slate-500 mt-0.5">
                                    Add interviewer details and preparation instructions.
                                </p>
                            </div>

                            {/* Interviewer Name */}
                            <div>
                                <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                    <Users className="w-3.5 h-3.5 inline mr-1" /> Interviewer Name(s)
                                </label>
                                <input
                                    type="text"
                                    value={formData.interviewer_name}
                                    onChange={(e) => setFormData({ ...formData, interviewer_name: e.target.value })}
                                    placeholder="e.g., Sarah Johnson, Mike Chen"
                                    className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none"
                                />
                                <p className="text-xs text-slate-400 mt-1">
                                    Separate multiple names with commas
                                </p>
                            </div>

                            {/* Interviewer Instructions */}
                            <div>
                                <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                    <FileText className="w-3.5 h-3.5 inline mr-1" /> Interviewer Instructions
                                </label>
                                <textarea
                                    value={formData.interviewer_instructions}
                                    onChange={(e) =>
                                        setFormData({ ...formData, interviewer_instructions: e.target.value })
                                    }
                                    rows={3}
                                    placeholder="Focus areas, questions to ask, evaluation criteria..."
                                    className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none resize-none"
                                />
                            </div>

                            {/* Preparation Notes for Candidate */}
                            <div>
                                <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                    <MessageSquare className="w-3.5 h-3.5 inline mr-1" /> Preparation Notes for Candidate
                                </label>
                                <textarea
                                    value={formData.preparation_notes}
                                    onChange={(e) =>
                                        setFormData({ ...formData, preparation_notes: e.target.value })
                                    }
                                    rows={3}
                                    placeholder="What the candidate should prepare, topics to review..."
                                    className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none resize-none"
                                />
                            </div>

                            {/* Internal Notes */}
                            <div>
                                <label className="block text-sm font-semibold text-slate-700 mb-1.5">
                                    Internal Notes (optional)
                                </label>
                                <textarea
                                    value={formData.notes}
                                    onChange={(e) => setFormData({ ...formData, notes: e.target.value })}
                                    rows={2}
                                    placeholder="Any additional internal notes..."
                                    className="w-full px-4 py-2.5 border border-slate-200 rounded-xl text-sm focus:ring-2 focus:ring-primary/30 focus:border-primary outline-none resize-none"
                                />
                            </div>
                        </div>
                    )}

                    {/* ─── Step 4: Review & Schedule ─── */}
                    {step === 4 && (
                        <div className="space-y-5">
                            <div>
                                <h3 className="text-lg font-bold text-slate-900">Review & Schedule</h3>
                                <p className="text-sm text-slate-500 mt-0.5">
                                    Confirm the interview details before scheduling.
                                </p>
                            </div>

                            <div className="bg-gradient-to-br from-slate-50 to-white border border-slate-200 rounded-2xl p-6 space-y-4">
                                {/* Type Badge */}
                                {selectedType && (
                                    <div className="flex items-center gap-3">
                                        <div className={`w-10 h-10 rounded-xl bg-white shadow-sm flex items-center justify-center`}>
                                            <selectedType.icon className={`w-5 h-5 ${selectedType.color}`} />
                                        </div>
                                        <div>
                                            <p className="text-xs font-bold text-slate-400 uppercase tracking-wider">
                                                Interview Type
                                            </p>
                                            <p className="font-bold text-slate-900">{selectedType.label}</p>
                                        </div>
                                    </div>
                                )}

                                <hr className="border-slate-100" />

                                {/* Summary Grid */}
                                <div className="grid grid-cols-2 gap-4 text-sm">
                                    <div>
                                        <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Title</p>
                                        <p className="font-semibold text-slate-900">{formData.title || "—"}</p>
                                    </div>
                                    <div>
                                        <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Candidate</p>
                                        <p className="font-semibold text-slate-900">{candidateName}</p>
                                    </div>
                                    <div>
                                        <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Date & Time</p>
                                        <p className="font-semibold text-slate-900">
                                            {formData.scheduled_start_datetime
                                                ? new Date(formData.scheduled_start_datetime).toLocaleString("en-US", {
                                                    dateStyle: "medium",
                                                    timeStyle: "short",
                                                })
                                                : "—"}
                                        </p>
                                    </div>
                                    <div>
                                        <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Duration</p>
                                        <p className="font-semibold text-slate-900">
                                            {formData.duration_minutes} minutes{" "}
                                            {formData.scheduled_start_datetime && (
                                                <span className="text-slate-400 text-xs">(ends at {getEndTime()})</span>
                                            )}
                                        </p>
                                    </div>
                                    <div>
                                        <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Timezone</p>
                                        <p className="font-semibold text-slate-900">{formData.timezone}</p>
                                    </div>
                                    {formData.round && (
                                        <div>
                                            <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Round</p>
                                            <p className="font-semibold text-slate-900">
                                                {ROUND_OPTIONS.find((r) => r.value === formData.round)?.label || formData.round}
                                            </p>
                                        </div>
                                    )}
                                    {formData.interviewer_name && (
                                        <div>
                                            <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Interviewer(s)</p>
                                            <p className="font-semibold text-slate-900">{formData.interviewer_name}</p>
                                        </div>
                                    )}
                                    {(formData.meeting_link || formData.location) && (
                                        <div>
                                            <p className="text-slate-400 text-xs font-semibold uppercase mb-0.5">Location</p>
                                            <p className="font-semibold text-slate-900 truncate">
                                                {formData.meeting_link || formData.location}
                                            </p>
                                        </div>
                                    )}
                                </div>

                                {/* Instructions preview */}
                                {formData.interviewer_instructions && (
                                    <>
                                        <hr className="border-slate-100" />
                                        <div>
                                            <p className="text-slate-400 text-xs font-semibold uppercase mb-1">
                                                Interviewer Instructions
                                            </p>
                                            <p className="text-sm text-slate-700 whitespace-pre-line">
                                                {formData.interviewer_instructions}
                                            </p>
                                        </div>
                                    </>
                                )}

                                {formData.preparation_notes && (
                                    <div>
                                        <p className="text-slate-400 text-xs font-semibold uppercase mb-1">
                                            Candidate Preparation Notes
                                        </p>
                                        <p className="text-sm text-slate-700 whitespace-pre-line">
                                            {formData.preparation_notes}
                                        </p>
                                    </div>
                                )}
                            </div>

                            {/* Validation */}
                            <div className="space-y-1">
                                <ValidationItem ok={!!interviewType} label="Interview type selected" />
                                <ValidationItem ok={!!formData.scheduled_start_datetime} label="Date and time set" />
                                <ValidationItem ok={!!formData.interviewer_name} label="Interviewer assigned" />
                                <ValidationItem
                                    ok={!!(formData.meeting_link || formData.location || formData.format === "phone")}
                                    label="Meeting location/link provided"
                                />
                            </div>
                        </div>
                    )}
                </div>

                {/* Footer */}
                <div className="border-t border-slate-100 px-8 py-4 flex items-center justify-between bg-slate-50/50">
                    <button
                        onClick={() => (step === 1 ? onClose() : setStep((step - 1) as WizardStep))}
                        className="inline-flex items-center gap-1.5 px-4 py-2 text-sm font-semibold text-slate-600 hover:text-slate-900 transition-colors"
                    >
                        <ArrowLeft className="w-4 h-4" />
                        {step === 1 ? "Cancel" : "Back"}
                    </button>

                    {step < 4 ? (
                        <button
                            onClick={() => setStep((step + 1) as WizardStep)}
                            disabled={!canProceed(step)}
                            className="inline-flex items-center gap-1.5 px-6 py-2.5 bg-primary text-white text-sm font-semibold rounded-xl hover:bg-primary/90 transition-colors disabled:opacity-40 disabled:cursor-not-allowed shadow-sm"
                        >
                            Continue <ArrowRight className="w-4 h-4" />
                        </button>
                    ) : (
                        <button
                            onClick={handleSchedule}
                            disabled={isSubmitting}
                            className="inline-flex items-center gap-1.5 px-6 py-2.5 bg-emerald-600 text-white text-sm font-semibold rounded-xl hover:bg-emerald-700 transition-colors disabled:opacity-50 shadow-sm"
                        >
                            {isSubmitting ? (
                                <>
                                    <Loader2 className="w-4 h-4 animate-spin" /> Scheduling...
                                </>
                            ) : (
                                <>
                                    <CheckCircle2 className="w-4 h-4" /> Schedule Interview
                                </>
                            )}
                        </button>
                    )}
                </div>
            </div>
        </div>
    );
}

// ─── Validation Item ───
function ValidationItem({ ok, label }: { ok: boolean; label: string }) {
    return (
        <div className="flex items-center gap-2 text-sm">
            <CheckCircle2 className={`w-4 h-4 ${ok ? "text-emerald-500" : "text-slate-300"}`} />
            <span className={ok ? "text-slate-700" : "text-slate-400"}>{label}</span>
        </div>
    );
}
