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

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

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

type Props = {
  params: PayloadRouteParams;
  searchParams: PayloadRouteSearchParams;
};

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

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