import { defineStore } from "pinia"
import { RouteRecordRaw } from "vue-router";

interface globalState {
  loadingShow: boolean;
  globalLodingShow: boolean;
  globalLodingShowText: string;
  currentMenue: RouteRecordRaw | null;
  historyRouterPath: string;
  loadingText: string
}
export const globalState = defineStore('globalState', {
  state(): globalState{
    return {
      loadingShow: false,
      loadingText: '',
      currentMenue: null,
      historyRouterPath: '/',
      globalLodingShow: false,
      globalLodingShowText: ""
    }
  },
  actions: {
    setLoadingShow(state: boolean, showText = '请稍候...' ) {
      this.loadingShow = state;
      this.loadingText = showText;
    },
    toggleLoadingShow() {
      this.loadingShow = !this.loadingShow;
    },
    setSelectMenue(menue: RouteRecordRaw) {
      this.currentMenue = menue;
    },
    setHistoryRouterPath(path: string) {
      this.historyRouterPath = path;
      localStorage.setItem('historyRouterPath', path);
    },
    setLoadingText(text:string) {
      this.loadingText = text;
    },
    setGlobalLoadingShow(state: boolean, showText = '请稍候...') {
      this.globalLodingShow = state;
      this.globalLodingShowText = showText;
    }
  }
})