import { redirect } from "next/navigation";

import { MotionFade } from "@/components/motion-fade";
import { AdminDashboardShell } from "@/components/admin/admin-dashboard-shell";
import { readFlash } from "@/lib/admin-feedback";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { getAdminAppPath } from "@/lib/admin-routing";
import { UiKitShowcase } from "@/components/ui/ui-kit-showcase";

export const dynamic = "force-dynamic";

const copy = {
  title: "UI Kit",
  subtitle: "Globale Referenz fuer das visuelle System im Admin Bereich.",
  maintenance: "Wartungsmodus",
  overview: "Uebersicht",
  uiKit: "UI Kit",
  media: "Media",
  siteSettings: "Settings",
  portfolio: "Portfolio",
  logout: "Ausloggen",
  backToSite: "Zur Website",
};

export default async function AdminUiKitPage({
  searchParams,
}: {
  searchParams?: Promise<{ success?: string; error?: string }>;
}) {
  const flash = readFlash(await searchParams);

  const authenticated = await isAdminAuthenticated();

  if (!authenticated) {
    redirect(getAdminAppPath("/"));
  }

  async function logoutAction() {
    "use server";

    await clearAdminSessionCookie();
    redirect(getAdminAppPath("/"));
  }

  return (
    <AdminDashboardShell
      copy={copy}
      active="ui-kit"
      flash={flash}
      logoutAction={logoutAction}
      headerTitle={copy.title}
      headerDescription={copy.subtitle}
    >
      <MotionFade delay={0.1}>
        <UiKitShowcase localeKey="de" />
      </MotionFade>
    </AdminDashboardShell>
  );
}
