import { Link, usePage } from '@inertiajs/react';
import type { PropsWithChildren } from 'react';
import AppLogoIcon from '@/components/app-logo-icon';
import {
    LegalFooterLinks,
    type LegalDocumentLink,
} from '@/components/legal-acceptance-notice';
import { useJabesWomenTheme } from '@/hooks/use-jabes-women';
import {
    Card,
    CardContent,
    CardDescription,
    CardHeader,
    CardTitle,
} from '@/components/ui/card';
import { home } from '@/routes';

export default function AuthCardLayout({
    children,
    title,
    description,
}: PropsWithChildren<{
    name?: string;
    title?: string;
    description?: string;
}>) {
    useJabesWomenTheme();
    const { legalDocumentLinks = [] } = usePage<{
        legalDocumentLinks?: LegalDocumentLink[];
    }>().props;

    return (
        <div className="flex min-h-screen min-h-svh flex-col items-center justify-center gap-6 bg-background p-6 md:p-10">
            <div className="flex w-full max-w-md flex-col gap-6">
                <div className="flex flex-col gap-6">
                    <Card className="rounded-xl bg-card/95">
                        <CardHeader className="items-center px-10 pt-8 pb-0 text-center">
                            <Link
                                href={home()}
                                className="mb-2 flex items-center gap-2 self-center font-medium"
                            >
                                <div className="flex h-9 w-9 items-center justify-center">
                                    <AppLogoIcon
                                        className="h-9 w-auto"
                                        alt=""
                                    />
                                </div>
                            </Link>
                            <CardTitle className="text-xl">{title}</CardTitle>
                            <CardDescription>{description}</CardDescription>
                        </CardHeader>
                        <CardContent className="px-10 py-8">
                            {children}
                        </CardContent>
                    </Card>
                    <footer className="flex flex-col items-center gap-4">
                        <div
                            aria-label="Partners"
                            className="flex flex-wrap items-center justify-center gap-6"
                        >
                            <img
                                src="/images/logo-markets.png"
                                alt="Markets"
                                className="h-8 w-auto object-contain opacity-80"
                            />
                            <img
                                src="/images/ultima-markets.png"
                                alt="Ultima Markets"
                                className="h-8 w-auto object-contain opacity-80"
                            />
                        </div>
                        <LegalFooterLinks links={legalDocumentLinks} />
                    </footer>
                </div>
            </div>
        </div>
    );
}
