import type { Metadata } from "next";
import { ThemeForm } from "@/components/admin/ThemeForm";
import { getSettings } from "@/lib/cms";

export const metadata: Metadata = {
  title: "Theme customizer",
  robots: { index: false, follow: false },
};

export default async function AdminThemePage({
  searchParams,
}: {
  searchParams: Promise<{ saved?: string }>;
}) {
  const [{ saved }, settings] = await Promise.all([searchParams, getSettings()]);

  return (
    <div className="space-y-8">
      <header>
        <p className="text-sm font-semibold uppercase tracking-[0.14em] text-coral">
          Design
        </p>
        <h1 className="display-2 mt-2">Theme customizer</h1>
        <p className="mt-2 max-w-2xl text-ink-soft">
          Adjust the palette, typography, header and footer for the whole
          website. Changes apply live once saved — the built-in look is one
          click away with “Restore defaults”.
        </p>
      </header>

      {saved ? (
        <p className="rounded-2xl border border-teal/30 bg-teal-soft px-5 py-3 text-sm font-medium text-teal-dark">
          {saved === "reset"
            ? "Theme restored to the built-in design and the website has been refreshed."
            : "Theme saved and the website has been refreshed."}
        </p>
      ) : null}

      <ThemeForm theme={settings.style} />
    </div>
  );
}
