import { createContext, ReactNode, useState } from "react";

export let gameObj: GameItemsContextType = null;

export const GameItemsContext = createContext<GameItemsContextType>({
	player: null,
	setPlayer: null,
	gameData: null,
	setGameData: null
});

export const GameItemsProvider = ({ children }: { children: ReactNode }) => {
	const [player, setPlayer] = useState<PlayerData>({});
	const [gameData, setGameData] = useState<GameData>({});

	const game: GameItemsContextType = gameObj = {
		player,
		setPlayer,
		gameData,
		setGameData
	};

	return (
		<GameItemsContext.Provider value={game}>
			{children}
		</GameItemsContext.Provider>
	);
};

interface GameItemsContextType {
	player: PlayerData;
	setPlayer: (v: PlayerData) => void;
	gameData: GameData;
	setGameData: (v: GameData) => void;
}

export interface PlayerData {
	id?: string;
	pw?: string;
	token?: string;
	[key: string]: any;
}

interface GameData {
	slotData?: SlotData[];
	slotList?: number[];
	nowSlotId?: number;
}

export type SlotData = [componyID: number, slotId: number, vip: number, status: number, tag: number]