import { notFound } from 'next/navigation';
import { prisma } from '@/lib/prisma';
import AcaraClientPage from '@/components/admin/acara-client-page';
import { Calendar } from 'lucide-react';

export const dynamic = 'force-dynamic';
export const revalidate = 0;

interface Props {
    params: Promise<{ slug: string }>;
}

export default async function AdminAcaraSlugPage({ params }: Props) {
    const { slug } = await params;

    let acara = null;
    try {
        acara = await prisma.acara.findUnique({
            where: { slug },
            include: {
                tabs: {
                    orderBy: { urutan: 'asc' }
                }
            }
        });
    } catch (e) {
        console.error(e);
    }

    if (!acara) {
        notFound();
    }

    return (
        <div className="space-y-6">
            <div>
                <div className="flex items-center gap-3 mb-1">
                    <div className="p-2 bg-primary/10 rounded-lg">
                        <Calendar className="h-6 w-6 text-primary" />
                    </div>
                    <div>
                        <h1 className="text-3xl font-bold tracking-tight">Acara: {acara.nama}</h1>
                        <p className="text-muted-foreground text-sm mt-0.5">
                            /admin/acara/{slug} · Kelola tabs untuk acara ini.
                        </p>
                    </div>
                </div>
            </div>

            <AcaraClientPage initialAcara={JSON.parse(JSON.stringify(acara))} />
        </div>
    );
}
