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

// 主题色枚举
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(() => {
        const theme = localStorageUtil.getItem('theme')
        if (theme) {
            changeTheme(theme)
        } else {
            // if (isOemByEnum(OemType.wrspot)) {
            //     changeTheme(ThemeEnum.light)
            // } else {
            //     changeTheme(ThemeEnum.dark)
            // }
            changeTheme(ThemeEnum.dark)
        }
    })
}

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