import { Head } from '@inertiajs/react';
import { type ReactNode, useMemo } from 'react';

interface Props {
    children: ReactNode;
    title?: string;
}

const particles = Array.from({ length: 12 }, (_, i) => ({
    left: `${10 + (i * 6.7) % 80}%`,
    bottom: `-${(i * 2.3) % 10}%`,
    animationDuration: `${10 + (i * 1.3) % 15}s`,
    animationDelay: `${(i * 0.7) % 8}s`,
    width: `${2 + (i * 0.3) % 2}px`,
    height: `${2 + (i * 0.3) % 2}px`,
}));

export default function GuestLayout({ children, title }: Props) {
    return (
        <>
            <Head title={title} />

            {/* Full-screen container with CSS aurora aesthetic */}
            <div className="relative flex min-h-dvh w-full flex-col items-center justify-center overflow-hidden bg-slate-50 dark:bg-slate-950 text-slate-900 dark:text-slate-100 font-sans p-6 md:p-10 transition-colors duration-300">

                {/* CSS Aurora Mesh Background */}
                <div className="aurora-mesh">
                    <div className="aurora-orb-accent" />

                    {/* Floating particles */}
                    {particles.map((p, i) => (
                        <div
                            key={i}
                            className="aurora-particle"
                            style={{
                                left: p.left,
                                bottom: p.bottom,
                                animationDuration: p.animationDuration,
                                animationDelay: p.animationDelay,
                                width: p.width,
                                height: p.height,
                            }}
                        />
                    ))}
                </div>

                {/* Subtle dot grid overlay */}
                <div
                    className="absolute inset-0 z-[1] opacity-10 dark:opacity-[0.06] pointer-events-none"
                    style={{
                        backgroundImage: 'radial-gradient(currentColor 1px, transparent 1px)',
                        backgroundSize: '24px 24px',
                    }}
                />

                {/* Keyframes for card entrance */}
                <style dangerouslySetInnerHTML={{__html: `
                    @keyframes zoomInUp {
                        0% { opacity: 0; transform: scale(0.95) translateY(15px); }
                        100% { opacity: 1; transform: scale(1) translateY(0); }
                    }
                    .animate-zoom-in-up {
                        animation: zoomInUp 0.7s cubic-bezier(0.16, 1, 0.3, 1) forwards;
                    }
                `}} />

                {/* Login Card */}
                <div className="relative z-10 w-full max-w-[420px] animate-zoom-in-up my-4 sm:my-0">
                    <div className="flex flex-col gap-5 sm:gap-6 rounded-[2rem] border border-slate-900/10 dark:border-white/15 bg-white/70 dark:bg-slate-900/55 p-6 sm:p-8 shadow-2xl shadow-black/5 dark:shadow-black/30 backdrop-blur-2xl ring-1 ring-slate-900/5 dark:ring-white/5 transition-all duration-300">
                        {children}
                    </div>
                </div>

                {/* Footer */}
                <footer className="relative z-10 mt-6 flex items-center justify-center">
                    <p className="text-[10px] sm:text-xs text-slate-500 dark:text-slate-400/70 font-medium">
                        &copy; {new Date().getFullYear()} UtiClass &bull; MTsN 1 Pohuwato &bull; Madrasah Wisata Digital
                    </p>
                </footer>
            </div>
        </>
    );
}
