import { BusinessEnum } from "@/_BusinessTypeSetting/BusinessTypeSetting";
import { IGameItems } from "@/types";
import { LineTools } from "@/utils/LineTools";
import { ReactNode, createContext, useContext, useState } from "react";

type GameItemsProviderProps = {
	children: ReactNode;
};
const GameItemsContext = createContext<IGameItems>(undefined);

export function useGameItems() {
	return useContext(GameItemsContext);
}
export let gameObj: IGameItems = null;

export function GameItemsProvider({ children }: GameItemsProviderProps) {
	const [gameId, setGameId] = useState<number>(null);

	const game: IGameItems = gameObj = {
		onLoad,
		gameId,
		setGameId
	};

	async function onLoad(serverType: BusinessEnum.ServerType) {
		await Promise.all([
			// // 設定執行環境
			// setBusinessType(),

			// // 設定LineTools環境
			// await setLineTools(),
		]);
	}

	/** 設定LineTools環境 */
	async function setLineTools() {
		await LineTools.onLoad();
	}

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