import InputError from '@/Components/InputError';
import PrimaryButton from '@/Components/PrimaryButton';
import TextInput from '@/Components/TextInput';
import GuestLayout from '@/Layouts/GuestLayout';
import { Head, Link, useForm } from '@inertiajs/react';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/Components/ui/card.jsx";
import { Label } from "@/Components/ui/label.jsx";
import { Alert, AlertDescription } from "@/components/ui/alert";

export default function ForgotPassword({ status }) {
    const { data, setData, post, processing, errors } = useForm({
        email: '',
    });

    const submit = (e) => {
        e.preventDefault();

        post(route('password.email'));
    };

    return (
        <GuestLayout>
            <Head title="Forgot Password" />
            <div className="flex flex-col gap-6">
                { status && (<Alert>
                    <AlertDescription>
                        { status }
                    </AlertDescription>
                </Alert> ) }
                <Card>
                    <CardHeader>
                        <CardTitle className="text-2xl">Forgot Password</CardTitle>
                        <CardDescription>
                            Forgot your password? No problem. Just let us know your email
                            address and we will email you a password reset link that will
                            allow you to choose a new one.
                        </CardDescription>
                    </CardHeader>
                    <CardContent>
                        <form onSubmit={ submit }>
                            <div className="flex flex-col gap-6">
                                <div className="grid gap-2">
                                    <Label htmlFor="email">E-mail Address</Label>
                                    <TextInput type="email" id="email" placeholder="me@yumj.in" value={ data.email }
                                               onChange={ (e) => setData('email', e.target.value) } required />
                                    <InputError message={ errors.email } className="mt-2" />
                                </div>
                                <PrimaryButton type="submit" disabled={ processing }
                                               className="w-full">Email Password Reset Link</PrimaryButton>
                            </div>
                            <div className="mt-4 text-center text-sm">
                                Return to &nbsp;
                                <Link href={ route('login') } className="underline underline-offset-4">
                                    Login
                                </Link>
                                &nbsp; | &nbsp;
                                <Link href={ route('register') } className="underline underline-offset-4">
                                    Sign up
                                </Link>
                            </div>
                        </form>
                    </CardContent>
                </Card>
            </div>
        </GuestLayout>
    );
}
