"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _vmFilter = require("../../vm-filter");
var _vmCharts = require("../../vm-charts");
require("./index.less");
var _moment = _interopRequireDefault(require("moment"));
var _utils = require("@vtx/utils");
var _vmContainer = _interopRequireDefault(require("../../vm-container"));
var _useSettings2 = _interopRequireDefault(require("../../vm-hooks/useSettings"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure 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 _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; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /**
 * 报警趋势
 */
function AlarmTrend(props) {
  var id = props.id,
    publicUrlJCSS = props.publicUrlJCSS,
    filterParams = props.filterParams;
  var _useState = (0, _react.useState)(1),
    _useState2 = _slicedToArray(_useState, 2),
    compareType = _useState2[0],
    setCompareType = _useState2[1];
  var _useState3 = (0, _react.useState)(''),
    _useState4 = _slicedToArray(_useState3, 2),
    alarmType = _useState4[0],
    setAlarmType = _useState4[1];
  var _useState5 = (0, _react.useState)(1),
    _useState6 = _slicedToArray(_useState5, 2),
    timeType = _useState6[0],
    setTimeType = _useState6[1];
  var _useState7 = (0, _react.useState)([]),
    _useState8 = _slicedToArray(_useState7, 2),
    trendData = _useState8[0],
    setAlarmTrendData = _useState8[1];
  var _useState9 = (0, _react.useState)([]),
    _useState0 = _slicedToArray(_useState9, 2),
    xData = _useState0[0],
    setXData = _useState0[1];
  var _useState1 = (0, _react.useState)([(0, _moment["default"])().subtract(3, 'day').format('YYYY-MM-DD 00:00:00'), (0, _moment["default"])().format('YYYY-MM-DD 23:59:59')]),
    _useState10 = _slicedToArray(_useState1, 2),
    rangeTime = _useState10[0],
    setRangeTime = _useState10[1];
  (0, _react.useEffect)(function () {
    getAlarmTrend();
  }, [alarmType, timeType, compareType, rangeTime]);
  var _useSettings = (0, _useSettings2["default"])(),
    theme = _useSettings.theme;
  var getAlarmTrend = function getAlarmTrend() {
    var time = {
      1: {
        startTime: (0, _moment["default"])(rangeTime[0]).format('YYYY-MM-DD 00:00:00'),
        endTime: (0, _moment["default"])(rangeTime[1]).format('YYYY-MM-DD 23:59:59')
      },
      2: {
        startTime: (0, _moment["default"])(rangeTime[0]).format('YYYY-MM-01 00:00:00'),
        endTime: (0, _moment["default"])(rangeTime[1]).format('YYYY-MM-DD 23:59:59')
      },
      3: {
        startTime: (0, _moment["default"])(rangeTime[0]).format('YYYY-01-01 00:00:00'),
        endTime: (0, _moment["default"])(rangeTime[1]).format('YYYY-MM-DD 23:59:59')
      }
    }[timeType];
    _utils.request.get("".concat(publicUrlJCSS, "/api/facility/warnTrend"), {
      data: Object.assign(Object.assign({
        isTotal: true,
        alarmType: alarmType,
        facilityId: id,
        compareType: compareType,
        timeType: timeType
      }, time), filterParams || {})
    }).then(function (res) {
      if (String(res === null || res === void 0 ? void 0 : res.result) === '0' && (res === null || res === void 0 ? void 0 : res.data)) {
        var newData = [];
        var _xData = [];
        res.data.map(function (v) {
          newData.push(v.warnCount);
          _xData.push(v.recordTime);
        });
        var alarmTrendData = [{
          name: '次数',
          data: newData,
          areaStyle: {
            opacity: 0.4
          },
          label: {
            show: true,
            position: 'top',
            formatter: function formatter(v) {
              var _a;
              var data = (_a = res.data[v === null || v === void 0 ? void 0 : v.dataIndex]) === null || _a === void 0 ? void 0 : _a.compareValue;
              if (data || String(data) === '0') {
                if (data > 0) {
                  return "{a|+".concat(data, "%}");
                } else if (data < 0) {
                  return "{b|".concat(data, "%}");
                } else {
                  return "{c|".concat(data, "%}");
                }
              }
            },
            rich: {
              a: {
                color: '#D9001B'
              },
              b: {
                color: '#99B603'
              },
              c: {
                color: '#fff'
              }
            }
          }
        }];
        setAlarmTrendData(alarmTrendData);
        setXData(_xData);
      }
    });
  };
  var typeItems = [{
    type: 'radio',
    label: '报警类别：',
    defaultValue: '',
    itemProps: {
      options: [{
        title: '全部',
        value: ''
      }, {
        title: '数值',
        value: '1'
      }, {
        title: '离线',
        value: '2'
      }]
    },
    onChange: function onChange(e) {
      setAlarmType(e.target.value);
    }
  }];
  var items = [{
    type: 'radio',
    label: '趋势类型：',
    itemProps: {
      options: [{
        title: '同比',
        value: '1'
      }, {
        title: '月环比',
        value: '2',
        width: '80px'
      }]
    },
    onChange: function onChange(e) {
      setCompareType(e.target.value);
    },
    defaultValue: '1'
  }];
  var dateItem = [{
    type: 'radioTime',
    timeStyle: {
      width: '240px'
    },
    itemProps: {
      options: [{
        title: '日',
        value: 'date'
      }, {
        title: '月',
        value: 'month'
      }, {
        title: '年',
        value: 'year'
      }],
      defaultTimeValue: [(0, _moment["default"])((0, _moment["default"])().subtract(3, 'day'), 'YYYY-MM-DD 00:00:00'), (0, _moment["default"])((0, _moment["default"])(), 'YYYY-MM-DD 23:59:59')],
      onRadioChange: function onRadioChange(e) {
        var time = {
          date: 1,
          month: 2,
          year: 3
        };
        // @ts-ignore
        setTimeType(time[e.target.value]);
      },
      onTimeChange: setRangeTime
    },
    defaultValue: 'date'
  }];
  return /*#__PURE__*/_react["default"].createElement(_vmContainer["default"], {
    title: "\u62A5\u8B66\u8D8B\u52BF",
    style: {
      height: '100%'
    },
    contentStyle: {
      height: '100%'
    },
    headerContent: /*#__PURE__*/_react["default"].createElement(_vmFilter.VmFilterItem, {
      items: dateItem
    })
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "item ".concat(theme)
  }, /*#__PURE__*/_react["default"].createElement(_vmFilter.VmFilterItem, {
    items: typeItems
  }), /*#__PURE__*/_react["default"].createElement(_vmFilter.VmFilterItem, {
    items: items
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-trend"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Line, {
    style: {
      height: 380
    },
    data: trendData,
    xAxis: xData,
    exportShow: true
  })));
}
var _default = exports["default"] = AlarmTrend;
//# sourceMappingURL=AlarmTrend.js.map
