import {
    nodeTypeDict,
    treeIcons,
    leftTreeMenus,
    rightTreeMenus,
    fmeaReadOnlyTopBtns,
    fmeaTopBtns,
    variantMatrixTopBtns,
    struLeftTreeMenus,
    struRightX6Menus,
    pLeftTreeMenus,
    parameterList,
    geometricObj
} from '../assets/fmeaTreeData'

const state = {
    nodeTypeDict: nodeTypeDict, // 节点类型对象字典
    treeIcons: treeIcons, // 结构树图标
    leftTreeMenus: leftTreeMenus, // 左侧结构菜单项
    rightTreeMenus: rightTreeMenus, // 右侧结构菜单项
    fmeaReadOnlyTopBtns: fmeaReadOnlyTopBtns, // 结构树，顶部的只读按钮
    fmeaTopBtns: fmeaTopBtns, // 结构树，顶部的按钮
    variantMatrixTopBtns: variantMatrixTopBtns, // 变体矩阵，顶部的按钮
    struLeftTreeMenus: struLeftTreeMenus, // 结构分析左侧结构菜单项
    struRightX6Menus: struRightX6Menus, // 结构分析右侧结构菜单项
    pLeftTreeMenus: pLeftTreeMenus, //P图右键菜单
    parameterList: parameterList, //P图右侧
    geometricObj: geometricObj, // 形位公差符号

    //缓存信息
    fmeaId: sessionStorage.getItem('fmeaId'), // fmeaId
    rfmeaId: sessionStorage.getItem('rfmeaId'), // rfmeaId
    fmeaName: sessionStorage.getItem('fmeaName'), // fmeaName
    structureId: sessionStorage.getItem('structureId'), // fmeaName
    strucTreeDataId: sessionStorage.getItem('strucTreeDataId'), //流程图跳转
    fmeaLanguage: sessionStorage.getItem('fmeaLanguage'), //fmeaLanguage
    pageLanguage: sessionStorage.getItem('pageLanguage'), //页面全局的语言
    lastFailCheckedNode: sessionStorage.getItem('lastFailCheckedNode'), // 最后选中的节点，右边树，整个node
    commentsFlag: sessionStorage.getItem('commentsFlag'),//是否能添加评审意见
    CopyCutNodeParentStruType: undefined, //复制或剪切的节点的父节点类型，主要用于复制 预防措施，预防控制，探测措施，探测控制时粘贴问题
    checkedLeftNodeId: undefined, // 左边最后选中的节点id
    checkedLeftNode: undefined, // 左边最后选中的节点
    checkedRightNodeId: undefined, // 右边最后选中的节点id
    checkedRightNode: undefined, // 右边最后选中的节点
    lastCheckedNodeId: undefined, // 最后选中的节点id
    lastCheckedX6Node: undefined, // 最后X6选中的节点
    lastCheckedNode: undefined, // 最后选中的节点
    lastCheckedLRTreeFlag: undefined, // 最后选中的左右侧树标识位
    lastCheckedNetNode: undefined, // 最后选中的网（功能网、失效网）节点
    lastCheckedNetLRNode: undefined, // 最后选中的网（功能网、失效网）两侧节点
    lastCheckedNodeTree: undefined, // 最后一次操作是在左边=struTree还是右边=failTree
    lastCopyOrCutNode: undefined, // 存储复制/剪切的对象
    lastCopyOrCutLRTreeFlag: undefined, // 存储复制/剪切的左右侧树标识位
    lastCopyOrCut: undefined, // 存储操作类型：复制=copy or 剪切=cut
    riskAnalysisSwitch: undefined, //用于风险分析
    sideRfmeaId: undefined, // 并排查看rfmeaId
    sideCheckedLeftNode: undefined, // 并排查看左边选中的节点
    sideLastCheckedNode: undefined, // 并排查看最后选中的节点
    multiCopyNode: undefined,  //右边多个复制的节点
    multiCopyOrCut: undefined, //多个复制的操作类型
    multiSelectedNode: undefined, //多个选中
    multiSelectedLNode: undefined, //左侧树多个选中
    boundaryStruIdList: undefined,//边界图左侧树结构id集合
    boundaryLeftStruTree: undefined,//边界图左侧树
    variantFilterNodes: [], // 变体过滤节点
    parameterCheckedNode: undefined, // P图选中节点
    lastBoundaryMapNode: undefined, //边界图点击节点
    leftStruIdFromComments: undefined,//左侧树评审意见跳转结构分析节点的id
    commentsParentIds: undefined, // 评审意见跳转父节点集合
    rightParentStruIdFromComments: undefined,//右侧树评审意见跳转结构分析根节点的id
    rightStruIdFromComments: undefined,//右侧树评审意见跳转结构分析节点的id
}

const mutations = {
    SET: (state, {key, value}) => {
        if (state.hasOwnProperty(key)) {
            // 下面三个参数可能跨页面传输，所以走cookie
            if (
                [
                    'fmeaId',
                    'rfmeaId',
                    'fmeaName',
                    'structureId',
                    'fmeaLanguage',
                    'pageLanguage',
                    'lastFailCheckedNode',
                    'commentsFlag'
                ].indexOf(key) !== -1
            ) {
                sessionStorage.setItem(key, value)
            }
            state[key] = value
        }
    },
    CLEAR: state => {
        // 清除fmeaId,结构树，失效树相关的缓存
        // state['fmeaId'] = undefined
        // state['fmeaName'] = undefined
        state['checkedLeftNodeId'] = undefined
        state['checkedLeftNode'] = undefined
        state['checkedRightNodeId'] = undefined
        state['checkedRightNode'] = undefined
        state['lastCheckedX6Node'] = undefined
        state['lastCheckedNodeId'] = undefined
        state['lastCheckedNode'] = undefined
        state['lastCheckedNetNode'] = undefined
        state['lastCheckedNetLRNode'] = undefined
        state['lastCheckedNodeTree'] = undefined
        // 清除复制/剪切相关缓存
        state['lastCopyOrCutNode'] = undefined
        state['lastCopyOrCutLRTreeFlag'] = undefined
        state['lastCopyOrCut'] = undefined

        state['multiCopyNode'] = undefined
        state['multiCopyOrCut'] = undefined
        state['multiSelectedNode'] = undefined
        state['variantFilterNodes'] = []

        state['parameterCheckedNode'] = undefined
    },
    CLEARSIDE: state => {
        state['sideCheckedLeftNode'] = undefined
        state['sideLastCheckedNode'] = undefined
    },
    CLEARSTRU: state => {
        // 在结构树上删除时，删除已被移除的节点的信息
        state['checkedLeftNodeId'] = undefined
        state['checkedLeftNode'] = undefined
    },
    CLEARFAIL: state => {
        // 在失效树上删除时，删除已被移除的节点的信息
        state['checkedRightNodeId'] = undefined
        state['checkedRightNode'] = undefined
    },
    CLEARCOPYORCUT: state => {
        state['lastCopyOrCutNode'] = undefined
        state['lastCopyOrCutLRTreeFlag'] = undefined
        state['lastCopyOrCut'] = undefined
    },
    CLEARLASTCHECKEDNODE: state => {
        // 在结构树上删除时，删除已被移除的节点的信息
        state['lastCheckedNodeId'] = undefined
        state['lastCheckedNode'] = undefined
    },
    CLEARMULTICOPY: state => {
        state['multiCopyNode'] = undefined
        state['multiCopyOrCut'] = undefined
        state['multiSelectedNode'] = undefined
    },
    CLEARNET: state => {
        state['lastCheckedNetNode'] = undefined
        state['lastCheckedNetLRNode'] = undefined
    },
}

const actions = {
    set({commit}, data) {
        commit('SET', data)
    },
    clear({commit}) {
        commit('CLEAR')
    },
    clearSide({commit}) {
        commit('CLEARSIDE')
    },
    clearCopyOrCut({commit}) {
        commit('CLEARCOPYORCUT')
    },
    clearStru({commit}) {
        commit('CLEARSTRU')
    },
    clearFail({commit}) {
        commit('CLEARFAIL')
    },
    clearLastCheckedNode({commit}) {
        commit('CLEARLASTCHECKEDNODE')
    },
    clearMultiCopy({commit}) {
        commit('CLEARMULTICOPY')
    },
    clearNet({commit}) {
        commit('CLEARNET')
    }
}

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