import { config, type GlobalConfig } from '@/settings/application'
import { defineStore } from 'pinia'

export const useAppStore = defineStore('app', {
	state: (): GlobalConfig => {
		return { ...config }
	},
	getters: {
		isCN(state) {
			return state.language === 'zh_CN'
		},
	},
	actions: {
		updateConf(conf: unknown) {
			Object.assign(this, { layout: conf })
		},
		changePrimaryColor(color: string) {
			this.theme.primaryColor = color
		},
		changeLocale(lang: 'zh_CN' | 'en_US') {
			this.language = lang
		},
		setting(setting: GlobalConfig) {
			this.title = setting.title
			this.name = setting.name
			this.site = setting.site
			this.copyright = setting.copyright
			this.logo = setting.logo
			this.description = setting.description
			this.layout.gray = setting.layout.gray
			this.iconfontUrl = setting.iconfontUrl
			this.theme.primaryColor = setting.theme.primaryColor
		},
	},
	persist: {
		key: 'app',
		storage: localStorage,
	},
})
