function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { request } from '@vtx/utils';
import { useRequest } from 'ahooks';
var CommonService = {
  useBaseInfo: function useBaseInfo(id) {
    var _baseInfoRes$data, _baseInfoRes$data2, _tabConfig$data;
    var coordType = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'wgs84';
    var _useRequest = useRequest(function () {
        return request.get('/cloud/jcss-reborn/facility/get', {
          data: {
            id: id,
            coordType: coordType
          }
        });
      }, {
        refreshDeps: [id]
      }),
      baseInfoRes = _useRequest.data;
    var info = baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data;
    var _useRequest2 = useRequest(function () {
        return request.get('/cloud/jcss-reborn/facility/type/config/getByCode', {
          data: {
            code: baseInfoRes.data.typeCode
          }
        });
      }, {
        ready: !!(baseInfoRes !== null && baseInfoRes !== void 0 && (_baseInfoRes$data = baseInfoRes.data) !== null && _baseInfoRes$data !== void 0 && _baseInfoRes$data.typeCode),
        refreshDeps: [baseInfoRes === null || baseInfoRes === void 0 || (_baseInfoRes$data2 = baseInfoRes.data) === null || _baseInfoRes$data2 === void 0 ? void 0 : _baseInfoRes$data2.typeCode]
      }),
      tabConfig = _useRequest2.data;
    var photos = info !== null && info !== void 0 && info.photoIds ? JSON.parse(info.photoIds) : info !== null && info !== void 0 && info.typePhotoIds ? JSON.parse(info.typePhotoIds) : [];
    return {
      photos: photos,
      code: info === null || info === void 0 ? void 0 : info.code,
      info: info,
      tabConfig: (tabConfig === null || tabConfig === void 0 || (_tabConfig$data = tabConfig.data) === null || _tabConfig$data === void 0 || (_tabConfig$data = _tabConfig$data.popupConfigJson) === null || _tabConfig$data === void 0 ? void 0 : _tabConfig$data.filter(function (ele) {
        return ele.display;
      }).map(function (ele) {
        return _objectSpread(_objectSpread({}, ele), {}, {
          key: ele.code,
          title: ele.name
        });
      })) || []
    };
  },
  //基础设施详情展示字段
  useGetFields: function useGetFields(code) {
    var _data$data$baseFields;
    var _useRequest3 = useRequest(function () {
        return request.get('/cloud/jcss-reborn/facility/type/view/detail', {
          data: {
            code: code
          }
        });
      }, {
        refreshDeps: [code],
        ready: !!code
      }),
      data = _useRequest3.data;
    return data !== null && data !== void 0 && data.data ? ((_data$data$baseFields = data.data.baseFields) === null || _data$data$baseFields === void 0 ? void 0 : _data$data$baseFields.filter(function (ele) {
      return !['photoIds', 'geometryInfo', 'orderIndex', 'geoPointLocation', 'geoLineLocation', 'geoPolygonLocation'].includes(ele.key);
    }).concat(data.data.customFields)) || [] : [];
  },
  // 计量详情
  useLmDetail: function useLmDetail(id, hasConfig) {
    var _useRequest4 = useRequest(function () {
        return request.get('/cloud/zd/base/api/cp/commonFactory/getCommonFactoryById.smvc', {
          data: {
            factoryId: id
          }
        });
      }, {
        refreshDeps: [id],
        ready: hasConfig
      }),
      res = _useRequest4.data;
    return {
      detail: (res === null || res === void 0 ? void 0 : res.data) || {}
    };
  },
  // 计量详情
  useLmDetailZdReborn: function useLmDetailZdReborn(id) {
    var _useRequest5 = useRequest(function () {
        return request.post('/cloud/zd-reborn/api/base/commonFactory/getCommonFactoryById?factoryId=' + id, {
          data: JSON.stringify({
            factoryId: id
          })
        });
      }, {
        refreshDeps: [id]
      }),
      res = _useRequest5.data;
    return {
      detail: (res === null || res === void 0 ? void 0 : res.data) || {}
    };
  }
};
export { CommonService };
export var getPreviewUrl = function getPreviewUrl(params) {
  return request.get('/cloud/vis/base/np/artemis/previewUrl.smvc', {
    data: params
  });
};
export var getBackUrl = function getBackUrl(params) {
  return request.get('/cloud/vis/base/cp/artemis/playbackUrl.smvc', {
    data: params
  });
};
export var execute = function execute(code, parameters) {
  return request.post('/cloud/sjzt-reborn/api/v101/dataSet/execute', {
    data: JSON.stringify({
      code: code,
      parameters: parameters
    })
  });
};