const UserContext={
    namespaced: true,
    state:{
        userName:"",
        userId:"",
        ptyCode:"",
        menu:[],
        state:"LOGOUT",
        token:"",
        homeCellsSetting: {
            defaultCells: [],
            cellRows: 0,
            cellCols: 0,
            cellNames: []
        }
    },
    mutations:{
        setLoginInfo(state,info){
            state.userName = info.userName
            state.userId = info.userId
            state.ptyCode = info.ptyCode
            state.menu = info.menu
            state.state = "LOGIN"
            state.token = info.token
            window.sessionStorage.userId = info.userId
            window.sessionStorage.userName = info.userName
            window.sessionStorage.token = info.token
        },
        setLogout(state){
            state.userName = ""
            state.userId = ""
            state.ptyCode = ""
            state.menu = []
            state.state = "LOGOUT"
            state.token = ""
        },
        setMenu(state, menu) {
            state.menu = menu;
        },
        setHomeCellsSetting(state, setting) {
            state.homeCellsSetting.cellRows = setting.cellRows
            state.homeCellsSetting.cellCols = setting.cellCols
            state.homeCellsSetting.cellNames = setting.cellNames
            localStorage.setItem(`cells-setting-${state.userId}`, JSON.stringify(setting));
        },
        setHomeDefaultCells(state, cells) {
            state.homeCellsSetting.defaultCells = cells;
        }
    }
}
export default UserContext;