import { fetchHeaderFooterForLayout } from '../../../lib/serverFetch';
import { getPaymentPageDataAction } from '../../../lib/actions/paymentPageAction';
import PayPageClient from './PayPageClient';

export const dynamic = 'force-dynamic';

interface PageProps {
  params: Promise<{ registrationId: string }>;
  searchParams: Promise<Record<string, string | string[]>> | Record<string, string | string[]>;
}

export default async function PayPage({ params, searchParams }: PageProps) {
  const searchParamsObj = typeof searchParams === "object" && "then" in searchParams
      ? await searchParams
      : searchParams ?? {};
  
  const lang = (searchParamsObj.lang as string) || (searchParamsObj.language as string) || "default";
  const franchiseeId = searchParamsObj.franchiseeId as string;

  // Fetch footer data on the server side
  let headerFooterData = null;
  let paymentPageContent = null;
  
  try {
    const [footerResponse, paymentResponse] = await Promise.all([
      fetchHeaderFooterForLayout().catch(e => {
        return null;
      }),
      getPaymentPageDataAction(lang, franchiseeId).catch(e => {
        return null;
      })
    ]);
    headerFooterData = footerResponse;
    paymentPageContent = paymentResponse || null;
  } catch (error) {
  }

  return <PayPageClient params={params} footerData={headerFooterData} paymentPageContent={paymentPageContent} />;
}
