import Cookies from 'js-cookie'

const state = () => ({
    isCollapse: true, // 侧边栏是否收缩展示
    contentFullScreen: false, // 内容是否可全屏展示
    showLogo: true, // 是否显示Logo
    fixedTop: false, // 是否固定顶部, 暂未使用
    showTabs: true, // 是否显示导航历史
    expandOneMenu: true, // 一次是否只能展开一个菜单
    elementSize: 'small', // element默认尺寸
    loading: false,
    windowSize: {},
    currentPageName: null,
    jdt: {
        title: null,
        isOpen: false,
        closeButton: false,
    },
    theme: {},
    unreadMessageCount: 0, // 未查看的消息数量
    systemMessages: [], // 已经看过的系统通知id
})

// mutations
const mutations = {
    isCollapseChange(state, type) {
        state.isCollapse = type
    },
    contentFullScreenChange(state, type) {
        state.contentFullScreen = type
    },
    menuListChange(state, arr) {
        state.menuList = arr
    },
    stateChange(state, option) {
        state[option.name] = option.value
    },
    setLoading(state, val) {
        //state.loading = val
    },
    setWindowSize(state, windowSize) {
        state.windowSize = windowSize
    },
    setCurrentPageName(state, val) {
        state.currentPageName = val
    },
    setJdt(state, val) {
        Cookies.set('jdtTitle', val.title)
        state.jdt = val
    },
    closeButton(state, val) {
        state.jdt.closeButton = val
    },
    closeJdt(state) {
        state.jdt.isOpen = false
    },
    titleJdt(state, val) {
        state.jdt.title = val
    },
    setUnreadMessageCount(state, val) {
        state.unreadMessageCount = val
    },
    setTheme(state, val) {
        state.theme = val
    },
    setSystemMessages(state, val) {
        if (val === null) {
            state.systemMessages = []
        } else {
            state.systemMessages.push(val)
        }
    },
}

// actions
const actions = {}

export default {
    namespaced: true,
    state,
    actions,
    mutations,
}
