function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 { Space } from 'antd';
import dayjs from 'dayjs';
import ReactEcharts from 'echarts-for-react';
import groupBy from 'lodash/groupBy';
import { useState } from 'react';
import { VmEmpty, VmFilter, VmTitle } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { alarmService } from "../../api";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var MYSDFZB = function MYSDFZB(_ref) {
  var _ref$classPrefix = _ref.classPrefix,
    classPrefix = _ref$classPrefix === void 0 ? '' : _ref$classPrefix,
    id = _ref.id;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var _useState = useState(dayjs()),
    _useState2 = _slicedToArray(_useState, 2),
    times = _useState2[0],
    setTimes = _useState2[1];
  var mySumByGarbageTypeAndPeriod = alarmService.useMySumByGarbageTypeAndPeriod({
    housingEstateId: id,
    beginTime: times.format('YYYY-MM-DD 00:00:00'),
    endTime: times.format('YYYY-MM-DD 23:59:59')
  });
  function transferData(data) {
    var chartData = [];
    var xAxis = [];
    var dataGroupByDate = groupBy(data, 'garbageTypeName');
    var count = 0;
    // eslint-disable-next-line guard-for-in
    for (var key in dataGroupByDate) {
      dataGroupByDate[key].forEach(function (item, index) {
        var x = "".concat(item.periodBegin, "-").concat(item.periodEnd);
        if (!xAxis.includes(x)) {
          xAxis.push(x);
        }
        chartData.push([index, count, item.count]);
      });
      count++;
    }
    return {
      xAxis: xAxis,
      yAxis: Object.keys(dataGroupByDate),
      chartData: chartData
    };
  }
  var getDistributionChart = function getDistributionChart(data) {
    var _transferData = transferData(data),
      xAxis = _transferData.xAxis,
      yAxis = _transferData.yAxis,
      chartData = _transferData.chartData;
    var max = Math.max.apply(Math, _toConsumableArray(chartData.map(function (item) {
      return item[2];
    })));
    if (!(chartData !== null && chartData !== void 0 && chartData.length)) return {};
    return {
      tooltip: {
        show: false,
        position: 'top',
        formatter: function formatter(params) {
          var value = params.value,
            marker = params.marker,
            name = params.name;
          var garbageType = yAxis[value[1]];
          return "<div>".concat(garbageType, " ").concat(name, "</div><div>").concat(marker, " \u91CD\u91CF\uFF1A").concat(value[2], "kg</div>");
        }
      },
      grid: {
        top: 50,
        bottom: 0,
        right: 0,
        left: 0,
        containLabel: true
      },
      xAxis: {
        type: 'category',
        data: xAxis,
        splitArea: {
          show: true
        },
        axisLabel: {
          color: isDark ? '#fff' : '#000'
        },
        axisTick: {
          show: false
        }
      },
      yAxis: {
        type: 'category',
        data: yAxis,
        splitArea: {
          show: true
        },
        axisLabel: {
          color: isDark ? '#fff' : '#000'
        },
        axisTick: {
          show: false
        }
      },
      visualMap: {
        min: 0,
        max: max,
        calculable: true,
        orient: 'horizontal',
        left: 48,
        top: 0,
        inRange: {
          color: ['rgba(34,154,239,0.5)', '#1CC10D', '#009DFF', '#FF9500', '#F5222D']
        },
        textStyle: {
          color: '#fff'
        }
      },
      series: [{
        name: '满溢时段分布',
        type: 'heatmap',
        data: chartData,
        label: {
          show: true
        },
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }]
    };
  };
  var legend = {
    xs: '少',
    sm: '较少',
    md: '中等',
    lg: '多',
    xxl: '较多'
  };
  return /*#__PURE__*/_jsxs("div", {
    children: [/*#__PURE__*/_jsxs("div", {
      className: "".concat(classPrefix, "-row"),
      children: [/*#__PURE__*/_jsx(VmTitle, {
        title: "\u6EE1\u6EA2\u65F6\u6BB5\u5206\u5E03",
        border: false
      }), /*#__PURE__*/_jsx(VmFilter.VMDatePicker, {
        value: times,
        onChange: function onChange(date) {
          setTimes(date);
        }
      })]
    }), /*#__PURE__*/_jsxs("div", {
      style: {
        height: '300px',
        position: 'relative'
      },
      children: [!(mySumByGarbageTypeAndPeriod !== null && mySumByGarbageTypeAndPeriod !== void 0 && mySumByGarbageTypeAndPeriod.length) ? /*#__PURE__*/_jsx(VmEmpty, {}) : /*#__PURE__*/_jsx(ReactEcharts, {
        option: getDistributionChart(mySumByGarbageTypeAndPeriod || [])
      }), /*#__PURE__*/_jsx("div", {
        className: "".concat(classPrefix, "-legends"),
        children: /*#__PURE__*/_jsx(Space, {
          size: 8,
          children: ['xs', 'sm', 'md', 'lg', 'xxl'].map(function (item) {
            return /*#__PURE__*/_jsx("div", {
              className: "".concat(classPrefix, "-legends-item ").concat(item),
              children: legend[item]
            }, item);
          })
        })
      })]
    })]
  });
};
export default MYSDFZB;