import { createContext, type ReactNode, useContext } from "react";
import { useEncounter } from "../hooks/use-encounter.js";

type EncounterContextValue = ReturnType<typeof useEncounter>;

const EncounterContext = createContext<EncounterContextValue | null>(null);

export function EncounterProvider({ children }: { children: ReactNode }) {
	const value = useEncounter();
	return (
		<EncounterContext.Provider value={value}>
			{children}
		</EncounterContext.Provider>
	);
}

export function useEncounterContext(): EncounterContextValue {
	const ctx = useContext(EncounterContext);
	if (!ctx) throw new Error("useEncounterContext requires EncounterProvider");
	return ctx;
}
