import React, { createContext, useContext, useState, ReactNode } from "react";

export enum ActivePopover {
  None = "None",
  Limit = "Limit",
  Scope = "Scope",
  ShowFooter = "ShowFooter",
}

interface UpgradePopoverContextType {
  activePopover: ActivePopover;
  setActivePopover: (popover: ActivePopover) => void;
}

const UpgradePopoverContext = createContext<UpgradePopoverContextType | null>(
  null
);

export const UpgradePopoverProvider: React.FC<{ children: ReactNode }> = ({
  children,
}) => {
  const [activePopover, setActivePopover] = useState<ActivePopover>(
    ActivePopover.None
  );

  return (
    <UpgradePopoverContext.Provider value={{ activePopover, setActivePopover }}>
      {children}
    </UpgradePopoverContext.Provider>
  );
};

export const useUpgradePopover = () => {
  const context = useContext(UpgradePopoverContext);
  if (!context) {
    throw new Error(
      "use UpgradePopover must be used within an UpgradePopoverProvider"
    );
  }
  return context;
};
