import { Calendar } from "antd";
import dayjs from "dayjs";
import React, { useMemo } from "react";
import { formatBackgroundColors } from "../products/utils";
var CalendarItem = function CalendarItem(props) {
  var month = props.month,
    schedulesData = props.schedulesData,
    selectDate = props.selectDate,
    onSelect = props.onSelect,
    isEdit = props.isEdit;
  var scheduleMap = useMemo(function () {
    return new Map(schedulesData.map(function (schedule) {
      return [schedule.date, schedule];
    }));
  }, [schedulesData]);
  var startDate = dayjs(month).startOf("month").format("YYYY-MM-DD");
  var endDate = dayjs(month).endOf("month").format("YYYY-MM-DD");
  return /*#__PURE__*/React.createElement("div", {
    className: "month-item"
  }, /*#__PURE__*/React.createElement("div", {
    className: "caleddar-month"
  }, dayjs(month).format("MMMM")), /*#__PURE__*/React.createElement(Calendar, {
    headerRender: function headerRender() {
      return null;
    },
    fullscreen: false,
    value: dayjs(month),
    disabledDate: function disabledDate(currentDate) {
      return currentDate.isAfter(endDate) || currentDate.isBefore(startDate);
    }
    // validRange={[
    // 	dayjs(month).startOf("month"),
    // 	dayjs(month).endOf("month"),
    // ]}
    ,
    fullCellRender: function fullCellRender(e) {
      var currentDayText = e.format("YYYY-MM-DD");
      var currentDayData = scheduleMap.get(currentDayText);
      // 是否当前月份
      var isCurrentMonth = e.format("YYYY-MM") === month;
      // 是否选中日期
      var isSelectDate = currentDayText === selectDate;
      var isExcluded = currentDayData === null || currentDayData === void 0 ? void 0 : currentDayData.isExcluded;
      var style = {};
      var colors = !isEdit ? ["#7D89B0"] : (currentDayData === null || currentDayData === void 0 ? void 0 : currentDayData.color) || [];
      style = {
        background: formatBackgroundColors(colors)
      };
      if (e.isAfter(endDate) || e.isBefore(startDate)) {
        return e.date();
      }
      return /*#__PURE__*/React.createElement("div", {
        className: "caleddar-date-cell ".concat(isSelectDate ? "select" : "", " ").concat(isExcluded ? "excluded" : ""),
        onClick: function onClick() {
          return onSelect(currentDayText, scheduleMap.get(currentDayText));
        }
      }, /*#__PURE__*/React.createElement("div", {
        className: "caleddar-date ".concat(colors.filter(Boolean).length ? "has-status" : "", " ").concat(isCurrentMonth ? "" : "disabled-date"),
        style: style
      }, e.date()));
    }
  }));
};
export default CalendarItem;