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 dayjs from 'dayjs';
import { VmEmpty, VmFactor, VmFilter, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { TfdService } from "../../api";
import { getImg } from "../ThrowRecord";
import { Spin } from 'antd';
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
var TfdRecord = function TfdRecord(props) {
  var id = props.id;
  var _useSettings = useSettings(),
    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 _TfdService$useSummar = TfdService.useSummaryInfo(id, formatType[dateType], date.startOf(formatType[dateType]).format('YYYY-MM-DD 00:00:00'), date.endOf(formatType[dateType]).format('YYYY-MM-DD 23:59:59')),
    data = _TfdService$useSummar.data,
    loading = _TfdService$useSummar.loading;
  return /*#__PURE__*/_jsx("div", {
    className: "shxq-tfd ".concat(isDark ? 'dark' : ''),
    children: /*#__PURE__*/_jsxs(VmWrapper, {
      title: "\u6295\u653E\u70B9\u7EDF\u8BA1(".concat((data === null || data === void 0 ? void 0 : data.length) || 0, ")"),
      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(Spin, {
        spinning: loading
      }), data === null || data === void 0 ? void 0 : data.map(function (item, index) {
        var _JSON$parse$, _item$pointThrowPerio, _item$garbageList;
        return /*#__PURE__*/_jsxs("div", {
          className: "shxq-tfd-row",
          children: [/*#__PURE__*/_jsx("div", {
            className: "shxq-tfd-row-left",
            children: item.photo ? /*#__PURE__*/_jsx("img", {
              src: "".concat(process.env.PREFIX || '', "/cloudFile/common/downloadFile?id=").concat((_JSON$parse$ = JSON.parse(item.photo)[0]) === null || _JSON$parse$ === void 0 ? void 0 : _JSON$parse$.id),
              alt: ""
            }) : /*#__PURE__*/_jsx(VmEmpty, {
              type: "NO_PICTURE"
            })
          }), /*#__PURE__*/_jsxs("div", {
            className: "shxq-tfd-row-right",
            children: [/*#__PURE__*/_jsx("div", {
              className: "shxq-tfd-row-title",
              children: item.pointName
            }), /*#__PURE__*/_jsxs("div", {
              className: "shxq-tfd-row-right-row",
              children: [/*#__PURE__*/_jsxs("div", {
                children: [/*#__PURE__*/_jsx("span", {
                  className: "shxq-tfd-row-label",
                  children: "\u7C7B\u578B\uFF1A"
                }), item.pointTypeDesc]
              }), /*#__PURE__*/_jsx("div", {
                className: "shxq-tfd-line"
              }), /*#__PURE__*/_jsxs("div", {
                children: [/*#__PURE__*/_jsx("span", {
                  className: "shxq-tfd-row-label",
                  children: "\u6295\u653E\u65F6\u6BB5\uFF1A"
                }), (_item$pointThrowPerio = item.pointThrowPeriods) === null || _item$pointThrowPerio === void 0 || (_item$pointThrowPerio = _item$pointThrowPerio.map(function (ele) {
                  return "".concat(ele.startTime, "~").concat(ele.endTime);
                })) === null || _item$pointThrowPerio === void 0 ? void 0 : _item$pointThrowPerio.join('、')]
              })]
            }), /*#__PURE__*/_jsx("div", {
              className: "shxq-tfd-factors",
              children: (_item$garbageList = item.garbageList) === null || _item$garbageList === void 0 ? void 0 : _item$garbageList.map(function (ele) {
                var img = getImg(ele.garbageTypeCode);
                return /*#__PURE__*/_jsx(VmFactor, {
                  img: img,
                  name: ele.garbageTypeName,
                  fontType: ele.garbageCanColor,
                  unit: item.unit,
                  style: {
                    width: '24%'
                  }
                }, ele.id);
              })
            })]
          })]
        }, index);
      })]
    })
  });
};
export default TfdRecord;