import PageContainer from '@/components/layout/page-container';
import SurveysAdminList from '@/feactures/surveys/components/admin/surveys-admin-list';
import { SurveysHeader } from '@/feactures/surveys/components/admin/surveys-header';
import SurveysTableAction from '@/feactures/surveys/components/admin/surveys-tables/survey-table-action';
import { searchParamsCache } from '@/feactures/surveys/utils/searchparams';
import { SearchParams } from 'nuqs';

type pageProps = {
  searchParams: Promise<SearchParams>;
};


export default async function SurveyAdminPage(props: pageProps) {
  const searchParams = await props.searchParams;
  searchParamsCache.parse(searchParams);
 
  const page = Number(searchParamsCache.get('page')) || 1;
  const search = searchParamsCache.get('q');
  const pageLimit = Number(searchParamsCache.get('limit')) || 10;
  const type = searchParamsCache.get('type');

  return (
    <PageContainer scrollable={false}>
      <div className="flex flex-1 flex-col space-y-4">
        <SurveysHeader />
        <SurveysTableAction />
        <SurveysAdminList
          initialPage={page}
          initialSearch={search}
          initialLimit={pageLimit}
          initialType={type}
        />
      </div>
    </PageContainer>
  );
}