import AltivateLayout from '@/Layouts/AltivateLayout';
import { Head, Link } from '@inertiajs/react';
import { ArrowLeft, MapPin, Tag, Calendar } from 'lucide-react';

interface Metric {
    k: string;
    v: string;
}

interface CaseStudy {
    id: number;
    title: string;
    tag: string | null;
    location: string | null;
    content: string | null;
    metrics: Metric[] | null;
    created_at: string;
    media?: {
        url: string;
    };
}

export default function Show({ caseStudy }: { caseStudy: CaseStudy }) {
    return (
        <AltivateLayout title={caseStudy.title}>
            <Head title={caseStudy.title} />
            
            <div className="bg-white min-h-screen">
                {/* Header Section */}
                <header className="relative pt-32 pb-20 md:pt-40 md:pb-32 overflow-hidden">
                    {/* Background Detail */}
                    <div className="absolute top-0 left-0 w-full h-full opacity-[0.03] pointer-events-none">
                        <div className="absolute inset-0 bg-[radial-gradient(#000_1px,transparent_1px)] [background-size:20px_20px]" />
                    </div>

                    <div className="container-x relative z-10">
                        <Link 
                            href={route('case_studies')}
                            className="inline-flex items-center gap-2 text-sm text-[#8C92AC] hover:text-ink transition-colors mb-12"
                        >
                            <ArrowLeft className="h-4 w-4" />
                            Back to Case Studies
                        </Link>

                        <div className="max-w-4xl">
                            <div className="flex flex-wrap items-center gap-4 mb-8">
                                <span className="px-4 py-1.5 rounded-full border border-[#E8E6DF] text-[11px] font-bold uppercase tracking-widest text-[#8C92AC] bg-white">
                                    {caseStudy.tag}
                                </span>
                                <div className="flex items-center gap-2 text-[11px] font-bold uppercase tracking-widest text-[#8C92AC]">
                                    <MapPin className="h-3.5 w-3.5" />
                                    {caseStudy.location}
                                </div>
                            </div>

                            <h1 className="font-display text-[clamp(2rem,6vw,4.5rem)] leading-[1.05] text-ink mb-10">
                                {caseStudy.title}
                            </h1>

                            <div className="grid grid-cols-2 md:grid-cols-4 gap-8 py-10 border-y border-[#F0EDE8]">
                                {caseStudy.metrics?.map((m, i) => (
                                    <div key={i} className="space-y-1">
                                        <div className="font-display text-4xl text-accent">{m.k}</div>
                                        <div className="text-[10px] uppercase tracking-widest font-bold text-[#8C92AC] leading-tight max-w-[120px]">{m.v}</div>
                                    </div>
                                ))}
                                <div className="space-y-1">
                                    <div className="flex items-center gap-2 text-[#C0BDBA] mb-1">
                                        <Calendar className="h-4 w-4" />
                                        <span className="text-[10px] font-bold uppercase tracking-widest">Published</span>
                                    </div>
                                    <div className="text-[13px] font-semibold text-ink">
                                        {new Date(caseStudy.created_at).toLocaleDateString('en-US', { month: 'long', year: 'numeric' })}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </header>

                {/* Main Content */}
                <section className="container-x pb-32">
                    <div className="grid lg:grid-cols-12 gap-16">
                        <div className="lg:col-span-8">
                            {caseStudy.media?.url && (
                                <div className="aspect-[16/9] rounded-[2.5rem] overflow-hidden bg-[#FAFAF8] border border-[#F0EDE8] mb-16 shadow-2xl shadow-ink/5">
                                    <img src={caseStudy.media.url} alt={caseStudy.title} className="w-full h-full object-cover" />
                                </div>
                            )}

                            <div 
                                className="prose prose-lg md:prose-xl prose-ink max-w-none prose-headings:font-display prose-headings:font-normal prose-headings:tracking-tight prose-p:text-[#4A4A4A] prose-p:leading-relaxed prose-a:text-accent prose-img:rounded-3xl"
                                dangerouslySetInnerHTML={{ __html: caseStudy.content || '' }}
                            />
                        </div>

                        <div className="lg:col-span-4">
                            <div className="sticky top-32 space-y-8">
                                <div className="p-8 rounded-[2rem] bg-[#FAFAF8] border border-[#F0EDE8]">
                                    <h3 className="font-display text-2xl mb-4">Ready for these results?</h3>
                                    <p className="text-[#8C92AC] text-sm leading-relaxed mb-8">
                                        Every business is a system. If your system isn't producing the growth you want, we can help you find the broken parts and fix them.
                                    </p>
                                    <Link
                                        href={route('audit')}
                                        className="w-full inline-flex h-12 items-center justify-center rounded-full bg-ink text-white text-sm font-bold hover:bg-accent transition-all shadow-lg"
                                    >
                                        Book a Growth Audit call
                                    </Link>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
            </div>
        </AltivateLayout>
    );
}
