"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 _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("../../../vtx-cp-modal/imgs/alarm.png"));
var _index = require("./../../index");
var _vmCard = _interopRequireDefault(require("../../../vm-card"));
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); }
var Summary = function Summary() {
  var _useSettings = (0, _useSettings2["default"])(),
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor,
    isDark = _useSettings.isDark,
    theme = _useSettings.theme;
  var _useContext = (0, _react.useContext)(_index.CcCpContext),
    id = _useContext.id;
  var alarmSummary = _api.AlarmService.getMonthCompareData(id, (0, _moment["default"])().format('YYYY-MM'));
  var alarmTypes = _api.AlarmService.getSyPointAbnormalTypeNums(id, (0, _moment["default"])().startOf('M').format('YYYY-MM-DD'), (0, _moment["default"])().endOf('M').format('YYYY-MM-DD'));
  var month = (0, _moment["default"])().month() + 1;
  var totalCount = (0, _sumBy["default"])(alarmTypes, 'labelValue');
  var alarmTabsValue = alarmTypes.map(function (item) {
    return {
      name: item.labelName,
      value: item.labelValue
    };
  });
  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(_vmCard["default"], {
    title: "".concat(month, "\u6708\u62A5\u8B66\u4FE1\u606F")
  }, /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time"
  }, /*#__PURE__*/_react["default"].createElement("img", {
    src: _alarm["default"]
  }), /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time-name"
  }, "\u6708\u5EA6\u62A5\u8B66\u603B\u6B21\u6570"), /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time-value"
  }, /*#__PURE__*/_react["default"].createElement("span", null, (alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.thisMonthNum) || 0), "\u6B21", /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-summary-time-value-compare"
  }, "\u6708\u540C\u6BD4 ".concat((alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.tbData) || 0, "%"), ((alarmSummary === null || alarmSummary === void 0 ? void 0 : alarmSummary.tbData) || 0) >= 100 ? (/*#__PURE__*/_react["default"].createElement("div", {
    className: "triangle-up"
  })) : (/*#__PURE__*/_react["default"].createElement("div", {
    className: "triangle-down"
  })))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: "alarm-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
