/** * useAppMachine Hook * * Provides access to the app-level state machine from any component. * Must be used within an AppStateMachineProvider. */ import { createContext, useContext } from 'react'; import type { ActorRefFrom } from 'xstate'; import { appMachine } from '@/lib/app-machine'; type AppMachineActor = ActorRefFrom; export const AppMachineContext = createContext(null); export function useAppMachine() { const actor = useContext(AppMachineContext); if (!actor) { throw new Error('useAppMachine must be used within AppStateMachineProvider'); } return actor; }