import type { Metadata } from "next";
import { importSiteAction, updateSettingsAction } from "@/actions/settings";
import { ImportExportSection } from "@/components/admin/ImportExportSection";
import { SettingsForm } from "@/components/admin/SettingsForm";
import { requireAdmin } from "@/lib/auth/dal";
import { listPublishedPages } from "@/lib/services/pages";
import { getSettings, listNavItems } from "@/lib/services/settings";
import { listAllTags } from "@/lib/services/tags";

export const metadata: Metadata = { title: "Site settings" };

export default async function AdminSettingsPage() {
  await requireAdmin();
  const [settings, navItems, allTags, publishedPages] = await Promise.all([
    getSettings(),
    listNavItems(),
    listAllTags(),
    listPublishedPages(),
  ]);

  return (
    <div>
      <h1 className="mb-6 text-2xl font-bold tracking-tight text-ink-bright">Site settings</h1>
      <SettingsForm
        settings={settings}
        navItems={navItems}
        allTags={allTags}
        publishedPages={publishedPages}
        action={updateSettingsAction}
      />
      <div className="mt-10">
        <ImportExportSection importAction={importSiteAction} />
      </div>
    </div>
  );
}
