import { defineStore } from "pinia";
import { store } from "@/stores";
import emitter from "@/utils/eventBus";

export const useGameStore = defineStore("game", {
  persist: true,
  state: () => {
    return {
      gameInfo: <any>{},
      gameUrl: <string>"",
      // 启动游戏详情
      startGameInfo: <any>{},
      // 搜索参数
      searchData: <any>{}
    };
  },
  actions: {
    setGameInfo(game: any) {
      this.gameInfo = {}
      this.gameInfo = game;
    },

    setSearchData(data: any) {
      this.searchData = data
    },

    setStartGameInfo(info: any) {
      console.log(info, 'start-game')
      this.startGameInfo = info
      emitter.emit('openGame')
    },

    clearGameUrl() {
      this.gameUrl = "";
    },
  },
});

// Need to be used outside the setup
export const useGameStoreWithOut = () => {
  return useGameStore(store);
};
