import { useEffect } from 'react';
import InputError from '@/Components/InputError';
import GuestLayout from '@/Layouts/GuestLayout';
import { Head, useForm } from '@inertiajs/react';
import useTranslation from '@/hooks/useTranslation'; 
import { Button } from '@/Components/ui/button';
import { Input } from '@/Components/ui/input';
import { Label } from '@/Components/ui/label';
import { Card, CardContent, CardDescription, CardHeader, CardTitle, CardFooter } from '@/Components/ui/card';
import { Loader2 } from 'lucide-react';

export default function ConfirmPassword() {
    const { t } = useTranslation(); 

    const { data, setData, post, processing, errors, reset } = useForm({
        password: '',
    });

    useEffect(() => {
        return () => {
            reset('password');
        };
    }, []);

    const submit = (e) => {
        e.preventDefault();
        post(route('password.confirm'));
    };

    return (
        <GuestLayout>
            <Head title={t('_confirm_password', 'Confirm Password')} />

            <div className="flex items-center justify-center min-h-[80vh]">
                <Card className="w-full max-w-md shadow-lg border-0 sm:border">
                    <CardHeader>
                        <CardTitle className="text-2xl font-bold">
                            {t('_confirm_password', 'Confirm Password')}
                        </CardTitle>
                        <CardDescription>
                            {t('_secure_area_notice', 'This is a secure area of the application. Please confirm your password before continuing.')}
                        </CardDescription>
                    </CardHeader>
                    
                    <CardContent>
                        <form onSubmit={submit}>
                            <div className="space-y-2">
                                <Label htmlFor="password">
                                    {t('_auth_password', 'Password')}
                                </Label>
                                <Input
                                    id="password"
                                    type="password"
                                    name="password"
                                    value={data.password}
                                    className="mt-1 block w-full"
                                    autoFocus
                                    onChange={(e) => setData('password', e.target.value)}
                                />
                                <InputError message={errors.password} className="mt-2" />
                            </div>

                            <div className="mt-6 flex items-center justify-end">
                                <Button className="ms-4" disabled={processing}>
                                    {processing && <Loader2 className="me-2 h-4 w-4 animate-spin" />}
                                    {t('_confirm', 'Confirm')}
                                </Button>
                            </div>
                        </form>
                    </CardContent>
                </Card>
            </div>
        </GuestLayout>
    );
}