1import api from '@/store/api';
2import i18n from '@/i18n';
3
4const ServerLedStore = {
5  namespaced: true,
6  state: {
7    indicatorLedActiveState: false,
8  },
9  getters: {
10    getIndicatorLedActiveState: (state) => state.indicatorLedActiveState,
11  },
12  mutations: {
13    setIndicatorLedActiveState(state, indicatorLedActiveState) {
14      state.indicatorLedActiveState = indicatorLedActiveState;
15    },
16  },
17  actions: {
18    async getIndicatorLedActiveState({ commit }) {
19      return await api
20        .get(`${await this.dispatch('global/getSystemPath')}`)
21        .then((response) => {
22          commit(
23            'setIndicatorLedActiveState',
24            response.data.LocationIndicatorActive,
25          );
26        })
27        .catch((error) => console.log(error));
28    },
29    async saveIndicatorLedActiveState({ commit }, payload) {
30      commit('setIndicatorLedActiveState', payload);
31      return await api
32        .patch(`${await this.dispatch('global/getSystemPath')}`, {
33          LocationIndicatorActive: payload,
34        })
35        .catch((error) => {
36          console.log(error);
37          commit('setIndicatorLedActiveState', !payload);
38          if (payload) {
39            throw new Error(
40              i18n.global.t('pageInventory.toast.errorEnableIdentifyLed'),
41            );
42          } else {
43            throw new Error(
44              i18n.global.t('pageInventory.toast.errorDisableIdentifyLed'),
45            );
46          }
47        });
48    },
49  },
50};
51
52export default ServerLedStore;
53