import { createContext, useContext, type PropsWithChildren } from 'react'; import type { AviationPlayer } from './Aviation'; import { AviationError } from './errors'; const AviationContext = createContext(undefined); interface AviationProviderProps extends PropsWithChildren { player: AviationPlayer; } export function AviationProvider({ player, children, }: AviationProviderProps): React.JSX.Element { return ( {children} ); } export function useAviationPlayer(player?: AviationPlayer): AviationPlayer { const contextPlayer = useContext(AviationContext); const resolved = player ?? contextPlayer; if (!resolved) { throw new AviationError( 'NO_PLAYER', '[Aviation] No AviationPlayer found. Pass a player explicitly or wrap the tree in .' ); } return resolved; }