"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _sumBy = _interopRequireDefault(require("lodash/sumBy"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _vmNodata = _interopRequireDefault(require("../../../vm-nodata"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var Wgfx = function Wgfx(props) {
  var _useSettings = (0, _useSettings2["default"])(),
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor,
    theme = _useSettings.theme;
  var _props$data = props.data,
    data = _props$data === void 0 ? [] : _props$data;
  var total = 0;
  var list = [];
  if ((data === null || data === void 0 ? void 0 : data.length) > 0) {
    total = (0, _sumBy["default"])(data, function (o) {
      return o.count;
    });
    list = data.map(function (ele) {
      return {
        name: ele.alarmTypeName,
        value: ele.count
      };
    });
  }
  var option = {
    color: chartColor,
    backgroundColor: 'transparent',
    tooltip: {
      trigger: 'item',
      formatter: function formatter(params) {
        var _a, _b;
        //tongjia
        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; // 返回带点的字符串
      }
    },
    title: {
      zlevel: 0,
      text: '总数',
      top: '33%',
      left: '19%',
      textAlign: 'center',
      textStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 14
      },
      subtext: "".concat(total || 0),
      subtextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 28
      }
    },
    legend: {
      orient: 'vertical',
      left: '50%',
      top: 'middle',
      align: 'left',
      itemGap: 8,
      itemWidth: 10,
      itemHeight: 10,
      formatter: function formatter(name) {
        var value = list.find(function (item) {
          return item.name === name;
        });
        if (value) {
          return "\t\t".concat(name, "\t\t").concat(value.value, "\u6B21\t\t");
        } 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%', '40%'],
      hoverAnimation: true,
      z: 10,
      itemStyle: {
        normal: {
          borderWidth: 2,
          borderColor: '#003359'
        }
      },
      label: {
        show: false
      },
      data: list,
      labelLine: {
        show: false
      }
    }]
  };
  return (data === null || data === void 0 ? void 0 : data.length) > 0 ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '100%',
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], null));
};
var _default = exports["default"] = Wgfx;
//# sourceMappingURL=Wgfx.js.map
