'use client' import { createContext, useContext, ReactNode, Dispatch, SetStateAction } from 'react' import { DownloadProgress } from '@/types/DownloadProgress' import { VersionsConfig } from '@/types/VersionsConfig' import { NormalConfig } from '@/types/NormalConfig' import { ServerVersionsResponse } from '@/types/ServerVersionsResponse' import { GameVersion } from '@/types/GameVersion' import { Game } from '@/types/Game' type GlobalCtxType = { serverVersionList: ServerVersionsResponse | null selectedVersionList: string[] setSelectedVersionList: (value: SetStateAction) => void downloadProgress: DownloadProgress[] setDownloadProgress: Dispatch> showPopup: boolean setShowPopup: Dispatch> popupMode: number | null setPopupMode: Dispatch> fadeOut: boolean setFadeOut: Dispatch> downloadedVersionsConfig: VersionsConfig | null setDownloadedVersionsConfig: Dispatch> normalConfig: NormalConfig | null setNormalConfig: Dispatch> managingVersion: string | null setManagingVersion: Dispatch> setSelectedGame: Dispatch> getVersionInfo: (id: string | undefined) => GameVersion | undefined getGameInfo: (game: number | undefined) => Game | undefined getListOfGames(): Game[] getVersionsAmountData: (gameId: number) => { installed: number total: number } | null viewingInfoFromDownloads: boolean version: string | null downloadVersions: (list: string[]) => Promise category: number setCategory: Dispatch> } const GlobalCtx = createContext(null) export const useGlobal = () => { const ctx = useContext(GlobalCtx) if (!ctx) throw new Error('useGlobal must be inside GlobalProvider') return ctx } export const GlobalProvider = ({ children, value }: { children: ReactNode value: GlobalCtxType }) => { return {children} }