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 { Radio } from 'antd';
import dayjs from 'dayjs';
import EChartsReact from 'echarts-for-react';
import { useState } from 'react';
import { VmEmpty, VmTitle } from "../../../_components";
import { alarmService } from "../../api";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var symbols = {
  'PLASTIC-BAG': require("../../imgs/PLASTIC_BAG.png"),
  NAPKIN: require("../../imgs/NAPKIN.png"),
  BOTTLE: require("../../imgs/BOTTLE.png"),
  CAN: require("../../imgs/CAN.png"),
  KRAFT_PAPER_BOX: require("../../imgs/KRAFT_PAPER_BOX.png"),
  DEFAULT: require("../../imgs/garbage_default.png")
};
var HTLJPH = function HTLJPH(_ref) {
  var _ref$classPrefix = _ref.classPrefix,
    classPrefix = _ref$classPrefix === void 0 ? '' : _ref$classPrefix,
    id = _ref.id;
  var _useState = useState('current'),
    _useState2 = _slicedToArray(_useState, 2),
    currentTabKey = _useState2[0],
    setCurrentTabKey = _useState2[1];
  var thisWeek = currentTabKey === 'current';
  var getPictorialBarOption = function getPictorialBarOption(_ref2) {
    var _ref2$title = _ref2.title,
      title = _ref2$title === void 0 ? '本周' : _ref2$title,
      _ref2$data = _ref2.data,
      data = _ref2$data === void 0 ? [] : _ref2$data;
    return {
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      grid: {
        containLabel: true,
        left: 20
      },
      yAxis: {
        data: data.map(function (item) {
          return item.name;
        }),
        inverse: true,
        axisLine: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLabel: {
          margin: 30,
          fontSize: 14
        },
        axisPointer: {
          label: {
            show: true,
            margin: 30
          }
        }
      },
      xAxis: {
        splitLine: {
          show: false
        },
        axisLabel: {
          show: false
        },
        axisTick: {
          show: false
        },
        axisLine: {
          show: false
        }
      },
      animationDurationUpdate: 500,
      series: [{
        name: title,
        id: 'bar1',
        type: 'pictorialBar',
        label: {
          show: true,
          position: 'right',
          offset: [10, 0],
          fontSize: 16,
          color: '#fff'
        },
        symbolRepeat: true,
        symbolSize: ['80%', '60%'],
        barCategoryGap: '40%',
        // universalTransition: {
        //     enabled: true,
        //     delay: function (idx, total) {
        //         return (idx / total) * 1000;
        //     }
        // },
        data: data.map(function (item) {
          return {
            value: item.count,
            symbol: "image://".concat(item.symbol)
          };
        })
      }]
    };
  };
  // 混投垃圾排行
  var mixRank = alarmService.useMixSumRank({
    throwPointId: id,
    beginTime: thisWeek ? dayjs().startOf('days').format('YYYY-MM-DD 00:00:00') : dayjs().subtract(1, 'weeks').startOf('days').format('YYYY-MM-DD 00:00:00'),
    endTime: thisWeek ? dayjs().endOf('weeks').format('YYYY-MM-DD 23:59:59') : dayjs().subtract(1, 'weeks').endOf('weeks').format('YYYY-MM-DD 23:59:59')
  });
  var barData = (mixRank || []).map(function (item) {
    return {
      name: item.garbageTypeName,
      count: thisWeek ? item.thisWeekCount : item.lastWeekCount,
      symbol: symbols[item.garbageTypeCode] || symbols.DEFAULT
    };
  });
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsxs("div", {
      className: "".concat(classPrefix, "-row"),
      children: [/*#__PURE__*/_jsx(VmTitle, {
        title: "\u6DF7\u6295\u5783\u573E\u6392\u884C",
        border: false
      }), /*#__PURE__*/_jsx("div", {
        className: "".concat(classPrefix, "-btns"),
        children: /*#__PURE__*/_jsxs(Radio.Group, {
          value: currentTabKey,
          onChange: function onChange(e) {
            return setCurrentTabKey(e.target.value);
          },
          children: [/*#__PURE__*/_jsx(Radio.Button, {
            value: "current",
            children: "\u672C\u5468"
          }), /*#__PURE__*/_jsx(Radio.Button, {
            value: "last",
            children: "\u4E0A\u5468"
          })]
        })
      })]
    }), /*#__PURE__*/_jsx("div", {
      className: "".concat(classPrefix, "-overflow-rank"),
      children: !(barData !== null && barData !== void 0 && barData.length) ? /*#__PURE__*/_jsx(VmEmpty, {
        type: "NO_CHART"
      }) : /*#__PURE__*/_jsx(EChartsReact, {
        option: getPictorialBarOption({
          title: thisWeek ? '本周' : '上周',
          data: barData
        })
      })
    })]
  });
};
export default HTLJPH;