/**
 * 系统语言
 */
export enum Language {
    Simplified = 'zh-CN',
    Traditional = 'zh-TW',
    English = 'en-US',
    Thai = 'th',
    Vietnamese = 'vi'
}

/**
 * 获取客户端语言
 * @returns 
 */
export function getClientLanguage() {
    const rules = [
        { result: Language.Simplified, code: ['zh-CN'] },
        { result: Language.Traditional, code: ['zh-TW'] },
        { result: Language.English, code: ['en', 'en-US'] },
        { result: Language.Thai, code: ['th', 'th-TH'] },
        { result: Language.Vietnamese, code: ['vi', 'vi-VN'] },
    ]
    const lang = rules.find(rule => rule.code.includes(navigator.language))
    return lang ? lang.result : Language.English
}

/**
 * 获取语言列表
 * @returns 
 */
export function getLanguageList() {
    return [
        { label: '简体中文', value: Language.Simplified },
        { label: '繁体中文', value: Language.Traditional },
        { label: 'English', value: Language.English },
        { label: 'ภาษาไทย', value: Language.Thai },
        { label: 'Tiếng Việt', value: Language.Vietnamese },
    ]
}

/**
 * 获取语言名称
 * @param languageValue 
 * @returns 
 */
export function getLanguageLabelByValue(languageValue: Language) {
    const languages = getLanguageList()
    const item = languages.find((e) => e.value === languageValue)
    return item?.label ?? languageValue
}