// src/store/context.tsx // WizardContext, WizardProvider, and useWizard hook. // useWizard throws if used outside WizardProvider — prevents silent "undefined state" bugs. import React, { createContext, useContext, useReducer } from 'react'; import { WizardState, WizardAction, INITIAL_STATE } from './types'; import { wizardReducer } from './reducer'; interface WizardContextValue { state: WizardState; dispatch: React.Dispatch; } const WizardContext = createContext(null); export function WizardProvider({ children }: { children: React.ReactNode }) { const [state, dispatch] = useReducer(wizardReducer, INITIAL_STATE); return ( {children} ); } export function useWizard(): WizardContextValue { const ctx = useContext(WizardContext); if (!ctx) throw new Error('useWizard must be used inside '); return ctx; }