import { Form, Head } from '@inertiajs/react';
import AuthField, {
    AuthFooterLink,
    AuthStatus,
    AuthSubmitButton,
    authInputClasses,
    errorAttributes,
} from '@/components/auth/auth-field';
import { login } from '@/routes';
import { email } from '@/routes/password';

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

            <AuthStatus message={status} />

            <Form {...email.form()} className="flex flex-col gap-5">
                {({ processing, errors }) => (
                    <>
                        <AuthField
                            id="email"
                            required
                            label="Email address"
                            error={errors.email}
                        >
                            <input
                                id="email"
                                type="email"
                                name="email"
                                required
                                autoFocus
                                autoComplete="email"
                                placeholder="you@example.com"
                                className={authInputClasses}
                                {...errorAttributes('email', errors.email)}
                            />
                        </AuthField>

                        <AuthSubmitButton
                            processing={processing}
                            className="mt-2"
                            data-test="email-password-reset-link-button"
                        >
                            Email me a reset link
                        </AuthSubmitButton>

                        <AuthFooterLink
                            prompt="Remembered it?"
                            href={login()}
                            label="Back to sign in"
                        />
                    </>
                )}
            </Form>
        </>
    );
}

ForgotPassword.layout = {
    title: 'Forgot your password?',
    description:
        'Enter the email you signed up with and we will send you a link to choose a new one.',
};
