import { Form, Head } from '@inertiajs/react';
import { AuthButton } from '@/components/auth-button';
import { AuthPasswordInput } from '@/components/auth-input';
import InputError from '@/components/input-error';
import { Label } from '@/components/ui/label';
import { Spinner } from '@/components/ui/spinner';
import { store } from '@/routes/password/confirm';

export default function ConfirmPassword() {
    return (
        <>
            <Head title="Confirmer le mot de passe" />

            <Form {...store.form()} resetOnSuccess={['password']}>
                {({ processing, errors }) => (
                    <div className="space-y-6">
                        <div className="grid gap-2">
                            <Label htmlFor="password" className="sr-only">
                                Mot de passe
                            </Label>
                            <AuthPasswordInput
                                id="password"
                                name="password"
                                placeholder="Mot de passe"
                                autoComplete="current-password"
                                autoFocus
                            />

                            <InputError message={errors.password} />
                        </div>

                        <AuthButton
                            disabled={processing}
                            data-test="confirm-password-button"
                        >
                            {processing && <Spinner />}
                            Confirmer le mot de passe
                        </AuthButton>
                    </div>
                )}
            </Form>
        </>
    );
}

ConfirmPassword.layout = {
    title: 'Confirmer le mot de passe',
    description:
        "Ceci est une zone sécurisée de l'application. Veuillez confirmer votre mot de passe avant de continuer.",
};
