import { usePagination, usePaginationSyncWithLocation } from "../usePagination";

type UseSyncedPaginationProps = {
  syncWithLocation?: boolean;
  initialPageIndex?: number;
  initialPageSize?: number;
};

export const useSyncedPagination = ({
  syncWithLocation = true,
  initialPageIndex,
  initialPageSize,
}: UseSyncedPaginationProps) => {
  const [paginationWithLocation, setPaginationWithLocation] = usePaginationSyncWithLocation();
  const [paginationWithoutLocation, setPaginationWithoutLocation] = usePagination(
    initialPageIndex,
    initialPageSize
  );

  if (syncWithLocation) {
    return [paginationWithLocation, setPaginationWithLocation] as const;
  } else {
    return [paginationWithoutLocation, setPaginationWithoutLocation] as const;
  }
};
