import { localStorageUtil } from '@/utils/storage';
import { ref } from "vue";
import { initData } from "../methods";
import { isOemByEnum, OemType } from './projectName';

// 主题色枚举
export enum ThemeEnum {
    default = 'default',
    dark = 'dark',
    light = 'light'
}

const themeName = ref<ThemeEnum>(ThemeEnum.default)

/**
 * 获取当前主题色
 * @returns
 */
export function getTheme() {
    return themeName
}
/**
 * 更改主题色
 * @param value
 */
export function setTheme(value: ThemeEnum) {
    localStorageUtil.setItem('theme', value)
    themeName.value = value
}

/**
 * 初始化主题（默认主题）
 */
export function initTheme() {
    initData(() => {
        if (isOemByEnum(OemType.wrspot) || isOemByEnum(OemType.tian_jing_mai_dun)) { // 云融 项目 主题缓存
            const theme = localStorageUtil.getItem('theme')
            if (theme) {
                changeTheme(theme)
            } else {
                changeTheme(ThemeEnum.dark)
            }
        } else {
            localStorageUtil.removeItem('theme')
            changeTheme(ThemeEnum.dark)
        }
    })
}

// 切换主题
export function changeTheme(value: ThemeEnum) {
    document.documentElement.removeAttribute('theme');
    document.documentElement.setAttribute('theme', value);
    setTheme(value)
}
export { };
