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/venueBooking/components/VenueSelection/components/MonthPicker.tsx
var MonthPicker_exports = {};
__export(MonthPicker_exports, {
  default: () => MonthPicker
});
module.exports = __toCommonJS(MonthPicker_exports);
var import_react = __toESM(require("react"));
var import_dayjs = __toESM(require("dayjs"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_context = require("../../../context");
var import_utils2 = require("../../../utils");
function MonthPicker() {
  const {
    monthCursor,
    setMonthCursor,
    anchorDate,
    setAnchorDate,
    setMonthPickerOpen,
    fetchWeekData,
    viewModel
  } = (0, import_context.useVenueBookingContext)();
  const days = (0, import_utils2.getMonthDays)(monthCursor);
  const selectedKey = (0, import_utils2.formatDateKey)(anchorDate);
  const todayKey = (0, import_utils2.formatDateKey)((0, import_dayjs.default)());
  const todayStart = (0, import_dayjs.default)().startOf("day");
  const knownDateRange = (0, import_react.useMemo)(() => {
    const knownDates = (viewModel.dateSummary || []).map((item) => (0, import_dayjs.default)(String((item == null ? void 0 : item.date) || ""))).filter((date) => date.isValid()).sort((a, b) => a.valueOf() - b.valueOf());
    if (!knownDates.length) return null;
    return {
      minDate: knownDates[0].startOf("day"),
      maxDate: knownDates[knownDates.length - 1].startOf("day")
    };
  }, [viewModel.dateSummary]);
  async function handleSelect(day) {
    setAnchorDate(day);
    setMonthCursor(day.startOf("month"));
    setMonthPickerOpen(false);
    const weekDays = (0, import_utils2.getWeekDays)(day);
    await fetchWeekData((0, import_utils2.formatDateKey)(weekDays[0]), (0, import_utils2.formatDateKey)(weekDays[weekDays.length - 1]));
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "absolute right-0 top-[calc(100%+12px)] z-30 w-[320px] rounded-[24px] border border-black/6 bg-white p-4 shadow-[0_20px_60px_rgba(20,20,20,0.14)]" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "mb-4 flex items-center justify-between" }, /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: "flex h-10 w-10 items-center justify-center rounded-2xl bg-[#fafafa] ring-1 ring-black/8 hover:bg-zinc-50",
      onClick: () => setMonthCursor(monthCursor.subtract(1, "month"))
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-left", style: { fontSize: 16 } })
  ), /* @__PURE__ */ import_react.default.createElement("div", { className: "text-sm font-bold text-zinc-900" }, (0, import_utils2.getMonthLabel)(monthCursor)), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      className: "flex h-10 w-10 items-center justify-center rounded-2xl bg-[#fafafa] ring-1 ring-black/8 hover:bg-zinc-50",
      onClick: () => setMonthCursor(monthCursor.add(1, "month"))
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-right", style: { fontSize: 16 } })
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "mb-2 grid grid-cols-7 gap-2 px-1 text-center text-[11px] font-bold uppercase tracking-wide text-zinc-400" }, [
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.mon") || "周一",
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.tue") || "周二",
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.wed") || "周三",
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.thu") || "周四",
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.fri") || "周五",
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.sat") || "周六",
    import_utils.locales.getText("pisell2.venue.calendar.weekday.short.sun") || "周日"
  ].map((d) => /* @__PURE__ */ import_react.default.createElement("div", { key: d }, d))), /* @__PURE__ */ import_react.default.createElement("div", { className: "grid grid-cols-7 gap-2" }, days.map((day, index) => {
    if (!day) return /* @__PURE__ */ import_react.default.createElement("div", { key: `empty-${index}`, className: "h-11" });
    const key = (0, import_utils2.formatDateKey)(day);
    const meta = (0, import_utils2.getDateMetaFromSummary)(day, viewModel.dateSummary);
    const selected = key === selectedKey;
    const isToday = key === todayKey;
    const isPastDate = day.isBefore(todayStart, "day");
    const isUnknownDate = !knownDateRange ? true : day.isBefore(knownDateRange.minDate, "day") || day.isAfter(knownDateRange.maxDate, "day");
    const isDisabledBySummary = !isUnknownDate && meta.soldOut;
    const isDisabled = isPastDate || isDisabledBySummary;
    const cellClass = isDisabled ? "bg-zinc-50 text-zinc-400 ring-1 ring-zinc-200" : selected ? "text-white shadow-sm" : isToday ? "" : "bg-[#fafafa] text-zinc-700 ring-1 ring-black/6";
    const cellStyle = selected && !meta.soldOut ? { backgroundColor: "var(--vb-primary)" } : isToday && !meta.soldOut ? { backgroundColor: "var(--vb-primary-light)", color: "var(--vb-primary)" } : void 0;
    return /* @__PURE__ */ import_react.default.createElement(
      "button",
      {
        key,
        onClick: () => {
          if (isDisabled) return;
          void handleSelect(day);
        },
        disabled: isDisabled,
        className: `h-11 rounded-2xl text-sm font-semibold transition ${cellClass}`,
        style: cellStyle
      },
      /* @__PURE__ */ import_react.default.createElement("span", { className: isDisabledBySummary ? "line-through text-zinc-400" : "" }, day.date())
    );
  })));
}
