import { createContext, useContext } from "react";
import type { AppContextType } from "./AppContextTypes";

export const AppContext = createContext<AppContextType<unknown, unknown>>({
  jsBridge: {
    customApex: {} as unknown,
    toast: null,
    refreshApex: () => {},
  },
  appData: {
    opportunityId: "",
  },
});

export function useAppContext<T, K>() {
  const context = useContext(AppContext);

  if (!context) {
    throw new Error("useAppContext must be used within an AppContextProvider");
  }

  return context as AppContextType<T, K>;
}
