import { Form, Head } from '@inertiajs/react';
import { LoaderCircle } from 'lucide-react';
import InputError from '@/components/input-error';
import TextLink from '@/components/text-link';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import AuthLayout from '@/layouts/auth-layout';
import { home } from '@/routes';
import { email } from '@/routes/password';

export default function ForgotPassword({ status }: { status?: string }) {
    return (
        <AuthLayout
            title="Mot de passe oublié"
            description="Entrez votre adresse email pour recevoir un lien de réinitialisation"
            showLogo={true}
        >
            <Head title="Mot de passe oublié" />

            <div className="w-full max-w-md mx-auto">
                {status && (
                    <div className="mb-6 rounded-xl bg-gradient-to-r from-green-50 to-emerald-50 border border-green-200 p-4 text-center dark:from-green-900/20 dark:to-emerald-900/20 dark:border-green-700">
                        <span className="text-sm font-medium text-green-700 dark:text-green-300">{status}</span>
                    </div>
                )}

                <div className="rounded-2xl border border-gray-200 bg-white p-8 shadow-xl dark:border-gray-700 dark:bg-gray-800">
                    <Form {...email.form()}>
                        {({ processing, errors }) => (
                            <>
                                <div className="space-y-3">
                                    <Label htmlFor="email">Adresse email</Label>
                                    <Input
                                        id="email"
                                        type="email"
                                        name="email"
                                        autoComplete="email"
                                        autoFocus
                                        required
                                        placeholder="email@exemple.com"
                                        className="h-12 rounded-lg border-2"
                                    />
                                    <InputError message={errors.email} />
                                </div>

                                <Button
                                    type="submit"
                                    className="mt-6 h-12 w-full"
                                    disabled={processing}
                                >
                                    {processing && <LoaderCircle className="h-4 w-4 animate-spin mr-2" />}
                                    Envoyer le lien de réinitialisation
                                </Button>
                            </>
                        )}
                    </Form>

                    <p className="mt-6 text-center text-sm text-muted-foreground">
                        <TextLink href={home.url()}>Retour à l'accueil</TextLink>
                    </p>
                </div>
            </div>
        </AuthLayout>
    );
}
