import React, { createContext, useContext } from 'react';

interface GameContextType {
    token: string | null;
    locale: string;
    inventory: any[];
    state: any;
    actions: any;
}

const GameContext = createContext<GameContextType | undefined>(undefined);

export const GameProvider: React.FC<{
    children: React.ReactNode;
    value: GameContextType;
}> = ({ children, value }) => {
    return <GameContext.Provider value={value}>{children}</GameContext.Provider>;
};

export const useGame = () => {
    const context = useContext(GameContext);
    if (context === undefined) {
        throw new Error('useGame must be used within a GameProvider');
    }
    return context;
};

// Optional hook that doesn't throw when outside GameProvider
export const useOptionalGame = () => {
    return useContext(GameContext);
};
