"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
exports.getMinHundred = getMinHundred;
var _react = _interopRequireWildcard(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _vmSubTitle = _interopRequireDefault(require("../../../vm-sub-title"));
var _vmButton = _interopRequireDefault(require("../../../vm-button"));
var _vmCharts = require("../../../vm-charts");
var _api = require("../../api");
var _groupBy = _interopRequireDefault(require("lodash/groupBy"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var getPieOption = function getPieOption(data) {
  return {
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: 'center',
      left: '35%',
      type: 'scroll',
      orient: 'vertical',
      formatter: function formatter(name) {
        var _a;
        var obj = (_a = data === null || data === void 0 ? void 0 : data.find) === null || _a === void 0 ? void 0 : _a.call(data, function (item) {
          return item.alarmTypeName === name;
        });
        return "{a|".concat(name, "}{a|").concat((obj === null || obj === void 0 ? void 0 : obj.count) || 0, "\u6B21}{a|\u5747\u503C\uFF1A").concat((obj === null || obj === void 0 ? void 0 : obj.countAvg) || 0, "\u6B21}");
      },
      textStyle: {
        color: '#fff',
        rich: {
          a: {
            width: 60
          }
        }
      }
    },
    series: [{
      name: '事件类型分布',
      type: 'pie',
      radius: ['50%', '80%'],
      center: ['15%', '50%'],
      avoidLabelOverlap: false,
      labelLine: {
        show: false
      },
      label: {
        show: false
      },
      data: data.map(function (item) {
        return {
          name: item.alarmTypeName,
          value: item.count
        };
      })
    }]
  };
};
var PieCharType;
(function (PieCharType) {
  PieCharType["SJLX"] = "\u4E8B\u4EF6\u7C7B\u578B\u5206\u5E03";
  PieCharType["QS"] = "\u8FD1\u4E00\u5468\u8D8B\u52BF";
})(PieCharType || (PieCharType = {}));
function getMinHundred(num) {
  return Math.ceil(num / 100) * 100 || 100;
}
function transferLineData() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var groupByThrowPoint = (0, _groupBy["default"])(data || [], 'throwPointId');
  var groupByDay = (0, _groupBy["default"])(data || [], 'day');
  var lineData = [];
  for (var key in groupByThrowPoint) {
    var item = groupByThrowPoint[key];
    lineData.push({
      name: item[0].alarmTypeName || '',
      data: item.map(function (item) {
        return item.count || 0;
      })
    });
  }
  // 去除日期中的年
  var xAxis = Object.keys(groupByDay).map(function (item) {
    return item.substring(5);
  });
  return {
    xAxis: xAxis,
    data: lineData
  };
}
var RightBottom = function RightBottom(_ref) {
  var classPrefix = _ref.classPrefix,
    id = _ref.id;
  var _useState = (0, _react.useState)(PieCharType.SJLX),
    _useState2 = _slicedToArray(_useState, 2),
    pieChartType = _useState2[0],
    setPieChartType = _useState2[1];
  // 事件类型分布
  var alarmByTypeData = _api.overViewService.alarmSumByType({
    housingEstateId: id
  });
  // 近一周趋势
  var alarmByDateData = _api.overViewService.alarmSumByDate({
    housingEstateId: id
  });
  // 工单处理效率
  var efficiencyData = _api.overViewService.resolveEfficiency({
    housingEstateId: id
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom")
  }, /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "AI\u5DE5\u5355"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom--buttons")
  }, /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    onClick: function onClick() {
      return setPieChartType(PieCharType.SJLX);
    },
    name: "\u4E8B\u4EF6\u7C7B\u578B\u5206\u5E03",
    active: pieChartType === PieCharType.SJLX,
    style: {
      marginRight: 10
    }
  }), /*#__PURE__*/_react["default"].createElement(_vmButton["default"], {
    onClick: function onClick() {
      return setPieChartType(PieCharType.QS);
    },
    name: "\u8FD1\u4E00\u5468\u8D8B\u52BF",
    active: pieChartType === PieCharType.QS
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom--pie")
  }, pieChartType === PieCharType.SJLX && /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getPieOption(alarmByTypeData || []),
    style: {
      height: 150
    }
  }), pieChartType === PieCharType.QS && /*#__PURE__*/_react["default"].createElement(_vmCharts.Line1, Object.assign({}, transferLineData(alarmByDateData), {
    style: {
      height: 150
    }
  }))), /*#__PURE__*/_react["default"].createElement(_vmSubTitle["default"], {
    title: "\u5DE5\u5355\u5904\u7406\u6548\u7387"
  }), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classPrefix, "-rightbottom--gauges")
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: "gauges-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u5173\u95ED\u7387",
    unit: "%",
    min: 0,
    max: 100,
    num: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRate) || 0,
    average: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRateAverage) || 0
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "gauges-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u5904\u7406\u65F6\u957F",
    unit: "\u5206",
    min: 0,
    max: getMinHundred(Math.max((efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinute) || 0, (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinuteAverage) || 0)),
    num: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinute) || 0,
    average: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinuteAverage) || 0
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "gauges-chart"
  }, /*#__PURE__*/_react["default"].createElement(_vmCharts.Gauge1, {
    name: "AI\u5DE5\u5355\u53CA\u65F6\u5173\u95ED\u7387",
    unit: "%",
    min: 0,
    max: 100,
    num: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRate) || 0,
    average: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRateAverage) || 0
  }))));
};
var _default = RightBottom;
exports["default"] = _default;
//# sourceMappingURL=RightBottom.js.map
