import { redirect } from "next/navigation";

import { MarqueeSettingsForm } from "@/components/admin/marquee-settings-form";
import { AdminDashboardShell } from "@/components/admin/admin-dashboard-shell";
import { MotionFade } from "@/components/motion-fade";
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
import { getAdminAppPath } from "@/lib/admin-routing";
import { getMarqueeSettings } from "@/lib/app-config";

import { saveMarqueeSettingsAction } from "./actions";

export const dynamic = "force-dynamic";

const copy = {
  title: "Marquee",
  subtitle: "Scrollende Textzeilen fuer die Startseite pro Sprache verwalten.",
  overview: "Uebersicht",
  maintenance: "Wartungsmodus",
  uiKit: "UI Kit",
  media: "Media",
  siteSettings: "Settings",
  marquee: "Marquee",
  smtp: "SMTP",
  portfolio: "Portfolio",
  logout: "Ausloggen",
  backToSite: "Zur Website",
};

export default async function AdminMarqueePage() {
  if (!(await isAdminAuthenticated())) {
    redirect(getAdminAppPath("/"));
  }

  async function logoutAction() {
    "use server";

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

  const marqueeSettings = await getMarqueeSettings();

  return (
    <AdminDashboardShell
      copy={copy}
      active="marquee"
      logoutAction={logoutAction}
      headerTitle={copy.title}
      headerDescription={copy.subtitle}
    >
      <div className="space-y-6">
        <MotionFade delay={0.14}>
          <MarqueeSettingsForm
            action={saveMarqueeSettingsAction}
            initialSettings={marqueeSettings}
          />
        </MotionFade>
      </div>
    </AdminDashboardShell>
  );
}
