import GuestLayout from '@/Layouts/GuestLayout';
import { Head, Link, useForm } from '@inertiajs/react';
import { ArrowRight, Mail } from 'lucide-react';
import { FormEventHandler } from 'react';

export default function VerifyEmail({ status }: { status?: string }) {
    const { post, processing } = useForm({});

    const submit: FormEventHandler = (e) => {
        e.preventDefault();
        post(route('verification.send'));
    };

    return (
        <GuestLayout>
            <Head title="Verify Email" />

            <div className="mb-6 flex flex-col items-center text-center">
                <div className="bg-primary/10 mb-4 flex h-14 w-14 items-center justify-center rounded-2xl">
                    <Mail className="text-primary h-7 w-7" />
                </div>
                <h1 className="pf-display text-foreground text-2xl font-bold tracking-tight">
                    Check your inbox
                </h1>
                <p className="text-muted-foreground mt-2 max-w-sm text-sm leading-relaxed">
                    We sent a verification link to your email address. Click the
                    link to activate your account.
                </p>
            </div>

            {status === 'verification-link-sent' && (
                <div
                    role="status"
                    className="mb-5 rounded-xl border border-green-200 bg-green-50 px-4 py-3 text-center text-sm font-medium text-green-700 dark:border-green-800/50 dark:bg-green-950/40 dark:text-green-400"
                >
                    A new verification link has been sent to your email.
                </div>
            )}

            <form onSubmit={submit} className="space-y-3">
                <button
                    type="submit"
                    disabled={processing}
                    className="pf-btn w-full py-3 text-sm disabled:cursor-not-allowed disabled:opacity-60"
                >
                    {processing ? (
                        'Sending…'
                    ) : (
                        <>
                            <span>Resend Verification Email</span>
                            <ArrowRight
                                className="h-4 w-4"
                                aria-hidden="true"
                            />
                        </>
                    )}
                </button>

                <Link
                    href={route('logout')}
                    method="post"
                    as="button"
                    className="text-muted-foreground hover:text-foreground w-full py-2 text-center text-sm transition-colors"
                >
                    Sign out
                </Link>
            </form>
        </GuestLayout>
    );
}
