import { getListData } from '@akinon/next/data/server';
import { withSegmentDefaults } from '@akinon/next/hocs/server';
import { ResolvedPageProps } from '@akinon/next/types';
import CategoryLayout from '@theme/views/category/layout';
import { ROUTES } from '@theme/routes';
import { buildListingPageContext } from '@theme/utils/theme-page-context';

async function Page({ searchParams }: ResolvedPageProps) {
  const data = await getListData({ searchParams });
  const pageType = data.search_text ? 'search' : 'plp';

  return (
    <>
      <CategoryLayout
        data={data}
        pageContext={buildListingPageContext({
          data,
          pageType,
          path: ROUTES.LIST
        })}
      />
    </>
  );
}

export default withSegmentDefaults(Page, { segmentType: 'page' });
