import { Head, Link } from '@inertiajs/react';
import { useLaravelReactI18n } from 'laravel-react-i18n';
import { ArrowRight, ChevronRight } from 'lucide-react';
import { ServiceIcon } from '@/components/frontend/ServiceIcon';
import { Button } from '@/components/ui/button';
import type { ServicePublic } from '@/types/models';

type Props = {
    service: ServicePublic;
    locale: string;
    locale_slugs: { id: string; en: string } | null;
    seo: {
        title: string;
        description: string;
        image: string | null;
    };
};

/**
 * Detail layanan (/{locale}/layanan/{slug}) — hero, konten, sticky sidebar CTA.
 */
export default function ServiceDetail({ service, locale, seo }: Props) {
    const { t } = useLaravelReactI18n();

    return (
        <>
            <Head title={seo.title}>
                <meta name="description" content={seo.description} />
                {seo.image && <meta property="og:image" content={seo.image} />}
            </Head>

            {/* Hero */}
            <section className="relative overflow-hidden bg-gradient-to-br from-primary/5 via-background to-primary/10">
                <div className="mx-auto w-full max-w-7xl px-4 py-14 sm:px-6 sm:py-18">
                    {/* Breadcrumb */}
                    <nav className="text-xs text-muted-foreground" aria-label="Breadcrumb">
                        <ol className="flex flex-wrap items-center gap-1">
                            <li>
                                <Link href={`/${locale}`} className="transition-colors hover:text-foreground">
                                    {t('nav.home')}
                                </Link>
                            </li>
                            <li><ChevronRight className="inline size-3" /></li>
                            <li>
                                <Link href={`/${locale}/layanan`} className="transition-colors hover:text-foreground">
                                    {t('nav.services')}
                                </Link>
                            </li>
                            <li><ChevronRight className="inline size-3" /></li>
                            <li className="text-foreground">{service.name}</li>
                        </ol>
                    </nav>

                    <div className="mt-6 flex items-center gap-4">
                        <div className="flex size-14 shrink-0 items-center justify-center rounded-2xl bg-primary/10 text-primary shadow-sm">
                            <ServiceIcon name={service.icon} className="size-7" />
                        </div>
                        <h1 className="font-poppins text-2xl font-bold tracking-tight sm:text-3xl">
                            {service.name}
                        </h1>
                    </div>

                    {service.short_description && (
                        <p className="mt-4 max-w-2xl text-muted-foreground">
                            {service.short_description}
                        </p>
                    )}
                </div>
            </section>

            {/* Content + Sidebar */}
            <section className="mx-auto w-full max-w-7xl px-4 py-12 sm:px-6 sm:py-16">
                <div className="grid gap-10 lg:grid-cols-3">
                    {/* Main content */}
                    <div className="lg:col-span-2">
                        {service.image && (
                            <div className="overflow-hidden rounded-2xl border shadow-sm">
                                <img
                                    src={service.image}
                                    alt={service.name}
                                    loading="lazy"
                                    className="aspect-[16/9] w-full object-cover"
                                />
                            </div>
                        )}

                        {service.description ? (
                            <article
                                className="tiptap-content prose prose-neutral mt-10 max-w-none dark:prose-invert"
                                dangerouslySetInnerHTML={{ __html: service.description }}
                            />
                        ) : (
                            <p className="mt-10 text-muted-foreground">
                                {locale === 'en' ? 'No description available for this service yet.' : 'Belum ada deskripsi untuk layanan ini.'}
                            </p>
                        )}
                    </div>

                    {/* Sticky sidebar */}
                    <aside className="lg:sticky lg:top-24 lg:self-start">
                        <div className="rounded-2xl border bg-background p-6 shadow-sm">
                            <div className="mb-4 flex size-12 items-center justify-center rounded-xl bg-primary/10 text-primary">
                                <ServiceIcon name={service.icon} className="size-6" />
                            </div>
                            <h3 className="font-semibold tracking-tight">{service.name}</h3>
                            {service.short_description && (
                                <p className="mt-2 text-sm text-muted-foreground">
                                    {service.short_description}
                                </p>
                            )}
                            <Button asChild className="mt-5 w-full">
                                <Link href={`/${locale}/kontak`}>
                                    {t('services.cta')}
                                    <ArrowRight className="size-4" />
                                </Link>
                            </Button>
                        </div>
                    </aside>
                </div>
            </section>
        </>
    );
}
