import db from "../../plugins/db";

const state = {
  clientConfig: {},
  curLevel: "",
  camera: "", // 相机编号
  curSubject: {},
  scanArea: {},
  scanNo: 0, // 已采集数量（当天登录）
  uploadNo: 0, // 已上传数量（当天登录）,
  showToLoginModel: false
};

const mutations = {
  setClientConfig(state, clientConfig) {
    state.clientConfig = Object.assign({}, state.clientConfig, clientConfig);
  },
  setCurLevel(state, curLevel) {
    state.curLevel = curLevel;
  },
  setCamera(state, camera) {
    state.camera = camera;
  },
  setShowToLoginModel(state, showToLoginModel) {
    state.showToLoginModel = showToLoginModel;
  },
  setCurSubject(state, curSubject) {
    state.curSubject = curSubject;
  },
  setScanArea(state, scanArea) {
    state.scanArea = scanArea;
  },
  setScanNo(state, scanNo) {
    state.scanNo = scanNo;
  },
  setUploadNo(state, uploadNo) {
    state.uploadNo = uploadNo;
  }
};

const actions = {
  updateCurSubject({ state, commit }, curSubject) {
    const scanArea = Object.assign({}, state.scanArea, {
      [curSubject.id]: curSubject
    });
    commit("setCurSubject", curSubject);
    commit("setScanArea", scanArea);
    db.setDict("scanArea", JSON.stringify(scanArea));
  }
};

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