import defaultSettings from '@/settings'
import { useDynamicTitle } from '@/utils/dynamicTitle'

const { sideTheme, showSettings, tagsView, dynamicTitle, navigationType, navigationTypeCopy, topTheme } = defaultSettings

const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''

const useSettingsStore = defineStore(
    'settings', {
    state: () => ({
        title: '',
        topTheme: storageSetting.topTheme === undefined ? topTheme : storageSetting.topTheme, //头部背景颜色单独设置
        topFontColor: storageSetting.topFontColor, //头部字体颜色单独设置
        sideTheme: storageSetting.sideTheme || sideTheme,
        navigationType: storageSetting.navigationType || navigationType,
        showSettings: storageSetting.showSettings || showSettings,
        tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView,
        dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle,

    }),
    actions: {
        // 设置主内容区的高度
        setMainHeight() {
            if (this.tagsView) return "96px";
            else return "56px";
        },

        // 修改布局设置
        changeSetting(data) {
            const { key, value } = data
            if (this.hasOwnProperty(key)) {
                this[key] = value
            }
        },
        // 设置网页标题
        setTitle(title) {
            this.title = title
            useDynamicTitle();
        }
    }
})

export default useSettingsStore