"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _moment = _interopRequireDefault(require("moment"));
var _vmTable = _interopRequireDefault(require("../../../vm-table"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
require("./index.less");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
 * 计量-工况信息
 */
var WorkCondition = function WorkCondition(props) {
  var _a, _b, _c;
  var _useSettings = (0, _useSettings2["default"])(),
    tabPosition = _useSettings.tabPosition;
  var startDate = props.startDate,
    endDate = props.endDate,
    deviceId = props.deviceId;
  var _BaseService$useRealt = _api.BaseService.useRealtime(deviceId),
    realtimeRes = _BaseService$useRealt.realtimeRes;
  var _BaseService$useJczbq = _api.BaseService.useJczbqsfx((_a = realtimeRes === null || realtimeRes === void 0 ? void 0 : realtimeRes.map(function (ele) {
      return ele.monitorItemCode;
    })) === null || _a === void 0 ? void 0 : _a.join(','), deviceId, (0, _moment["default"])(startDate).format('YYYY-MM-DD 00:00:00'), (0, _moment["default"])(endDate).format('YYYY-MM-DD 23:59:59')),
    timeSumData = _BaseService$useJczbq.timeSumData;
  var data = [];
  if (!(timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.names) || ((_b = timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.names) === null || _b === void 0 ? void 0 : _b.length) < 1) {
    data = [];
  } else {
    var extraData = timeSumData.extraData,
      names = timeSumData.names,
      values = timeSumData.values;
    names.forEach(function (name, index) {
      var obj = {};
      extraData === null || extraData === void 0 ? void 0 : extraData.forEach(function (item, idx) {
        obj[item.monitorItemName] = values[idx][index];
      });
      data.push(Object.assign({
        time: name
      }, obj));
    });
  }
  var columns = [].concat(_toConsumableArray(((_c = timeSumData === null || timeSumData === void 0 ? void 0 : timeSumData.extraData) === null || _c === void 0 ? void 0 : _c.map(function (ele) {
    return {
      title: ele.unit ? "".concat(ele.monitorItemName, "(").concat(ele.unit, ")") : "".concat(ele.monitorItemName),
      dataIndex: ele.monitorItemName,
      key: ele.monitorItemName,
      render: function render(text) {
        return text || '-';
      }
    };
  })) || []), [{
    title: '数据采集时间',
    dataIndex: 'time',
    key: 'time',
    fixed: 'right',
    sorter: function sorter(a, b) {
      return (0, _moment["default"])(a.time).valueOf() - (0, _moment["default"])(b.time).valueOf();
    },
    render: function render(text) {
      return text || '-';
    }
  }]);
  var tableProps = {
    height: tabPosition === 'top' ? 424 : 462,
    paganitation: false,
    dataSource: data || []
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_vmTable["default"], Object.assign({
    columns: columns,
    rowKey: "time"
  }, tableProps)));
};
var _default = exports["default"] = WorkCondition;
//# sourceMappingURL=Table.js.map
