import type { Metadata } from "next";
import Link from "next/link";
import { cookies } from "next/headers";
import { AuthShell } from "../_components/auth-shell";
import { SignUpForm } from "./signup-form";
import { getAuthSettings } from "@/lib/auth";
import { authTexts } from "@/lib/i18n/auth";
import { commonTexts } from "@/lib/i18n/common";

export const dynamic = "force-dynamic";

export const metadata: Metadata = {
  title: `${authTexts.signUpTitle} · ${commonTexts.appName}`,
  description: authTexts.signUpSubtitle,
};

export default async function SignUpPage() {
  const [general, jar] = await Promise.all([getAuthSettings(), cookies()]);
  const hasReferral = Boolean(jar.get("ref")?.value);

  return (
    <AuthShell
      title={authTexts.signUpTitle}
      description={authTexts.signUpSubtitle}
      footer={
        <>
          {authTexts.haveAccount}{" "}
          <Link
            href="/signin"
            className="font-medium text-primary transition-colors hover:text-primary/80"
          >
            {authTexts.signInLink}
          </Link>
        </>
      }
    >
      <SignUpForm requireTerms={general.termsCheckbox !== false} hasReferral={hasReferral} />
    </AuthShell>
  );
}
