import { usePagination } from "@erp/core/hooks";
import { PropsWithChildren, createContext, useContext } from "react";

export type IInvoicesContextState = {};

export const InvoicesContext = createContext<IInvoicesContextState | null>(null);

export const InvoicesProvider = ({ children }: PropsWithChildren) => {
  const [pagination, setPagination] = usePagination();

  return (
    <InvoicesContext.Provider
      value={{
        pagination,
        setPagination,
      }}
    >
      {children}
    </InvoicesContext.Provider>
  );
};

export const useInvoicesContext = () => {
  const context = useContext(InvoicesContext);
  if (context === null) throw new Error("useInvoices must be used within a InvoicesProvider");
  return context;
};
