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/CalenDateWeek/index.tsx
var CalenDateWeek_exports = {};
__export(CalenDateWeek_exports, {
  default: () => CalenDateWeek_default
});
module.exports = __toCommonJS(CalenDateWeek_exports);
var import_react = require("react");
var import_dayjs = __toESM(require("dayjs"));
var import_materials = require("@pisell/materials");
var import_classnames = __toESM(require("classnames"));
var import_WeekItem = __toESM(require("./WeekItem/index"));
var import_state = require("../state");
var import_CallToBook = __toESM(require("./CallToBook"));
var import_index = require("./index.less");
var CalenDateWeek = (props) => {
  const {
    currentDate,
    dateChange,
    productId,
    timeList,
    dateLimitData,
    getLimitData,
    cutTime
  } = props;
  const [weekList, setWeekList] = (0, import_react.useState)([]);
  const [showCallToBook, setShowCallToBook] = (0, import_react.useState)(false);
  const weekListRef = (0, import_react.useRef)(null);
  const [selectStatus, setSelectStatus] = (0, import_react.useState)("");
  const [selectDisabled, setSelectDisabled] = (0, import_react.useState)(false);
  const initCurrentWeekData = (dateText) => {
    let currentMoment = (0, import_dayjs.default)(dateText);
    let startOfWeek = currentMoment.startOf("week");
    if (startOfWeek.day() !== 0) {
      startOfWeek.subtract(startOfWeek.day(), "days");
    }
    let weekDates = [];
    for (let i = 0; i < 7; i++) {
      let date = startOfWeek.clone().add(i, "days");
      weekDates.push(date.format("YYYY-MM-DD"));
    }
    return weekDates;
  };
  const initWeekData = () => {
    const list = initCurrentWeekData(currentDate);
    setWeekList(list);
  };
  const init = () => {
    initWeekData();
  };
  (0, import_react.useEffect)(() => {
    init();
  }, [currentDate]);
  (0, import_react.useEffect)(() => {
    const { status, disabled } = (0, import_state.getStatus)(dateLimitData, currentDate, cutTime);
    const isShow = (0, import_state.getCallToBookStatus)(currentDate, dateLimitData, cutTime);
    if (isShow && (status === "lots_of_space" || status === "filling_up_fast")) {
      setShowCallToBook(true);
    } else {
      setShowCallToBook(false);
    }
    setSelectStatus(status);
    setSelectDisabled(disabled);
  }, [currentDate, timeList, cutTime]);
  (0, import_react.useEffect)(() => {
    const index = weekList.findIndex((date) => date === currentDate);
    if ((weekListRef == null ? void 0 : weekListRef.current) && index !== -1) {
      weekListRef.current.scrollLeft = (index - 1) * 50;
    }
  }, [currentDate, weekList]);
  return /* @__PURE__ */ React.createElement("div", { className: "calendar-week-wrap" }, /* @__PURE__ */ React.createElement("div", { ref: weekListRef, className: "calendar-week-list" }, /* @__PURE__ */ React.createElement(
    import_WeekItem.default,
    {
      weekList,
      currentDate,
      dateChange,
      isActive: true,
      productId,
      setCurrentDate: dateChange,
      timeList,
      dateLimitData,
      cutTime
    }
  )), selectStatus === "sold_out" || selectDisabled ? /* @__PURE__ */ React.createElement("div", { className: "disabled-status" }, /* @__PURE__ */ React.createElement(
    import_materials.Iconfont,
    {
      className: (0, import_classnames.default)(
        "disabled-icon",
        "iconhourglass_disabled_wght300_24px"
      )
    }
  ), /* @__PURE__ */ React.createElement("div", { className: "disabled-status-text" }, selectDisabled ? 2 : 5)) : null, /* @__PURE__ */ React.createElement(import_CallToBook.default, { show: showCallToBook }));
};
var CalenDateWeek_default = CalenDateWeek;
