import React, { createContext, useContext } from "react";
import { useIsPastTrial } from "../hooks/stripe";

interface UpgradeBlockContextValue {
  isBlocked: boolean;
}

const UpgradeBlockContext = createContext<UpgradeBlockContextValue | null>(null);

export const useUpgradeBlock = () => {
  const context = useContext(UpgradeBlockContext);
  if (!context) {
    throw new Error("useUpgradeBlock must be used within UpgradeBlockProvider");
  }
  return context;
};

interface UpgradeBlockProviderProps {
  children: React.ReactNode;
}

export const UpgradeBlockProvider: React.FC<UpgradeBlockProviderProps> = ({ children }) => {
  const { isPastTrial: isBlocked } = useIsPastTrial();

  return (
    <UpgradeBlockContext.Provider value={{ isBlocked }}>{children}</UpgradeBlockContext.Provider>
  );
};
