import { PaginationState } from "@tanstack/react-table";
import { useState } from "react";

export const usePagination = ({
  pageSize,
  pageIndex,
}: {
  pageSize?: number;
  pageIndex?: number;
} = {}) => {
  const [pagination, setPagination] = useState<PaginationState>({
    pageIndex: pageIndex ?? 0,
    pageSize: pageSize ?? 10,
  });

  const setPage = (pageIndex: number) => {
    setPagination((prev) => ({ ...prev, pageIndex }));
  };

  return {
    pagination,
    setPagination,
    setPage,
  };
};
