import Service from 'src/service'
// import { BaseStore } from '@zenview/micro-basic-library'

export function queryUserDevice(options, needDeviceLocalRecordAbility = true) {
  function emptyPromise() {
    return new Promise((resolve) => resolve(false));
  }
  return Promise.all([
    Service.queryUserDevicesNew(options ? options : { offset: 0, limit: 100000 }),
    Service.queryUserDevicesStatusNew(options ? options : { offset: 0, limit: 100000 }),
    needDeviceLocalRecordAbility ? Service.queryDeviceLocalRecordAbilityList(options ? options : { queryType: 2 }) : emptyPromise(),
  ]).then((devices) => {
    const [listRes, statusRes, frontEndRes] = devices;
    let deviceState = {};
    statusRes.data && statusRes.data.split('|').forEach((res) => {
      const [id, state] = res.split(',');
      deviceState[id] = `${state}`;
    });
    let deviceFrontEnd = {};
    let deviceStorage = {};
    frontEndRes && frontEndRes.data &&
      frontEndRes.data.split('|').forEach((res) => {
        const [id, state, storage] = res.split(',');
        deviceFrontEnd[id] = state;
        deviceStorage[id] = storage;
      });

    return formatDeviceMap(listRes.data.list, listRes.data.other, deviceState, deviceFrontEnd, deviceStorage);
  });
}


export function jumpPlaceFile({ history = window.ReactHistory, base, placeId, beforeAction }) {
  // const { Utils } = window;
  // if (!BaseStore.menu.isAuth('placeFile')) {
  //   return Utils.log.debug('暂无场所档案权限！');
  // }
  // const placeInfo = BaseStore.place.getPlaceInfoById(placeId);
  // if (!(placeInfo && placeInfo.placeInfoUrl)) {
  //   return message.warn('您无当前场所权限，不支持查看场所档案!');
  // }
  // base = base ? base : getThemeMode() === 'single' ? `/objectMap/${BaseStore.tab.createTabKey()}` : `/objectMap/${getTopModuleKey('objectMap')}`;
  const pathname = `/objectMap/placeFile?id=${placeId}`;
  beforeAction && beforeAction();
  history.push(pathname);
}
