import type { GlobalState } from './pinia.types'

const useStore = defineStore('globalStore', () => {
    const state: GlobalState = reactive({
        globalLoading: false,
        routerLoading: false,
        requestLoading: false,
        fullScreenLoading: false,
        ISLocal: import.meta.env.VITE_APP_ENV === 'development',
        ISDEV: import.meta.env.VITE_APP_ENV === 'development',
        ISPRE: import.meta.env.VITE_APP_ENV === 'pre-release',
        ISPROD: import.meta.env.VITE_APP_ENV === 'production',
        isPageSwitching: false,
        theme: 'light',
        // theme: 'dark',
    })

    const setGlobalTheme = (payload: string) => {
        state.theme = 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,
        setGlobalTheme,
        setRouterLoading,
        setRequestLoading,
        setFullScreenLoading,
    }
})

export default useStore // 导出
