import dayjs from 'dayjs'
import customParseFormat from 'dayjs/plugin/customParseFormat'
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'
import localeData from 'dayjs/plugin/localeData'
import duration from 'dayjs/plugin/duration'
import isBetween from 'dayjs/plugin/isBetween'
import weekday from 'dayjs/plugin/weekday'
import updateLocale from 'dayjs/plugin/updateLocale'
import En from 'dayjs/locale/en'
import ZhCn from 'dayjs/locale/zh-cn'

// 引入英文语言包
import {Locale} from 'wot-design-uni'
import enUS from 'wot-design-uni/locale/lang/en-US'
import zhCN from 'wot-design-uni/locale/lang/zh-CN'

import type {App} from 'vue'

dayjs.extend(customParseFormat)
dayjs.extend(isSameOrAfter)
dayjs.extend(localeData)
dayjs.extend(duration)
dayjs.extend(isBetween)
dayjs.extend(weekday)
dayjs.extend(updateLocale)


dayjs.updateLocale('en', {
    weekdaysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
    weekdays: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
})


dayjs.updateLocale('zh-cn', {
    weekdaysShort: ["日", "一", "二", "三", "四", "五", "六"],
    weekdays: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
});


export function setWotDesignLocale() {
    const localeLanguages = uni.getLocale()
    localeLanguages === 'zh-Hans' && Locale.use('zh-CN', zhCN)
    localeLanguages === 'en' && Locale.use('en-US', enUS)
}

export function setDayjsLocale() {
    const localeLanguages = uni.getLocale()
    console.log('localeLanguages', localeLanguages)
    localeLanguages === 'zh-Hans' && dayjs.locale(ZhCn)
    localeLanguages === 'en' && dayjs.locale(En)
}

export function installAppPlugins(app: App<Element>) {
    app.provide('dayjs', dayjs)
}

export {dayjs}
