import storage from '@/utils/storage'
const state = {
  globalTimes: {
    interval: parseInt((new Date() - new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 0, 0)) / (1000 * 60)), // 默认是5分钟 // 20: 20m // 60: 1h // 360: 6h // 720: 12h // 1440: 1d
    // startTime: Math.round((new Date().getTime()) / 1000 - (5 * 60)), // 默认5分钟
    startTime: Math.round(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()).getTime() / 1000), // 默认当日凌晨
    endTime: Math.round(new Date().getTime() / 1000),
    timeOut: 1, // 默认是5000毫秒也就是5s
    timeType: '当日'
  },
  timesFlag: false,
  topoGlobalTimes: { // 动态拓扑-时间组件
    interval: parseInt((new Date() - new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate(), 0, 0, 0)) / (1000 * 60)), // 默认是5分钟 // 20: 20m // 60: 1h // 360: 6h // 720: 12h // 1440: 1d
    startTime: Math.round((new Date().getTime()) / 1000 - (5 * 60)), // 默认5分钟
    // startTime: Math.round(new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()).getTime() / 1000), // 默认当日凌晨
    endTime: Math.round(new Date().getTime() / 1000),
    timeOut: 1, // 默认是5000毫秒也就是5s
    timeType: '5m'
  }
}

const mutations = {
  setTimes: (state, data) => {
    state.globalTimes = data
    storage.set('global_times', data)
  },
  setTimeFlag: (state, flag) => {
    state.timesFlag = flag
  },
  setTopoTimes: (state, data) => {
    state.topoGlobalTimes = data
    storage.set('topoGlobalTimes', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
