import { notFound } from 'next/navigation';
import { getOrCreateUKK } from '@/lib/admin-actions';
import UKKClientPage from '@/components/admin/ukk-client-page';
import { Layers } from 'lucide-react';

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

const VALID_SLUGS = ['cakrawala', 'khauf'];

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

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

    if (!VALID_SLUGS.includes(slug)) {
        notFound();
    }

    const ukk = await getOrCreateUKK(slug);

    if (!ukk) {
        return (
            <div className="flex items-center justify-center min-h-[40vh]">
                <p className="text-muted-foreground">Gagal memuat data UKK. Coba muat ulang halaman.</p>
            </div>
        );
    }

    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">
                        <Layers className="h-6 w-6 text-primary" />
                    </div>
                    <div>
                        <h1 className="text-3xl font-bold tracking-tight">UKK {ukk.nama}</h1>
                        <p className="text-muted-foreground text-sm mt-0.5">
                            /admin/ukk/{slug} · Kelola profil, program kerja, dan anggota.
                        </p>
                    </div>
                </div>
            </div>

            <UKKClientPage initialUKK={JSON.parse(JSON.stringify(ukk))} />
        </div>
    );
}
