"use client";

import * as React from "react";

type PageContextType = {
  currentPage: Number | undefined;
  setCurrentPage: (currentPage: Number | undefined) => void;
};

const PageContext = React.createContext<PageContextType | undefined>(undefined);

export function usePageContext() {
  const context = React.useContext(PageContext);
  if (context === undefined) {
    throw new Error("usePageContext must be used within a PageProvider");
  }
  return context;
}

export function PageProvider({ children }: { children: React.ReactNode }) {
  const [currentPage, setCurrentPage] = React.useState<Number | undefined>(1);

  const value = React.useMemo(() => {
    return { currentPage, setCurrentPage };
  }, [currentPage]);

  return <PageContext.Provider value={value}>{children}</PageContext.Provider>;
}
