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 { useSetState } from 'ahooks';
import { Col, Row } from 'antd';
import dayjs from 'dayjs';
import { sumBy } from 'lodash';
import { VmFactor, VmFilter, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { ThrowService } from "../../api";
import tfCy from "../../imgs/tf_cy_dark.png";
import tfKhs from "../../imgs/tf_khs_dark.png";
import tfQt from "../../imgs/tf_qt_dark.png";
import tfTotal from "../../imgs/tf_total.png";
import tfTotalDark from "../../imgs/tf_total_dark.png";
import tfYh from "../../imgs/tf_yh_dark.png";
import List from "./List";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var ThrowRecord = function ThrowRecord(props) {
  var _data$;
  var id = props.id,
    _props$source = props.source,
    source = _props$source === void 0 ? '' : _props$source;
  var _useSettings = useSettings(),
    theme = _useSettings.theme,
    isDark = _useSettings.isDark;
  var _useSetState = useSetState({
      dateType: 'datePicker',
      date: dayjs()
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  var dateType = state.dateType,
    date = state.date;
  var formatType = {
    datePicker: 'day',
    monthPicker: 'month',
    yearPicker: 'year'
  };
  var _ThrowService$useSumm = ThrowService.useSummaryInfo(id, date.startOf(formatType[dateType]).format('YYYY-MM-DD 00:00:00'), date.endOf(formatType[dateType]).format('YYYY-MM-DD 23:59:59'), source),
    data = _ThrowService$useSumm.data;
  return /*#__PURE__*/_jsx("div", {
    className: "shxq-thr ".concat(theme),
    children: /*#__PURE__*/_jsxs(Row, {
      gutter: [16, 16],
      children: [/*#__PURE__*/_jsx(Col, {
        span: 24,
        children: /*#__PURE__*/_jsx(VmWrapper, {
          title: "\u6295\u653E\u6C47\u603B",
          filterType: dateType,
          filterChange: function filterChange(date) {
            setState({
              date: date
            });
          },
          dateValue: date,
          extra: /*#__PURE__*/_jsx("div", {
            style: {
              position: 'absolute',
              right: 188,
              top: 0,
              borderRadius: 10,
              background: 'rgba(12,154,255,0.99)'
            },
            children: /*#__PURE__*/_jsx(VmFilter.VMSelect, {
              value: dateType,
              options: [{
                label: '日',
                value: 'datePicker'
              }, {
                label: '月',
                value: 'monthPicker'
              }, {
                label: '年',
                value: 'yearPicker'
              }],
              onChange: function onChange(key) {
                setState({
                  dateType: key
                });
              }
            })
          }),
          children: /*#__PURE__*/_jsx("div", {
            className: "shxq-thr-factors",
            children: [{
              garbageTypeName: '投放总量',
              img: isDark ? tfTotalDark : tfTotal,
              value: sumBy(data, 'value'),
              garbageCanColor: 'blue',
              statisticType: data === null || data === void 0 || (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$.statisticType
            }].concat(_toConsumableArray(data === null || data === void 0 ? void 0 : data.filter(function (ele, index) {
              return index < 4;
            }))).map(function (item, index) {
              var img = item.img;
              if (!img) {
                img = getImg(item.garbageTypeCode);
              }
              var unit = dateType !== 'datePicker' && item.statisticType === 'THROW_WEIGHT' ? '吨' : UNIT[item.statisticType];
              return /*#__PURE__*/_jsx(VmFactor, {
                img: img,
                value: item.value,
                name: item.garbageTypeName,
                unit: unit,
                fontType: item.garbageCanColor,
                unitStyle: {
                  fontSize: '14px'
                }
              }, index);
            })
          })
        })
      }), /*#__PURE__*/_jsx(Col, {
        span: 24,
        children: /*#__PURE__*/_jsx(VmWrapper, {
          title: "\u6295\u653E\u660E\u7EC6",
          style: {
            height: 460
          },
          children: /*#__PURE__*/_jsx(List, {
            id: id,
            startTime: date.startOf(formatType[dateType]).format('YYYY-MM-DD 00:00:00'),
            endTime: date.endOf(formatType[dateType]).format('YYYY-MM-DD 23:59:59'),
            source: source
          })
        })
      })]
    })
  });
};
export default ThrowRecord;
export var UNIT = {
  THROW_TIMES: '次',
  THROW_BAGS: '袋',
  THROW_WEIGHT: 'kg'
};
export var getImg = function getImg(code) {
  switch (code === null || code === void 0 ? void 0 : code.toUpperCase()) {
    case 'CHUYU':
      return tfCy;
    case 'KHSW':
      return tfKhs;
    case 'YOUHAI':
      return tfYh;
    case 'QITA':
      return tfQt;
  }
};
export var getColor = function getColor(name) {
  if (name.indexOf('厨余') > -1) {
    return 'green';
  } else if (name.indexOf('可回收') > -1) {
    return 'blue';
  } else if (name.indexOf('有害') > -1) {
    return 'red';
  } else if (name.indexOf('其他') > -1) {
    return 'gray';
  }
};