import React from 'react';
import GuestLayout from '@/Layouts/GuestLayout';
import { Head, Link, useForm } from '@inertiajs/react';

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

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

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

            <div className="mb-8 anim-down">
                <div className="w-12 h-12 bg-[#3D4E4B]/5 rounded-2xl flex items-center justify-center mb-6">
                    <svg className="w-5 h-5 text-[#3D4E4B]" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
                        <path strokeLinecap="round" strokeLinejoin="round" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" />
                    </svg>
                </div>
                <h1 className="text-2xl font-bold text-[#1A2421] tracking-tight">Check your email</h1>
                <p className="mt-1.5 text-sm text-gray-400 font-medium 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 className="mb-6 px-4 py-3 rounded-xl bg-emerald-50 border border-emerald-100 text-sm font-semibold text-emerald-700 anim-fade">
                    A new verification link has been sent to your email.
                </div>
            )}

            <form onSubmit={submit} className="anim-up" style={{ animationDelay: '0.1s' }}>
                <button
                    type="submit"
                    disabled={processing}
                    className="w-full h-11 rounded-xl bg-[#3D4E4B] hover:bg-[#2D3A38] text-white text-sm font-bold tracking-tight transition-colors duration-200 flex items-center justify-center gap-2 disabled:opacity-60 disabled:cursor-not-allowed"
                >
                    {processing ? (
                        <>
                            <svg className="w-4 h-4 animate-spin text-white/60" fill="none" viewBox="0 0 24 24">
                                <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
                                <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z" />
                            </svg>
                            Sending…
                        </>
                    ) : 'Resend verification email'}
                </button>
            </form>

            <div className="mt-5 text-center anim-fade" style={{ animationDelay: '0.18s' }}>
                <Link
                    href={route('logout')}
                    method="post"
                    as="button"
                    className="text-sm font-semibold text-gray-400 hover:text-[#3D4E4B] transition-colors duration-200"
                >
                    Sign out
                </Link>
            </div>
        </GuestLayout>
    );
}
