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 { LeftOutlined, RightOutlined } from '@ant-design/icons';
import { useMemoizedFn } from 'ahooks';
import { Row } from 'antd';
import classnames from 'classnames';
import dayjs from 'dayjs';
import { isEmpty } from 'lodash';
import groupBy from 'lodash/groupBy';
import { useContext, useState } from 'react';
import { VmCalendar, VmTag, VmWrapper } from "../../../_components";
import useSettings from "../../../_hooks/useSettings";
import { BasicService } from "../../api";
import { CcCpContext } from "../../index";
import "./index.less";
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
var CalendarContent = function CalendarContent(_ref) {
  var isCollect = _ref.isCollect,
    date = _ref.date,
    collectList = _ref.collectList;
  var _useSettings = useSettings(),
    isDark = _useSettings.isDark;
  var isAfter = dayjs().isAfter(date);
  var _useState = useState(0),
    _useState2 = _slicedToArray(_useState, 2),
    currentIndex = _useState2[0],
    setCurrentIndex = _useState2[1];
  var collectItem = collectList[currentIndex];
  var iconStyle = {
    cursor: 'pointer',
    color: isDark ? '#fff' : '#bfbfbf',
    fontSize: 14
  };
  return /*#__PURE__*/_jsxs(_Fragment, {
    children: [/*#__PURE__*/_jsx("div", {
      className: 'cc_restaurant_calendar-dot',
      children: /*#__PURE__*/_jsx("div", {
        className: classnames('cc_restaurant_calendar_dot', {
          gray: !isCollect
        })
      })
    }), isAfter && collectList.length > 1 ? /*#__PURE__*/_jsxs("div", {
      className: 'cc_restaurant_calendar-index-wrap',
      children: [/*#__PURE__*/_jsx(LeftOutlined, {
        style: iconStyle,
        onClick: function onClick() {
          if (currentIndex !== 0) {
            setCurrentIndex(currentIndex - 1);
          }
        }
      }), /*#__PURE__*/_jsxs("span", {
        children: [currentIndex + 1, "/", collectList.length]
      }), /*#__PURE__*/_jsx(RightOutlined, {
        style: iconStyle,
        onClick: function onClick() {
          if (currentIndex !== collectList.length - 1) {
            setCurrentIndex(currentIndex + 1);
          }
        }
      })]
    }) : null, /*#__PURE__*/_jsxs("div", {
      className: 'cc_restaurant_calendar',
      children: [!isEmpty(collectList) ? /*#__PURE__*/_jsxs("div", {
        className: 'cc_restaurant_calendar-content',
        children: [/*#__PURE__*/_jsxs(Row, {
          align: 'middle',
          justify: 'space-between',
          children: [/*#__PURE__*/_jsx("div", {
            children: collectItem !== null && collectItem !== void 0 && collectItem.weighTime ? dayjs(collectItem.weighTime).format('HH:mm:ss') : '--' || '--'
          }), /*#__PURE__*/_jsx(VmTag, {
            title: '已收集',
            type: 'green'
          })]
        }), /*#__PURE__*/_jsxs("div", {
          className: 'cc_restaurant_calendar-content-value',
          style: {
            height: 14
          },
          children: [collectItem === null || collectItem === void 0 ? void 0 : collectItem.trashNum, "\u6876 / ", collectItem === null || collectItem === void 0 ? void 0 : collectItem.netWeight, "kg"]
        }), /*#__PURE__*/_jsx("div", {
          className: 'cc_restaurant_calendar-content-item',
          children: collectItem === null || collectItem === void 0 ? void 0 : collectItem.carCode
        })]
      }) : null, isEmpty(collectList) && isAfter && isCollect ? /*#__PURE__*/_jsx(VmTag, {
        title: '未收集',
        type: 'yellow',
        style: {
          width: '100%'
        }
      }) : null]
    })]
  });
};
var CollectCalendar = function CollectCalendar() {
  var _useSettings2 = useSettings(),
    isDark = _useSettings2.isDark;
  var _useContext = useContext(CcCpContext),
    id = _useContext.id,
    defaultDate = _useContext.date;
  var _useState3 = useState(defaultDate ? dayjs(defaultDate) : dayjs()),
    _useState4 = _slicedToArray(_useState3, 2),
    date = _useState4[0],
    setDate = _useState4[1];
  var calendarList = BasicService.useGetSyPointMonthDetail(id, dayjs(date).format('YYYY-MM-DD'), dayjs(date).format('YYYY-MM'));
  var collectList = BasicService.useCollectList({
    id: id,
    startTime: dayjs(date).startOf('month').format('YYYY-MM-DD 00:00:00'),
    endTime: dayjs(date).endOf('month').format('YYYY-MM-DD 23:59:59')
  });
  var groupByDate = groupBy(collectList, function (item) {
    return dayjs(item.weighTime).format('YYYY-MM-DD');
  });
  var dateCellRender = useMemoizedFn(function (_date) {
    var dateStr = dayjs(_date).format('YYYY-MM-DD');
    var isCollect = calendarList.includes(dateStr);
    return dayjs(_date).isSame(date, 'month') && /*#__PURE__*/_jsx(CalendarContent, {
      isCollect: isCollect,
      date: dateStr,
      collectList: groupByDate[dateStr] || []
    });
  });
  return /*#__PURE__*/_jsx("div", {
    className: classnames('cc_restaurant_calendar_wrap', {
      dark: isDark
    }),
    children: /*#__PURE__*/_jsxs(VmWrapper, {
      title: '收运日历',
      filterType: "monthPicker",
      dateValue: date,
      filterChange: setDate,
      disabledDate: function disabledDate(current) {
        return current && current > dayjs().endOf('M');
      },
      children: [/*#__PURE__*/_jsxs("div", {
        className: 'cc_restaurant_calendar_title_wrap',
        children: [/*#__PURE__*/_jsxs("div", {
          className: 'cc_restaurant_calendar_title_item blue',
          children: [/*#__PURE__*/_jsx("div", {
            className: 'cc_restaurant_calendar_dot'
          }), /*#__PURE__*/_jsx("span", {
            children: "\u6536\u96C6\u65E5"
          })]
        }), /*#__PURE__*/_jsxs("div", {
          className: 'cc_restaurant_calendar_title_item',
          children: [/*#__PURE__*/_jsx("div", {
            className: 'cc_restaurant_calendar_dot gray'
          }), /*#__PURE__*/_jsx("span", {
            className: 'cc_restaurant_calendar_title_wrap-text',
            children: "\u4E0D\u6536\u96C6\u65E5"
          })]
        })]
      }), /*#__PURE__*/_jsx(VmCalendar, {
        headerRender: function headerRender() {
          return null;
        },
        disabledDate: function disabledDate() {
          return true;
        },
        dateCellRender: dateCellRender,
        value: date
      })]
    })
  });
};
export default CollectCalendar;