import { Link, usePage } from '@inertiajs/react';
import AppLogoIcon from '@/components/app-logo-icon';
import { LogYardIllustration } from '@/components/log-yard-illustration';
import { home } from '@/routes';
import type { AuthLayoutProps } from '@/types';

export default function AuthSplitLayout({
    children,
    title,
    description,
}: AuthLayoutProps) {
    const { name, website } = usePage().props;

    return (
        <div className="flex min-h-dvh items-center justify-center overflow-y-auto bg-[#eeebe4] p-4 py-8 sm:p-8 dark:bg-background">
            <div className="grid w-full max-w-5xl overflow-hidden rounded-[28px] bg-white p-3 shadow-[0_30px_80px_-30px_rgba(28,20,16,0.35)] lg:grid-cols-2 dark:bg-card">
                <div className="relative hidden flex-col justify-between overflow-hidden rounded-[22px] bg-gradient-to-br from-[#8b5e34] to-[#4a3220] p-10 text-[#f5f0e6] lg:flex">
                    <Link
                        href={home()}
                        className="relative z-10 flex items-center gap-2.5 text-lg font-semibold"
                    >
                        <AppLogoIcon className="size-8 fill-current text-[#f5f0e6]" />
                        {name}
                    </Link>

                    <div className="relative z-10 flex flex-1 items-center justify-center py-6">
                        <LogYardIllustration className="h-auto w-full max-w-sm drop-shadow-xl" />
                    </div>

                    <div className="relative z-10">
                        <h2 className="text-[28px] leading-[1.2] font-semibold text-balance">
                            Pilotez votre parc à bois en toute simplicité
                        </h2>
                        <p className="mt-3 text-[15px] leading-relaxed text-[#e8dcc8]">
                            Entrées de grumes, production et ventes locales et
                            export, centralisées et tracées.
                        </p>
                    </div>
                </div>

                <div className="flex flex-col px-6 py-10 sm:px-12 lg:px-14">
                    <Link
                        href={home()}
                        className="mb-8 flex items-center gap-2.5 lg:hidden"
                    >
                        <span className="flex size-9 items-center justify-center rounded-md bg-[#8b5e34]">
                            <AppLogoIcon className="size-5 fill-current text-[#f5f0e6]" />
                        </span>
                        <span className="text-sm font-medium text-[#2d2420] dark:text-foreground">
                            {name}
                        </span>
                    </Link>

                    <div className="flex flex-1 flex-col justify-center">
                        <div className="mx-auto w-full max-w-sm">
                            <div className="flex flex-col gap-2">
                                <h1 className="text-2xl font-semibold text-[#2d2420] dark:text-foreground">
                                    {title}
                                </h1>
                                <p className="text-sm text-balance text-[#796a57] dark:text-muted-foreground">
                                    {description}
                                </p>
                            </div>

                            <div className="mt-8">{children}</div>
                        </div>
                    </div>

                    <p className="mx-auto mt-10 w-full max-w-sm text-center text-xs text-[#9c8c75] dark:text-muted-foreground">
                        © {new Date().getFullYear()} {name} — Développé par{' '}
                        <a
                            href={website.developerUrl}
                            target="_blank"
                            rel="noopener noreferrer"
                            className="font-medium text-[#8b5e34] hover:underline dark:text-foreground"
                        >
                            {website.developerName}
                        </a>
                    </p>
                </div>
            </div>
        </div>
    );
}
