"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 _ahooks = require("ahooks");
var _moment = _interopRequireDefault(require("moment"));
var _sumBy = _interopRequireDefault(require("lodash/sumBy"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
var _api = require("../../api");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _alarm = _interopRequireDefault(require("../../imgs/alarm.png"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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; } /**
 * 公厕-异常信息-异常信息汇总
 */
var Summary = function Summary(_ref) {
  var id = _ref.id;
  var _useSettings = (0, _useSettings2["default"])(),
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor,
    isDark = _useSettings.isDark,
    theme = _useSettings.theme;
  var _useSetState = (0, _ahooks.useSetState)({
      alarmTabsValue: [],
      totalCount: 0
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var alarmTabsValue = state.alarmTabsValue,
    totalCount = state.totalCount;
  var _ExeceptionService$us = _api.ExeceptionService.useAlarmSummary(id, (0, _moment["default"])().format('YYYY-MM-DD')),
    alarmSummary = _ExeceptionService$us.alarmSummary;
  var _ExeceptionService$us2 = _api.ExeceptionService.useAlarmTrend(id, (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'), (0, _moment["default"])().format('YYYY-MM-DD')),
    alarmTypes = _ExeceptionService$us2.alarmTypes;
  (0, _react.useEffect)(function () {
    var list = [];
    var count = 0;
    if ((alarmTypes === null || alarmTypes === void 0 ? void 0 : alarmTypes.length) > 0) {
      count = (0, _sumBy["default"])(alarmTypes, function (o) {
        return o.count;
      });
      alarmTypes.forEach(function (ele) {
        var obj = {
          key: ele.typeCode,
          name: ele.typeName,
          value: ele.count
        };
        list.push(obj);
      });
      setState({
        totalCount: count,
        alarmTabsValue: list
      });
    }
  }, [alarmTypes]);
  var option = {
    color: chartColor,
    backgroundColor: 'transparent',
    tooltip: {
      trigger: 'item',
      formatter: function formatter(params) {
        var _a, _b;
        var unit = '次';
        var str = '';
        if (Array.isArray(params)) {
          str = "<div  style=\"text-align:left\">".concat((_a = params === null || params === void 0 ? void 0 : params[0]) === null || _a === void 0 ? void 0 : _a.axisValue, "<?div>");
          var color = (_b = params === null || params === void 0 ? void 0 : params[0].color) === null || _b === void 0 ? void 0 : _b.colorStops; // 获取系列的颜色
          params.map(function (item, index) {
            var _a;
            str += "<div  style=\"text-align:left\"><span style=\"color:".concat(item.color && typeof item.color == 'string' ? item.color : (_a = color === null || color === void 0 ? void 0 : color[index]) === null || _a === void 0 ? void 0 : _a.color, "\">\u2022</span> ").concat(item.seriesName, " &nbsp;&nbsp;&nbsp;").concat(item.value).concat(unit, "</div>");
          });
        } else {
          var _color = params === null || params === void 0 ? void 0 : params.color; // 获取系列的颜色
          str += "<div style=\"display:flex;align-items:center\"><span style=\"color:".concat(_color, ";font-size:24px \">\u2022</span>&nbsp;").concat(params === null || params === void 0 ? void 0 : params.name, "&nbsp;&nbsp;").concat(params.value).concat(unit, "</div>");
        }
        return str; // 返回带点的字符串
      }
    },
    legend: {
      orient: 'vertical',
      left: '40%',
      top: 'middle',
      align: 'left',
      itemGap: 8,
      itemWidth: 10,
      itemHeight: 10,
      formatter: function formatter(name) {
        var value = alarmTabsValue.find(function (item) {
          return item.name === name;
        });
        var rate = ((value === null || value === void 0 ? void 0 : value.value) || 0) / totalCount * 100;
        if (value) {
          return "\t\t".concat(name, "\t\t").concat(value.value, "\u6B21\t\t").concat(rate.toFixed(2), "%");
        } else {
          return '';
        }
      },
      textStyle: {
        fontSize: 14,
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      pageIconColor: chartFontColor,
      pageIconInactiveColor: chartFontColor,
      pageTextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      }
    },
    series: [{
      type: 'pie',
      radius: ['55%', '75%'],
      center: ['20%', '50%'],
      hoverAnimation: true,
      z: 10,
      itemStyle: {
        normal: {
          borderWidth: 2,
          borderColor: isDark ? '#003359' : '#ffffff'
        }
      },
      label: {
        show: false
      },
      data: alarmTabsValue,
      labelLine: {
        show: false
      }
    }]
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "exeception-summary"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u5F02\u5E38\u4FE1\u606F\u6C47\u603B"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "exeception-summary-time"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _alarm["default"]
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "exeception-summary-time-name"
  }, "\u6708\u5EA6\u5F02\u5E38\u603B\u6B21\u6570"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "exeception-summary-time-value"
  }, /*#__PURE__*/_react["default"].createElement("span", null, (alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisMonthCount) || 0), "\u6B21", /*#__PURE__*/_react["default"].createElement("div", {
    className: "exeception-summary-time-value-compare"
  }, "\u6708\u540C\u6BD4 ".concat((alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisMonthOnLastMonthCount) || 0, "%"), (alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisMonthOnLastMonthCount) >= 100 ? (/*#__PURE__*/_react["default"].createElement("div", {
    className: "triangle-up"
  })) : (/*#__PURE__*/_react["default"].createElement("div", {
    className: "triangle-down"
  })))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "exeception-summary-type-analysis"
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u7C7B\u578B\u5206\u6790"
  }), (alarmTabsValue === null || alarmTabsValue === void 0 ? void 0 : alarmTabsValue.length) > 0 ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '180px',
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: '180px',
      marginLeft: '50%',
      transform: 'translateX(-50%)'
    }
  }))));
};
var _default = exports["default"] = Summary;
//# sourceMappingURL=Summary.js.map
