import {getUnreadCount, workGetUnreadCount} from '@/api/desk/notice'

const area = {
  state: {count: 0},
  actions: {
    getUnreadCount({commit}) {
      getUnreadCount().then(
          resp => {commit('SET_NOTICE_COUNT', resp.data.data)})
    },
    workGetUnreadCount({commit}) {
      workGetUnreadCount().then(
          resp => {commit('SET_NOTICE_COUNT', resp.data.data)})
    },
  },
  mutations: {
    SET_NOTICE_COUNT: (state, count) => {
      state.count = count
    },
    NOTICE_READ: (state, count = 1) => {
      if (count > state.count) {
        state.count = 0
      } else if (state.count > 0) {
        state.count -= count
      }
    },
  },
  getters: {}
};

export default area;
