import { defineStore } from 'pinia'
import zhCn from 'element-plus/lib/locale/lang/zh-cn'
import ja from 'element-plus/lib/locale/lang/ja'
import en from 'element-plus/lib/locale/lang/en'
import { Language } from 'element-plus/lib/locale'
import key from '@/constant/key'

export const useGlobalPinia = defineStore('global', {
	state: () => {
		return {
			language:
				localStorage.getItem(key.languageKey) == 'en'
					? en
					: localStorage.getItem(key.languageKey) == 'jp'
					? ja
					: (zhCn as Language),
			size: localStorage.getItem(key.sizeKey) || 'default',
			header: 0,
			mainPadding: 20,
			lang: localStorage.getItem(key.languageKey)
		}
	},
	actions: {
		handleSetLanguage(val: Language) {
			this.language = val
		},
		handleSetSize(val: string) {
			this.size = val
		},
		handleSetHeader(val: number) {
			this.header = val
		},
	},
})
