import { redirect } from "next/navigation";
import type { Lang } from "@/lib/config";

function normalizeRedirectTarget(value?: string): string | null {
  if (!value?.startsWith("/")) {
    return null;
  }

  if (value.startsWith("//")) {
    return null;
  }

  return value;
}

export default function SignupPage({
  params,
  searchParams,
}: {
  params: { lang: Lang };
  searchParams?: {
    redirect_url?: string;
  };
}) {
  const { lang } = params;
  const redirectTarget = normalizeRedirectTarget(searchParams?.redirect_url);
  const target = redirectTarget
    ? `/${lang}/clerk-signup?redirect_url=${encodeURIComponent(redirectTarget)}`
    : `/${lang}/clerk-signup`;

  redirect(target);
}
