import type { GlobalState } from "./pinia.types";
import { defineStore } from "pinia";
import { toRefs, reactive } from "vue";
const useStore = defineStore("globalStore", () => {
  const state: GlobalState = reactive({
    globalLoading: false,
    routerLoading: false,
    requestLoading: false,
    fullScreenLoading: false,
    isPageSwitching: false,
    theme: "light",
    statusBarHeight: 0
    // theme: 'dark',
  });

  const setGlobalTheme = (payload: string) => {
    state.theme = payload;
  };
  const setBarHeight = (payload: number) => {
    state.statusBarHeight = payload;
  };
  const setGlobalLoading = (payload: boolean) => {
    state.globalLoading = payload;
  };
  const setRouterLoading = (payload: boolean) => {
    state.routerLoading = payload;
  };
  const setRequestLoading = (payload: boolean) => {
    state.requestLoading = payload;
  };
  const setFullScreenLoading = (payload: boolean) => {
    state.fullScreenLoading = payload;
  };

  return {
    ...toRefs(state),
    setGlobalLoading,
    setBarHeight,
    setGlobalTheme,
    setRouterLoading,
    setRequestLoading,
    setFullScreenLoading,
  };
});

export default useStore; // 导出
