import { RootPage, generatePageMetadata } from '@payloadcms/next/views';
import type { Metadata } from 'next';
import config from '../../../../payload.config';
import { importMap } from '../importMap';

export const dynamic = 'force-dynamic';

type PayloadRouteParams = {
  segments?: string[];
};

type PayloadRouteSearchParams = {
  [key: string]: string | string[] | undefined;
};

type Props = {
  params: Promise<PayloadRouteParams>;
  searchParams: Promise<PayloadRouteSearchParams>;
};

export const generateMetadata = (props: Props): Promise<Metadata> => {
  return generatePageMetadata({
    config,
    params: props.params as Promise<Record<string, string | string[]>>,
    searchParams: props.searchParams as Promise<Record<string, string | string[]>>,
  });
};

export default function Page(props: Props) {
  return RootPage({
    config,
    importMap,
    params: props.params as Promise<{ segments: string[] }>,
    searchParams: props.searchParams as Promise<Record<string, string | string[]>>,
  });
}
