import { useState } from 'react';
import { CheckCircle, AlertTriangle, MessageSquare, Loader2, FastForward } from 'lucide-react';

interface ApproveModalProps {
    isOpen: boolean;
    onClose: () => void;
    job: any;
    onApprove: (data: { featureJob: boolean, notifyPremium: boolean, addNewsletter: boolean, adminNote: string }) => Promise<void>;
}

export function ApproveModal({ isOpen, onClose, job, onApprove }: ApproveModalProps) {
    const [loading, setLoading] = useState(false);
    const [options, setOptions] = useState({
        featureJob: false,
        notifyPremium: false,
        addNewsletter: false,
        adminNote: ''
    });

    if (!isOpen) return null;

    const handleSubmit = async () => {
        setLoading(true);
        try {
            await onApprove(options);
        } finally {
            setLoading(false);
        }
    };

    return (
        <div className="fixed inset-0 z-[100] flex items-center justify-center p-4">
            <div className="absolute inset-0 bg-slate-900/60 backdrop-blur-sm" onClick={!loading ? onClose : undefined} />

            <div className="relative w-full max-w-lg bg-white rounded-2xl shadow-2xl flex flex-col overflow-hidden animate-in fade-in zoom-in-95 duration-200">
                <div className="p-6 border-b border-slate-200 bg-green-50">
                    <div className="flex items-center gap-3 text-green-700 font-bold text-lg">
                        <CheckCircle className="w-6 h-6" />
                        APPROVE JOB POSTING?
                    </div>
                </div>

                <div className="p-6 space-y-6">
                    <div>
                        <h3 className="font-bold text-slate-900">{job.title}</h3>
                        <p className="text-slate-600 font-medium">{job.company}</p>
                    </div>

                    <div className="bg-slate-50 border border-slate-200 rounded-xl p-4 space-y-2 text-sm text-slate-700">
                        <p className="font-bold mb-3 text-slate-900">Final Checklist:</p>
                        <p className="flex items-center gap-2"><CheckCircle className="w-4 h-4 text-green-500" /> Job content reviewed</p>
                        <p className="flex items-center gap-2"><CheckCircle className="w-4 h-4 text-green-500" /> Company verified</p>
                        <p className="flex items-center gap-2"><CheckCircle className="w-4 h-4 text-green-500" /> No red flags detected</p>
                        <p className="flex items-center gap-2"><CheckCircle className="w-4 h-4 text-green-500" /> Salary competitive</p>
                        <p className="flex items-center gap-2"><CheckCircle className="w-4 h-4 text-green-500" /> Requirements reasonable</p>
                    </div>

                    <div className="bg-orange-50 border border-orange-200 rounded-xl p-4 text-sm text-orange-800">
                        <p className="font-bold flex items-center gap-2 mb-2"><AlertTriangle className="w-4 h-4" /> This action will:</p>
                        <ul className="list-disc pl-5 space-y-1 mt-1">
                            <li>Publish job immediately</li>
                            <li>Make visible to all candidates</li>
                            <li>Send approval email to employer</li>
                            <li>Cannot be easily undone</li>
                        </ul>
                    </div>

                    <div className="border border-slate-200 rounded-xl p-4 space-y-3">
                        <p className="font-bold text-sm text-slate-900">Optional Features:</p>
                        <label className="flex items-center gap-2 text-sm text-slate-700 cursor-pointer">
                            <input type="checkbox" className="rounded text-blue-600 focus:ring-blue-500" checked={options.featureJob} onChange={(e) => setOptions(o => ({ ...o, featureJob: e.target.checked }))} /> Feature this job
                        </label>
                        <label className="flex items-center gap-2 text-sm text-slate-700 cursor-pointer">
                            <input type="checkbox" className="rounded text-blue-600 focus:ring-blue-500" checked={options.notifyPremium} onChange={(e) => setOptions(o => ({ ...o, notifyPremium: e.target.checked }))} /> Notify premium candidates
                        </label>
                        <label className="flex items-center gap-2 text-sm text-slate-700 cursor-pointer">
                            <input type="checkbox" className="rounded text-blue-600 focus:ring-blue-500" checked={options.addNewsletter} onChange={(e) => setOptions(o => ({ ...o, addNewsletter: e.target.checked }))} /> Add to newsletter
                        </label>
                    </div>

                    <div>
                        <label className="block text-sm font-bold text-slate-900 mb-2">Admin Note (optional):</label>
                        <textarea
                            className="w-full bg-slate-50 border border-slate-200 rounded-lg p-3 text-sm focus:ring-2 focus:ring-blue-500 outline-none"
                            placeholder="E.g. Verified company, good posting"
                            rows={2}
                            value={options.adminNote}
                            onChange={(e) => setOptions(o => ({ ...o, adminNote: e.target.value }))}
                        />
                    </div>
                </div>

                <div className="p-6 border-t border-slate-200 bg-slate-50 flex justify-between items-center bg-white">
                    <button
                        onClick={onClose}
                        disabled={loading}
                        className="px-5 py-2.5 text-slate-600 font-medium hover:bg-slate-100 rounded-lg transition-colors disabled:opacity-50"
                    >
                        Cancel
                    </button>
                    <button
                        onClick={handleSubmit}
                        disabled={loading}
                        className="flex items-center gap-2 px-6 py-2.5 bg-green-600 text-white font-bold rounded-lg hover:bg-green-700 focus:ring-4 focus:ring-green-100 transition shadow-sm disabled:opacity-50"
                    >
                        {loading ? <Loader2 className="w-5 h-5 animate-spin" /> : <CheckCircle className="w-5 h-5" />}
                        {loading ? 'Approving...' : '✓ Approve Job'}
                    </button>
                </div>
            </div>
        </div>
    );
}
