var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/eventBooking/components/scheduleCalendar/calendarItem.tsx
var calendarItem_exports = {};
__export(calendarItem_exports, {
  default: () => calendarItem_default
});
module.exports = __toCommonJS(calendarItem_exports);
var import_antd = require("antd");
var import_dayjs = __toESM(require("dayjs"));
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("../../utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_zh_CN = __toESM(require("antd/es/date-picker/locale/zh_CN"));
var import_en_US = __toESM(require("antd/es/date-picker/locale/en_US"));
var import_ScheduleTimes = __toESM(require("./components/ScheduleTimes"));
var CalendarItem = (props) => {
  var _a, _b;
  const { month, schedulesData, selectDate, onSelect, isEdit, onChange, type } = props;
  const context = (0, import_useEngineContext.default)();
  const utils = context.appHelper.utils || {};
  const locale = ((_b = (_a = utils == null ? void 0 : utils.storage) == null ? void 0 : _a.get("umi_locale")) == null ? void 0 : _b.includes("zh")) ? import_zh_CN.default : import_en_US.default;
  const scheduleMap = (0, import_react.useMemo)(
    () => new Map(
      schedulesData.map((schedule) => [schedule.date, schedule])
    ),
    [schedulesData]
  );
  const handleMonth = (type2) => {
    const date = /* @__PURE__ */ new Date(month + "-01");
    if (type2 === "prev") {
      date.setMonth(date.getMonth() - 1);
    } else {
      date.setMonth(date.getMonth() + 1);
    }
    onChange(date.toISOString().slice(0, 7), type2);
  };
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "month-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "calendar-month" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      onClick: () => handleMonth("prev"),
      className: "calendar-month-icon"
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-left" })
  ), /* @__PURE__ */ import_react.default.createElement("span", { className: "calendar-month-title" }, (0, import_utils.formatMonthDisplay)(month)), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      onClick: () => handleMonth("next"),
      className: "calendar-month-icon"
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-right" })
  )), type === "textList" ? /* @__PURE__ */ import_react.default.createElement(import_ScheduleTimes.default, { month, schedulesData }) : /* @__PURE__ */ import_react.default.createElement(
    import_antd.Calendar,
    {
      locale,
      headerRender: () => null,
      fullscreen: false,
      value: (0, import_dayjs.default)(month),
      disabledDate: (currentDate) => {
        return !schedulesData.some((item) => currentDate.isSame(item.date)) || currentDate.format("YYYY-MM") !== month;
      },
      fullCellRender: (e) => {
        const isDisabled = !schedulesData.some((item) => e.isSame(item.date)) || e.format("YYYY-MM") !== month;
        const currentDayText = e.format("YYYY-MM-DD");
        const currentDayData = scheduleMap.get(currentDayText);
        const isCurrentMonth = e.format("YYYY-MM") === month;
        const isSelectDate = currentDayText === selectDate;
        const isExcluded = currentDayData == null ? void 0 : currentDayData.isExcluded;
        let style = {
          // 如果是当前月份，无论是否禁用都添加红色文字颜色
          color: isCurrentMonth ? "#101828" : "inherit"
        };
        const colors = !isEdit ? ["#7F56D9"] : (currentDayData == null ? void 0 : currentDayData.color) || [];
        if (isDisabled) {
          return /* @__PURE__ */ import_react.default.createElement("div", { style }, e.date());
        }
        style = {
          background: (0, import_utils.formatBackgroundColors)(colors)
        };
        return /* @__PURE__ */ import_react.default.createElement(
          "div",
          {
            className: `caleddar-date-cell ${isSelectDate ? "select" : ""} ${isExcluded ? "excluded" : ""}`,
            onClick: () => onSelect(currentDayText, scheduleMap.get(currentDayText)),
            style: {
              position: "absolute",
              left: "50%",
              top: "50%",
              transform: "translate(-50%, -50%)",
              // 使用 transform 进行居中
              display: "flex",
              alignItems: "center",
              justifyContent: "center"
            }
          },
          /* @__PURE__ */ import_react.default.createElement(
            "div",
            {
              className: `caleddar-date ${colors.filter(Boolean).length ? "has-status" : ""} ${isCurrentMonth ? "" : "disabled-date"}`,
              style
            },
            e.date()
          )
        );
      }
    }
  ));
};
var calendarItem_default = CalendarItem;
