import React from 'react';
import { Head, useForm, Link } from '@inertiajs/react';
import { Key, Lock, ArrowRight, ShieldCheck, CheckCircle } from 'lucide-react';

interface Props {
    demoLogins: Array<{
        role: string;
        email: string;
        password: string;
    }>;
}

export default function Login({ demoLogins = [] }: Props) {
    const form = useForm({
        email: 'admin@primonhotel.com',
        password: 'password123',
        remember: true,
    });

    const handleLogin = (e: React.FormEvent) => {
        e.preventDefault();
        form.post('/login');
    };

    const handleQuickFill = (email: string) => {
        form.setData({
            ...form.data,
            email: email,
            password: 'password123',
        });
    };

    return (
        <div className="min-h-screen bg-[#1A1A1A] text-[#FBF9F5] flex flex-col justify-between p-4 sm:p-8">
            <Head title="Staff Authentication — Primon Hotel PMS" />

            {/* Top Bar */}
            <div className="max-w-6xl mx-auto w-full flex items-center justify-between py-4">
                <Link href="/" className="flex items-center gap-3">
                    <div className="w-9 h-9 rounded-full border border-[#C5A880] flex items-center justify-center bg-black/40">
                        <span className="font-serif text-lg font-bold text-[#C5A880]">P</span>
                    </div>
                    <span className="font-serif text-lg tracking-widest uppercase text-white font-medium">Primon Hotel</span>
                </Link>

                <Link href="/" className="text-xs font-semibold uppercase text-gray-400 hover:text-white">
                    ← Return to Website
                </Link>
            </div>

            {/* Main Center Auth Card */}
            <div className="max-w-md w-full mx-auto my-12 bg-[#222222] border border-[#C5A880]/30 rounded-3xl p-8 sm:p-10 shadow-2xl space-y-8">
                <div className="text-center space-y-2">
                    <div className="w-12 h-12 rounded-full bg-[#C5A880]/20 border border-[#C5A880] text-[#C5A880] flex items-center justify-center mx-auto mb-2">
                        <Key className="h-6 w-6" />
                    </div>
                    <h1 className="font-serif text-3xl font-light text-white">Staff Authentication</h1>
                    <p className="text-xs text-gray-400 font-light">Enter authorized employee credentials to access operational PMS.</p>
                </div>

                {/* Error message */}
                {form.errors.email && (
                    <div className="bg-red-900/50 border border-red-500/50 text-red-200 text-xs p-3 rounded-xl">
                        {form.errors.email}
                    </div>
                )}

                <form onSubmit={handleLogin} className="space-y-4">
                    <div>
                        <label className="text-[10px] uppercase tracking-wider text-[#C5A880] font-semibold block mb-1">
                            Employee Email Address
                        </label>
                        <input
                            type="email"
                            required
                            value={form.data.email}
                            onChange={(e) => form.setData('email', e.target.value)}
                            className="w-full bg-white/5 border border-white/20 text-white rounded-xl px-3.5 py-2.5 text-xs focus:outline-none focus:border-[#C5A880]"
                        />
                    </div>

                    <div>
                        <label className="text-[10px] uppercase tracking-wider text-[#C5A880] font-semibold block mb-1">
                            Password
                        </label>
                        <input
                            type="password"
                            required
                            value={form.data.password}
                            onChange={(e) => form.setData('password', e.target.value)}
                            className="w-full bg-white/5 border border-white/20 text-white rounded-xl px-3.5 py-2.5 text-xs focus:outline-none focus:border-[#C5A880]"
                        />
                    </div>

                    <div className="flex items-center justify-between text-xs text-gray-400">
                        <label className="flex items-center gap-2 cursor-pointer">
                            <input
                                type="checkbox"
                                checked={form.data.remember}
                                onChange={(e) => form.setData('remember', e.target.checked)}
                                className="rounded bg-white/10 border-white/20 text-[#C5A880]"
                            />
                            <span>Remember Device</span>
                        </label>
                    </div>

                    <button
                        type="submit"
                        disabled={form.processing}
                        className="w-full bg-[#C5A880] hover:bg-[#DFC7A5] text-[#1A1A1A] py-3.5 rounded-xl text-xs font-bold uppercase tracking-widest transition-all shadow flex items-center justify-center gap-2"
                    >
                        <span>Access Operations</span>
                        <ArrowRight className="h-4 w-4" />
                    </button>
                </form>

                {/* Quick Demo Fill Buttons for Testing */}
                <div className="pt-6 border-t border-white/10 space-y-3">
                    <span className="text-[10px] uppercase tracking-widest text-[#C5A880] font-semibold block text-center">
                        Quick Demo Switcher (Preloaded Roles)
                    </span>
                    <div className="grid grid-cols-2 gap-2">
                        {demoLogins.map((d, i) => (
                            <button
                                key={i}
                                type="button"
                                onClick={() => handleQuickFill(d.email)}
                                className="p-2 rounded-lg bg-white/5 hover:bg-white/10 border border-white/10 text-left transition-colors truncate"
                            >
                                <span className="text-[10px] font-bold text-white block truncate">{d.role}</span>
                                <span className="text-[9px] text-gray-400 truncate block">{d.email}</span>
                            </button>
                        ))}
                    </div>
                </div>
            </div>

            {/* Footer */}
            <div className="text-center text-[10px] text-gray-500 py-4">
                Primon Hotel Management System • Encrypted & Audited Connection
            </div>
        </div>
    );
}
