import {createPageContext, usePageContextReducer} from '@hooks';
import {ChildrenFC, PAGE_SIZE_LIST} from '@utils';

type Props = {
  context: ReturnType<typeof createPageContext>;
  initPageSize?: string;
};

const PageProvider: ChildrenFC<Props> = function ({
  children,
  context,
  initPageSize = PAGE_SIZE_LIST[0],
}) {
  const state = usePageContextReducer({
    pageSize: Number(initPageSize),
    page: 1,
  });
  const {Provider} = context;

  return <Provider value={state}>{children}</Provider>;
};

export default PageProvider;
