import { redirect } from "next/navigation";
import { getSettings } from "@/lib/settings";
import { RegisterForm } from "./register-form";

export default async function RegisterPage({
  searchParams,
}: {
  searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
}) {
  const settings = await getSettings();

  if (settings.registrationEnabled !== "true") {
    redirect("/login?notice=registration_closed");
  }

  const sp = await searchParams;
  const str = (v: string | string[] | undefined) => (Array.isArray(v) ? v[0] : v) ?? "";

  return (
    <div className="min-h-screen flex items-center justify-center" style={{ backgroundColor: "var(--background)" }}>
      <div className="w-full max-w-sm">
        <div className="text-center mb-8">
          <h1 className="text-2xl font-bold tracking-wide" style={{ color: "var(--foreground)" }}>
            {settings.schoolName}
          </h1>
          <p className="mt-1 text-sm uppercase tracking-widest" style={{ color: "var(--muted-foreground)", fontSize: "13px" }}>
            Образовательная платформа
          </p>
        </div>
        <div className="card-aubade p-8">
          <RegisterForm
            showTermsCheckbox={settings.showTermsCheckbox === "true"}
            privacyPolicyUrl={settings.privacyPolicyUrl}
            termsUrl={settings.termsUrl}
            offerUrl={settings.offerUrl}
            archetype={str(sp.archetype)}
            utmSource={str(sp.utm_source)}
            utmMedium={str(sp.utm_medium)}
            utmCampaign={str(sp.utm_campaign)}
          />
        </div>
      </div>
    </div>
  );
}
