import { Link } from '@inertiajs/react';
import { Settings2, ShieldCheck, UserRound } from 'lucide-react';
import type { PropsWithChildren } from 'react';
import { useCurrentUrl } from '@/hooks/use-current-url';
import { cn, toUrl } from '@/lib/utils';
import { edit } from '@/routes/profile';
import { edit as editSecurity } from '@/routes/security';

const settingsNavigation = [
    { title: 'Profile', href: edit(), icon: UserRound },
    { title: 'Security', href: editSecurity(), icon: ShieldCheck },
];

export default function SettingsLayout({ children }: PropsWithChildren) {
    const { isCurrentOrParentUrl } = useCurrentUrl();

    return (
        <div className="min-h-full bg-[#e9e6dc]">
            <section className="relative isolate overflow-hidden bg-[#090c0d] px-4 py-9 text-white sm:px-6">
                <div className="absolute inset-0 -z-20 bg-[radial-gradient(circle_at_80%_8%,#e8422b55,transparent_27%),linear-gradient(115deg,#090c0d_18%,#172022_100%)]" />
                <div
                    aria-hidden="true"
                    className="race-track-detail race-track-detail--inverse"
                />
                <div className="mx-auto flex max-w-6xl flex-wrap items-end justify-between gap-5">
                    <div>
                        <p className="text-[10px] font-black tracking-[.24em] text-[#f6c84f] uppercase">
                            Race account
                        </p>
                        <h1 className="mt-3 text-4xl leading-[.9] font-black tracking-[-.07em]">
                            SETTINGS
                            <span className="text-[#e8422b]">.</span>
                        </h1>
                        <p className="mt-3 max-w-md text-sm leading-6 text-white/60">
                            Manage your account details and security controls.
                        </p>
                    </div>
                    <span className="grid size-11 place-items-center rounded-sm bg-[#e8422b] text-white">
                        <Settings2 size={21} />
                    </span>
                </div>
            </section>

            <div className="mx-auto max-w-6xl px-4 py-8 sm:px-6 sm:py-10">
                <nav
                    aria-label="Settings"
                    className="flex [scrollbar-width:none] gap-2 overflow-x-auto pb-2"
                >
                    {settingsNavigation.map((item) => {
                        const isActive = isCurrentOrParentUrl(item.href);
                        const Icon = item.icon;

                        return (
                            <Link
                                key={toUrl(item.href)}
                                href={item.href}
                                className={cn(
                                    'inline-flex shrink-0 items-center gap-2 rounded-full px-4 py-2.5 text-xs font-black transition',
                                    isActive
                                        ? 'bg-[#111516] text-white shadow-sm shadow-[#111516]/15'
                                        : 'border border-[#111516]/15 bg-[#f7f5ef] text-[#59615b] hover:border-[#e8422b] hover:text-[#e8422b]',
                                )}
                            >
                                <Icon size={15} />
                                {item.title}
                            </Link>
                        );
                    })}
                </nav>

                <section className="mt-6 max-w-2xl rounded-[1.7rem] bg-[#f7f5ef] p-5 shadow-sm shadow-[#111516]/5 sm:p-7">
                    {children}
                </section>
            </div>
        </div>
    );
}
