"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 Charts = function Charts(props) {
  var _a, _b;
  var _useSettings = (0, _useSettings2["default"])(),
    chartColor = _useSettings.chartColor,
    chartFontColor = _useSettings.chartFontColor,
    theme = _useSettings.theme;
  var _props$pieData = props.pieData,
    pieData = _props$pieData === void 0 ? [] : _props$pieData,
    _props$lineData = props.lineData,
    lineData = _props$lineData === void 0 ? {} : _props$lineData;
  var total = 0;
  var list = [];
  if ((pieData === null || pieData === void 0 ? void 0 : pieData.length) > 0) {
    total = (0, _sumBy["default"])(pieData, function (o) {
      return o.count;
    });
    list = pieData.map(function (ele) {
      return {
        name: ele.alarmTypeName,
        value: ele.count
      };
    });
  }
  var option = {
    color: chartColor,
    backgroundColor: 'transparent',
    tooltip: {
      show: true,
      trigger: 'item',
      formatter: function formatter(params) {
        var str = "";
        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, "\u6B21</div>");
        return str; // 返回带点的字符串
      }
    },
    title: {
      left: '29.5%',
      top: '40%',
      text: '报警总次数',
      textAlign: 'center',
      textStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 14
      },
      subtext: total || '0',
      subtextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 22
      }
    },
    legend: {
      orient: 'vertical',
      left: '42%',
      top: 'middle',
      align: 'left',
      itemGap: 12,
      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: ['30%', '50%'],
      hoverAnimation: true,
      z: 10,
      itemStyle: {
        normal: {
          borderWidth: 2,
          borderColor: '#12196b'
        }
      },
      label: {
        show: false
      },
      data: list,
      labelLine: {
        show: false
      }
    }]
  };
  var xAxis = (lineData === null || lineData === void 0 ? void 0 : lineData.names) || [];
  var lineOption = {
    color: chartColor,
    tooltip: {
      trigger: 'axis',
      formatter: function formatter(params) {
        var _a;
        var 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>");
        // let color = params[0].color; // 获取系列的颜色
        params.map(function (item) {
          str += "<div  style=\"text-align:left\" ><span style=\"color:".concat(item.color, " \">\u2022</span> ").concat(item.seriesName, " &nbsp;&nbsp;&nbsp;").concat(item.data, "\u6B21</div>");
        });
        return str; // 返回带点的字符串
      }
    },
    legend: {
      show: true,
      itemWith: 6,
      itemHeight: 6,
      top: 20,
      textStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor,
        fontSize: 12
      },
      data: (lineData === null || lineData === void 0 ? void 0 : lineData.legends) || []
    },
    grid: {
      // top: 58,
      left: 24,
      bottom: 12,
      right: 36,
      containLabel: true
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      data: xAxis || []
    },
    yAxis: [{
      name: '',
      type: 'value',
      nameTextStyle: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        color: theme === 'blue' ? '#fff' : chartFontColor
      },
      axisLine: {
        show: true
      },
      splitLine: {
        lineStyle: {
          type: 'dashed',
          color: 'rgba(151,151,151,0.28)'
        }
      }
    }],
    series: ((_a = lineData === null || lineData === void 0 ? void 0 : lineData.values) === null || _a === void 0 ? void 0 : _a.length) > 0 ? lineData.values.map(function (ele, index) {
      return {
        type: 'line',
        name: lineData.legends[index],
        data: ele
      };
    }) : []
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "car-alarm-charts"
  }, (pieData === null || pieData === void 0 ? void 0 : pieData.length) ? (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: option,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '200px',
      width: '100%'
    }
  })) : (/*#__PURE__*/_react["default"].createElement(_vmNodata["default"], {
    style: {
      height: '200px',
      width: '400px'
    }
  })), ((_b = lineData === null || lineData === void 0 ? void 0 : lineData.values) === null || _b === void 0 ? void 0 : _b.length) > 0 && (/*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: lineOption,
    notMerge: true,
    lazyUpdate: true,
    style: {
      height: '300px',
      width: '100%'
    }
  })));
};
var _default = exports["default"] = Charts;
//# sourceMappingURL=Charts.js.map
