"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Service = void 0;
var _ahooks = require("ahooks");
var _utils = require("@vtx/utils");
var handelData = function handelData() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  // 横坐标、同比、环比
  var xAxisData = [],
    compareData = [],
    sequentialData = [],
    barChartData = {};
  data.map(function (item) {
    var _a;
    var sdkDTO = item.sdkDTO,
      _item$recordTime = item.recordTime,
      recordTime = _item$recordTime === void 0 ? null : _item$recordTime,
      _item$compareValue = item.compareValue,
      compareValue = _item$compareValue === void 0 ? null : _item$compareValue,
      _item$sequentialValue = item.sequentialValue,
      sequentialValue = _item$sequentialValue === void 0 ? null : _item$sequentialValue;
    xAxisData.push(recordTime);
    compareData.push(compareValue);
    sequentialData.push(sequentialValue);
    (sdkDTO === null || sdkDTO === void 0 ? void 0 : sdkDTO.statistics) && ((_a = sdkDTO === null || sdkDTO === void 0 ? void 0 : sdkDTO.statistics) === null || _a === void 0 ? void 0 : _a.length) && (sdkDTO === null || sdkDTO === void 0 ? void 0 : sdkDTO.statistics.map(function (val) {
      if (val.name && barChartData[val.name]) {
        barChartData[val.name].push(val.num || null);
      } else if (val.name && !barChartData[val.name]) {
        barChartData[val.name] = [val.num || null];
      }
    }));
  });
  var alarmData = {
    xAxisData: xAxisData,
    compareData: compareData,
    sequentialData: sequentialData,
    barChartData: barChartData // 因子数据集合
  };
  return alarmData;
};
var Service = exports.Service = {
  UseAlarmData: function UseAlarmData(_ref) {
    var id = _ref.id,
      publicUrlJCSS = _ref.publicUrlJCSS,
      startTime = _ref.startTime,
      endTime = _ref.endTime,
      timeType = _ref.timeType;
    // 报警情况
    var _useRequest = (0, _ahooks.useRequest)(function () {
        if (id) {
          return _utils.request.get("".concat(publicUrlJCSS, "/api/device/deviceWarnTrend"), {
            body: {
              deviceId: id,
              startTime: startTime,
              endTime: endTime,
              timeType: timeType
            }
          });
        }
      }, {
        refreshDeps: [id, timeType]
      }),
      baseInfoRes = _useRequest.data;
    var alarmData = handelData(baseInfoRes === null || baseInfoRes === void 0 ? void 0 : baseInfoRes.data);
    return {
      alarmData: alarmData
    };
  }
};
//# sourceMappingURL=api.js.map
