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/bookingAvailabilityCalendar/components/CalendarDate/index.tsx
var CalendarDate_exports = {};
__export(CalendarDate_exports, {
  default: () => CalendarDate_default
});
module.exports = __toCommonJS(CalendarDate_exports);
var import_react = require("react");
var import_dayjs = __toESM(require("dayjs"));
var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_state = require("./state");
var import_classnames = __toESM(require("classnames"));
var import_Status = __toESM(require("./Status"));
var import_index = require("./index.less");
import_dayjs.default.extend(import_isSameOrBefore.default);
var CalendarDate = (props, ref) => {
  const { cutTime, getLimitData, dateLimitData, loading } = props;
  const [productId, setProductId] = (0, import_react.useState)("");
  const [currentDate, setCurrentDate] = (0, import_react.useState)("");
  const [dateMonthList, setDateMonthList] = (0, import_react.useState)([]);
  const [currentMonth, setCurrentMonth] = (0, import_react.useState)(() => {
    return (0, import_dayjs.default)();
  });
  const [open, setOpen] = (0, import_react.useState)(false);
  const startingColumn = 0 % 7;
  const columns = Array.from(
    { length: 7 },
    (_, index) => (index + 7 - startingColumn) % 7
  );
  const calendarDays = (days, list) => {
    let index = list == null ? void 0 : list.find((i) => (i == null ? void 0 : i.day) == days);
    if (!index) {
      return 0;
    } else {
      return index == null ? void 0 : index.status;
    }
  };
  const getMonthData = (date) => {
    const firstDay = (0, import_dayjs.default)(`${date}-01`);
    const startDay = firstDay.day();
    const daysInMonth = firstDay.daysInMonth();
    const monthData = [];
    for (let i = 0; i < startDay; i++) {
      monthData.push({
        day: -1,
        // 表示前一个月的日期
        date: (0, import_dayjs.default)(firstDay).subtract(startDay - i, "day").toDate()
      });
    }
    for (let i = 1; i <= daysInMonth; i++) {
      monthData.push({
        day: i,
        date: firstDay.date(i).format("YYYY-MM-DD")
      });
    }
    return monthData;
  };
  const lastMonthDisable = () => {
    let newCurrentMonth = currentMonth.format("YYYY-MM");
    let lastDate = (0, import_dayjs.default)(newCurrentMonth).subtract(1, "month");
    return lastDate.isBefore((0, import_dayjs.default)(), "month");
  };
  const lastMonth = () => {
    let currentLastText = currentMonth.format("YYYY-MM");
    let newLastMonth = (0, import_dayjs.default)(currentLastText).subtract(1, "month");
    setCurrentMonth(newLastMonth);
    setDateMonthList(getMonthData(newLastMonth.format("YYYY-MM")));
  };
  const nextMonth = () => {
    let currentMonthText = currentMonth.format("YYYY-MM");
    let newNextMonth = (0, import_dayjs.default)(currentMonthText).add(1, "month");
    setCurrentMonth(newNextMonth);
    setDateMonthList(getMonthData(newNextMonth.format("YYYY-MM")));
  };
  const CalendarDateContent = (0, import_react.useMemo)(() => {
    return /* @__PURE__ */ React.createElement("div", { className: "calendar-box" }, /* @__PURE__ */ React.createElement("div", { className: "calendar-header" }, /* @__PURE__ */ React.createElement(
      "div",
      {
        className: (0, import_classnames.default)("calendar-last-month", {
          "last-month-disabled": lastMonthDisable()
        }),
        onClick: () => {
          if (lastMonthDisable()) return;
          lastMonth();
        }
      },
      /* @__PURE__ */ React.createElement(import_materials.Iconfont, { type: "pisell2-chevron-left" })
    ), /* @__PURE__ */ React.createElement("div", { className: "calendar-current-month" }, currentMonth.format("MMMM YYYY")), /* @__PURE__ */ React.createElement(
      "div",
      {
        className: "calendar-next-month",
        onClick: () => {
          nextMonth();
        }
      },
      /* @__PURE__ */ React.createElement(import_materials.Iconfont, { type: "pisell2-chevron-right" })
    )), /* @__PURE__ */ React.createElement("div", { className: "calendar-content" }, /* @__PURE__ */ React.createElement("div", { className: "calendar-weeks" }, columns.map((col) => /* @__PURE__ */ React.createElement("div", { key: col, className: "calendar-weeks-items" }, import_state.weekListText[Number(col)]))), /* @__PURE__ */ React.createElement("div", { className: "calendar-days" }, dateMonthList.map((day, index) => {
      const date = (0, import_dayjs.default)(day.date).format("YYYY-MM-DD");
      const { status, disabled } = (0, import_state.getStatus)(
        dateLimitData,
        date,
        cutTime
      );
      const isShowCallToBook = (0, import_state.getCallToBookStatus)(
        date,
        dateLimitData,
        cutTime
      );
      const currentStatus = isShowCallToBook && (status === "lots_of_space" || status === "filling_up_fast") ? "call_to_book" : status;
      return /* @__PURE__ */ React.createElement(
        "div",
        {
          key: index,
          className: (0, import_classnames.default)("calendar-days-items", {
            disabledDate: disabled || loading,
            disabledSelect: status === "sold_out",
            selectDate: currentDate === date,
            "other-month-days": (day == null ? void 0 : day.day) < 1
          }),
          onClick: () => {
            if (loading) return;
            props.dateChange(date);
          }
        },
        (day == null ? void 0 : day.day) >= 1 && /* @__PURE__ */ React.createElement(
          "div",
          {
            style: {
              "--lineColor": !loading ? import_state.statusColor[currentStatus] : ""
            },
            className: (0, import_classnames.default)("day-text", {
              "day-line": !disabled
            })
          },
          (day == null ? void 0 : day.day) < 1 ? "" : day == null ? void 0 : day.day
        )
      );
    }))), /* @__PURE__ */ React.createElement(import_Status.default, { style: { margin: 0 } }));
  }, [currentMonth, dateMonthList, getLimitData, currentDate]);
  (0, import_react.useImperativeHandle)(ref, () => {
    return {
      open: (date, id) => {
        setOpen(true);
        let daysText = (0, import_dayjs.default)(date).format("YYYY-MM");
        setCurrentMonth((0, import_dayjs.default)(date));
        setCurrentDate(date);
        setDateMonthList(getMonthData(daysText));
      }
    };
  });
  return /* @__PURE__ */ React.createElement(
    import_materials.PisellModal,
    {
      open,
      title: "device",
      mobileModalHeight: "auto",
      platform: (0, import_utils.isMobile)() ? "h5" : "pc",
      bodyStyle: { padding: (0, import_utils.isMobile)() ? "16px 24px" : 32 },
      destroyOnClose: true,
      className: "select-holder-modal",
      footer: null,
      onCancel: () => setOpen(false)
    },
    CalendarDateContent
  );
};
var CalendarDate_default = (0, import_react.forwardRef)(CalendarDate);
