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); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
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(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(arr) { if (Array.isArray(arr)) return arr; }
import { Progress } from 'antd';
import { sumBy } from 'lodash';
import groupBy from 'lodash/groupBy';
import { useState } from 'react';
import { VmLineCharts, VmPieCharts, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { overViewService } from "../../api";
import { getFilterEcharts } from "../../config";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
export function getMinHundred(num) {
  return Math.ceil(num / 100) * 100 || 100;
}
export function getPercent(num) {
  return num ? num * 100 : 0;
}
var RightBottom = function RightBottom(_ref) {
  var classPrefix = _ref.classPrefix,
    id = _ref.id,
    serviceList = _ref.serviceList;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState('efficiency'),
    _useState2 = _slicedToArray(_useState, 2),
    pieChartType = _useState2[0],
    setPieChartType = _useState2[1];
  // 事件类型分布
  var alarmByTypeData = overViewService.useAlarmSumByType({
    housingEstateId: id
  });
  // 近一周趋势
  var alarmByDateData = overViewService.useAlarmSumByDate({
    housingEstateId: id
  });
  // 工单处理效率
  var efficiencyData = overViewService.useResolveEfficiency({
    housingEstateId: id
  });
  var lineData = (getFilterEcharts(alarmByDateData, serviceList) || []).map(function (item) {
    return {
      name: item.alarmTypeName || '',
      count: item.count || 0,
      day: item.day || ''
    };
  });
  var _pieData = getFilterEcharts(alarmByTypeData, serviceList) || [];
  var strokeColor = {
    alarm: {
      '0%': '#FF575F',
      '100%': '#F5222D'
    },
    normal: {
      '0%': '#02E574',
      '100%': '#0FB964'
    }
  };
  return /*#__PURE__*/_jsx("div", {
    className: "".concat(classPrefix, "-rightbottom"),
    children: /*#__PURE__*/_jsx(VmWrapper, {
      tabList: [{
        label: 'AI工单处理',
        key: 'efficiency'
      }, {
        label: '近一周趋势',
        key: 'trend'
      }],
      activeKey: pieChartType,
      onChangeTab: function onChangeTab(key) {
        return setPieChartType(key);
      },
      children: pieChartType === 'efficiency' ? /*#__PURE__*/_jsxs(_Fragment, {
        children: [/*#__PURE__*/_jsx(VmPieCharts, {
          dataList: (_pieData === null || _pieData === void 0 ? void 0 : _pieData.map(function (item) {
            return {
              name: item.alarmTypeName || '--',
              value: item.count
            };
          })) || [],
          height: 120,
          name: '事件类型',
          title: "\u603B\u6570",
          innerRadius: ['65%', '80%'],
          outerRadius: ['80%', '95%'],
          legendConfig: {
            right: 0
          },
          spaceLength: 0,
          total: sumBy(_pieData, 'count'),
          unit: "\u8D77"
        }), /*#__PURE__*/_jsx("div", {
          className: "".concat(classPrefix, "-rightbottom-progress"),
          children: [{
            name: 'AI 工单关闭率',
            value: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRate),
            avg: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeRateAverage),
            unit: '%'
          }, {
            name: 'AI 工单处理时长',
            value: ((efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinute) || 0) / ((efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinuteAverage) || 1),
            avg: (efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.resolveMinuteAverage) || 0,
            unit: '分'
          }, {
            name: 'AI 工单及时关闭率',
            value: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRate),
            avg: getPercent(efficiencyData === null || efficiencyData === void 0 ? void 0 : efficiencyData.closeInTimeRateAverage),
            unit: '%'
          }].map(function (ele, index) {
            return /*#__PURE__*/_jsxs("div", {
              className: "".concat(classPrefix, "-rightbottom-progress-item"),
              children: [/*#__PURE__*/_jsx("div", {
                children: ele.name
              }), /*#__PURE__*/_jsx(Progress, {
                type: "dashboard",
                percent: ele.value,
                size: 120,
                width: 120,
                strokeWidth: 10,
                gapDegree: 180,
                strokeLinecap: "butt",
                strokeColor: strokeColor[ele.value > ele.avg ? 'alarm' : 'normal'],
                trailColor: isDark ? '#9B9FA8' : 'rgba(0, 0, 0, 0.1)',
                railColor: isDark ? '#9B9FA8' : 'rgba(0, 0, 0, 0.1)',
                showInfo: false
              }), /*#__PURE__*/_jsxs("div", {
                className: "".concat(classPrefix, "-rightbottom-progress-desc"),
                children: ["\u5747\u503C", ele.avg, ele.unit, /*#__PURE__*/_jsxs("div", {
                  className: ele.value > ele.avg ? 'white_red' : 'white_green',
                  style: {
                    fontSize: 16
                  },
                  children: [ele.value, ele.unit]
                })]
              })]
            }, index);
          })
        })]
      }) : /*#__PURE__*/_jsx(VmLineCharts, _objectSpread(_objectSpread({}, transferLineData(lineData)), {}, {
        unit: "\u8D77",
        height: 238
      }))
    })
  });
};
export default RightBottom;
export function transferLineData() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var groupByThrowPoint = groupBy(data || [], 'name');
  var groupByDay = groupBy(data || [], 'day');
  var lineData = [];
  // eslint-disable-next-line guard-for-in
  for (var key in groupByThrowPoint) {
    var item = groupByThrowPoint[key];
    lineData.push({
      name: item[0].name || '',
      data: item.map(function (item) {
        return item.count || 0;
      })
    });
  }
  // 去除日期中的年
  var xAxis = Object.keys(groupByDay).map(function (item) {
    return item.substring(5);
  });
  return {
    xAxis: xAxis,
    dataList: lineData
  };
}