import { unstable_cache } from 'next/cache';
import { getLatestTerms } from '@/sanity/cms';
import { getSanityOrgCode } from '@/sanity/tenantOrg.server';
import SignUpForm from './components/SignUpForm';

const JURISDICTION_LIST = ['ID', 'SG', 'MY', 'GLOBAL', 'VN'];
const LOCALE_LIST = ['en-US', 'id-ID'];

export default async function SignUpModule() {
  const orgCode = await getSanityOrgCode();
  const jurisdiction = JURISDICTION_LIST[0];
  const locale = LOCALE_LIST[0];

  const fetchTerms = unstable_cache(
    async () => getLatestTerms(orgCode, jurisdiction, locale) || null,
    ['terms', orgCode, jurisdiction, locale, 'signup'],
    { tags: [`terms:${orgCode}:${jurisdiction}:${locale}`] },
  );

  const terms = orgCode ? await fetchTerms() : null;

  return (
    <div className="flex flex-col flex-1 lg:w-1/2 w-full">
      <div className="flex flex-col justify-center flex-1 w-full max-w-md mx-auto">
        <SignUpForm terms={terms} />
      </div>
    </div>
  );
}
