import { Form, Head, Link } from '@inertiajs/react';
import { LoaderCircle, Mail, ArrowLeft } from 'lucide-react';
import InputError from '@/components/input-error';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { email } from '@/routes/password';

export default function ForgotPassword({ status }: { status?: string }) {
    return (
        <>
            <Head title="Forgot Password" />

            {status && (
                <div className="p-3 rounded-xl bg-emerald-500/10 border border-emerald-500/30 text-emerald-400 text-xs font-semibold text-center mb-4">
                    {status}
                </div>
            )}

            <div className="space-y-4">
                <Form {...email.form()}>
                    {({ processing, errors }) => (
                        <>
                            <div className="space-y-4">
                                <div>
                                    <Label htmlFor="email" className="text-xs font-bold text-slate-300 uppercase tracking-wider block mb-1">
                                        Registered Email Address
                                    </Label>
                                    <div className="relative">
                                        <Input
                                            id="email"
                                            type="email"
                                            name="email"
                                            autoComplete="off"
                                            autoFocus
                                            placeholder="admin@techinsoul.com"
                                            className="w-full bg-[#060B18] border border-slate-800 rounded-xl px-4 py-2.5 pl-10 text-sm text-white placeholder-slate-500 focus:outline-none focus:border-[#00F2FE]"
                                        />
                                        <Mail className="w-4 h-4 text-slate-500 absolute left-3.5 top-3" />
                                    </div>
                                    <InputError message={errors.email} className="mt-1" />
                                </div>

                                <button
                                    type="submit"
                                    disabled={processing}
                                    className="btn-aqua w-full py-3 rounded-xl text-sm font-bold flex items-center justify-center gap-2 mt-2"
                                >
                                    {processing && (
                                        <LoaderCircle className="h-4 w-4 animate-spin" />
                                    )}
                                    Send Password Reset Link
                                </button>
                            </div>
                        </>
                    )}
                </Form>

                <div className="text-center text-xs text-slate-400 pt-2 border-t border-slate-800/60">
                    <Link href="/login" className="inline-flex items-center gap-1.5 text-[#00F2FE] font-semibold hover:underline">
                        <ArrowLeft className="w-3.5 h-3.5" /> Return to Login
                    </Link>
                </div>
            </div>
        </>
    );
}

ForgotPassword.layout = {
    title: 'Reset Password',
    description: 'Enter your email address to receive a secure password reset link',
};
