"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _vmCard = _interopRequireDefault(require("../../../vm-card"));
var _antd = require("antd");
var _index = require("../../index");
var _vmFilter = require("../../../vm-filter");
var _moment = _interopRequireDefault(require("moment"));
require("moment/locale/zh-cn");
var _zh_CN = _interopRequireDefault(require("antd/lib/calendar/locale/zh_CN.js"));
require("./index.less");
var _icons = require("@ant-design/icons");
var _useSettings2 = _interopRequireDefault(require("../../../vm-hooks/useSettings"));
var _api = require("../../api");
var _groupBy = _interopRequireDefault(require("lodash/groupBy"));
var _lodash = require("lodash");
var _ahooks = require("ahooks");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
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(r) { if (Array.isArray(r)) return r; }
var CalendarContent = function CalendarContent(_ref) {
  var isCollect = _ref.isCollect,
    date = _ref.date,
    collectList = _ref.collectList;
  var _useSettings = (0, _useSettings2["default"])(),
    isDark = _useSettings.isDark;
  var isAfter = (0, _moment["default"])().isAfter(date);
  var _useState = (0, _react.useState)(0),
    _useState2 = _slicedToArray(_useState, 2),
    currentIndex = _useState2[0],
    setCurrentIndex = _useState2[1];
  var collectItem = collectList[currentIndex];
  var infoList = [{
    label: '桶数',
    value: (collectItem === null || collectItem === void 0 ? void 0 : collectItem.trashNum) || '--'
  }, {
    label: '垃圾净重(kg)',
    value: (collectItem === null || collectItem === void 0 ? void 0 : collectItem.netWeight) || '--'
  }, {
    label: '时间',
    value: (collectItem === null || collectItem === void 0 ? void 0 : collectItem.weighTime) ? (0, _moment["default"])(collectItem.weighTime).format('HH:mm:ss') : '--' || '--'
  }, {
    label: '收运车辆',
    value: (collectItem === null || collectItem === void 0 ? void 0 : collectItem.carCode) || '--'
  }];
  var iconStyle = {
    cursor: 'pointer',
    color: isDark ? '#fff' : '#bfbfbf',
    fontSize: 14
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: 'cc_restaurant_calendar'
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: 'cc_restaurant_calendar-dot'
  }, /*#__PURE__*/_react["default"].createElement(_antd.Badge, {
    color: isCollect ? '#1677FF' : '#BFBFBF'
  })), isAfter && collectList.length > 1 ? (/*#__PURE__*/_react["default"].createElement("div", {
    className: 'cc_restaurant_calendar-index-wrap'
  }, /*#__PURE__*/_react["default"].createElement(_icons.LeftOutlined, {
    style: iconStyle,
    onClick: function onClick() {
      if (currentIndex !== 0) {
        setCurrentIndex(currentIndex - 1);
      }
    }
  }), /*#__PURE__*/_react["default"].createElement("span", null, currentIndex + 1, "/", collectList.length), /*#__PURE__*/_react["default"].createElement(_icons.RightOutlined, {
    style: iconStyle,
    onClick: function onClick() {
      if (currentIndex !== collectList.length - 1) {
        setCurrentIndex(currentIndex + 1);
      }
    }
  }))) : null, !(0, _lodash.isEmpty)(collectList) ? (/*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
    className: 'cc_restaurant_calendar-status-wrap'
  }, /*#__PURE__*/_react["default"].createElement(_antd.Badge, {
    color: '#52C41A'
  }), /*#__PURE__*/_react["default"].createElement("span", null, "\u5DF2\u6536\u96C6")), /*#__PURE__*/_react["default"].createElement("div", {
    className: 'cc_restaurant_calendar-content-wrap'
  }, infoList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: item.label,
      className: 'cc_restaurant_calendar-content-item'
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: 'cc_restaurant_calendar-label'
    }, item.label), /*#__PURE__*/_react["default"].createElement("div", null, item.value));
  })))) : null, (0, _lodash.isEmpty)(collectList) && isAfter && isCollect ? (/*#__PURE__*/_react["default"].createElement("div", {
    className: 'cc_restaurant_calendar-status-wrap cc_restaurant_calendar-status-wrap-error'
  }, /*#__PURE__*/_react["default"].createElement(_antd.Badge, {
    color: '#F5222D'
  }), /*#__PURE__*/_react["default"].createElement("span", null, "\u672A\u6536\u96C6"))) : null));
};
var CollectCalendar = function CollectCalendar() {
  var _useContext = (0, _react.useContext)(_index.CcCpContext),
    id = _useContext.id;
  var _useState3 = (0, _react.useState)((0, _moment["default"])()),
    _useState4 = _slicedToArray(_useState3, 2),
    date = _useState4[0],
    setDate = _useState4[1];
  var calendarList = _api.BasicService.getSyPointMonthDetail(id, (0, _moment["default"])(date).format('YYYY-MM-DD'), (0, _moment["default"])(date).format('YYYY-MM'));
  var collectList = _api.BasicService.collectList({
    id: id,
    startTime: (0, _moment["default"])(date).startOf('month').format('YYYY-MM-DD 00:00:00'),
    endTime: (0, _moment["default"])(date).endOf('month').format('YYYY-MM-DD 23:59:59')
  });
  var groupByDate = (0, _groupBy["default"])(collectList, function (item) {
    return (0, _moment["default"])(item.weighTime).format('YYYY-MM-DD');
  });
  var dateCellRender = (0, _ahooks.useMemoizedFn)(function (_date) {
    var dateStr = (0, _moment["default"])(_date).format('YYYY-MM-DD');
    var isCollect = calendarList.includes(dateStr);
    return (0, _moment["default"])(_date).isSame(date, 'month') && (/*#__PURE__*/_react["default"].createElement(CalendarContent, {
      isCollect: isCollect,
      date: dateStr,
      collectList: groupByDate[dateStr] || []
    }));
  });
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: "cc_restaurant_calendar_wrap"
  }, /*#__PURE__*/_react["default"].createElement(_vmCard["default"], {
    title: /*#__PURE__*/_react["default"].createElement("div", {
      className: 'cc_restaurant_calendar_title_wrap'
    }, /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_antd.Badge, {
      color: '#1677FF'
    }), /*#__PURE__*/_react["default"].createElement("span", {
      className: 'cc_restaurant_calendar_title_wrap-text'
    }, "\u6536\u96C6\u65E5")), /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_antd.Badge, {
      color: '#BFBFBF'
    }), /*#__PURE__*/_react["default"].createElement("span", {
      className: 'cc_restaurant_calendar_title_wrap-text'
    }, "\u4E0D\u6536\u96C6\u65E5"))),
    rightContent: /*#__PURE__*/_react["default"].createElement(_vmFilter.VMDatePicker, {
      picker: "month",
      value: date,
      onChange: function onChange(date) {
        return setDate(date);
      }
    })
  }, /*#__PURE__*/_react["default"].createElement(_antd.Calendar, {
    locale: _zh_CN["default"],
    headerRender: function headerRender() {
      return null;
    },
    disabledDate: function disabledDate() {
      return true;
    },
    dateCellRender: dateCellRender,
    value: date
  })));
};
var _default = exports["default"] = CollectCalendar;
//# sourceMappingURL=index.js.map
