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/appointmentBooking/components/Date/state.ts
var state_exports = {};
__export(state_exports, {
  ShowDayOnly: () => ShowDayOnly,
  getCallToBookStatus: () => getCallToBookStatus,
  getNextSevenDaysList: () => getNextSevenDaysList,
  getStatus: () => getStatus,
  localeTypes: () => localeTypes,
  statusColor: () => statusColor,
  weekListText: () => weekListText
});
module.exports = __toCommonJS(state_exports);
var import_dayjs = __toESM(require("dayjs"));
var getNextSevenDaysList = (defaultDay) => {
  const currentDate = (0, import_dayjs.default)(defaultDay);
  const nextSevenDays = [];
  for (let i = 0; i < 7; i++) {
    const previousDay = currentDate.add(i, "day");
    nextSevenDays.push(previousDay.format("YYYY-MM-DD"));
  }
  return nextSevenDays;
};
var ShowDayOnly = (date) => {
  let defaultDay = (0, import_dayjs.default)().format("YYYY-MM-DD");
  if (date == defaultDay) {
    return "ToDay";
  }
  return (0, import_dayjs.default)(date).format("DD");
};
var weekListText = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"];
var statusColor = {
  call_to_book: "#444CE7",
  // 请致电预订
  lots_of_space: "#079455",
  // 库存充足
  filling_up_fast: "#CA8504",
  // 库存紧张
  sold_out: "#D92D20"
  // 无库存
};
var getStatus = (dateLimit, currentDate, cutTime) => {
  var _a, _b;
  let status = "";
  let disabled = false;
  const dataItem = dateLimit[currentDate];
  const startTime = (0, import_dayjs.default)(cutTime == null ? void 0 : cutTime.shop_time).format("YYYY-MM-DD HH:mm");
  const startDate = (0, import_dayjs.default)(cutTime == null ? void 0 : cutTime.shop_time).format("YYYY-MM-DD");
  const endTime = (0, import_dayjs.default)(startTime).add(cutTime == null ? void 0 : cutTime.unit, cutTime == null ? void 0 : cutTime.unit_type);
  const endDay = endTime.format("YYYY-MM-DD");
  try {
    if (!dataItem) {
      return {
        status,
        disabled: true
      };
    }
  } catch (err) {
    return {
      status,
      disabled: true
    };
  }
  if (!Object.keys(dateLimit).length) {
    return {
      status,
      disabled: true
    };
  }
  const times = dataItem.times || [];
  if (!times.length) {
    disabled = true;
  } else {
    let useable = null;
    if (cutTime.type === "ongoing" && currentDate === startDate) {
      if (((_a = cutTime == null ? void 0 : cutTime["ongoing"]) == null ? void 0 : _a.type) === "before_end") {
        useable = times.find((d) => {
          return startTime >= d.start_at && startTime < d.end_at || d.start_at >= startTime;
        });
      }
      if (((_b = cutTime == null ? void 0 : cutTime["ongoing"]) == null ? void 0 : _b.type) === "after_start") {
        useable = times.find((d) => {
          var _a2;
          const _endAt = (0, import_dayjs.default)(d.start_at).add(
            (_a2 = cutTime == null ? void 0 : cutTime["ongoing"]) == null ? void 0 : _a2.unit,
            "minutes"
          );
          const _endTime = _endAt.format("YYYY-MM-DD HH:mm");
          return startTime >= d.start_at && startTime <= _endTime || d.start_at >= startTime;
        });
      }
    } else {
      useable = times.find((d) => {
        return startTime < d.start_at;
      });
    }
    if (!useable) {
      return {
        status,
        disabled: true
      };
    }
    const haveUnLimit = times.find((item) => item.limit === 0);
    if (haveUnLimit) {
      status = "lots_of_space";
    } else {
      const allLimit = times.reduce((prev, next) => {
        return prev + next.limit;
      }, 0);
      const allOrderCount = times.reduce((prev, next) => {
        return prev + next.order_count;
      }, 0);
      const percent = (allLimit - allOrderCount) / allLimit;
      if (percent > 0.5) {
        status = "lots_of_space";
      } else if (percent <= 0.5 && percent > 0) {
        status = "filling_up_fast";
      } else if (percent <= 0) {
        status = "sold_out";
      }
    }
  }
  return {
    status,
    disabled
  };
};
var getCallToBookStatus = (currentDate, dateLimitData, cutTime) => {
  var _a, _b;
  const timeList = ((_a = dateLimitData[currentDate]) == null ? void 0 : _a.times) || [];
  let isShowCallToBook = false;
  if (!currentDate || !(cutTime == null ? void 0 : cutTime.shop_time) || !(cutTime == null ? void 0 : cutTime.unit) || !(cutTime == null ? void 0 : cutTime.unit_type)) {
    isShowCallToBook = false;
    return isShowCallToBook;
  }
  if ((cutTime == null ? void 0 : cutTime.unit_type) === "hours" || (cutTime == null ? void 0 : cutTime.unit_type) === "minutes" || (cutTime == null ? void 0 : cutTime.unit_type) === "days") {
    const startTime = (0, import_dayjs.default)(cutTime.shop_time).format("YYYY-MM-DD HH:mm:ss");
    const endTime = (0, import_dayjs.default)(startTime).add(cutTime == null ? void 0 : cutTime.unit, cutTime == null ? void 0 : cutTime.unit_type).format("YYYY-MM-DD HH:mm:ss");
    if ((0, import_dayjs.default)(currentDate).isBefore((0, import_dayjs.default)(endTime.split(" ")[0]))) {
      isShowCallToBook = true;
    } else {
      if (currentDate === endTime.split(" ")[0]) {
        const haveTime = (_b = timeList == null ? void 0 : timeList.find) == null ? void 0 : _b.call(timeList, (item) => {
          const end_at = `${item.date} ${item.end_at}`;
          if ((0, import_dayjs.default)(end_at).valueOf() > (0, import_dayjs.default)(endTime).valueOf()) {
            return true;
          }
        });
        if (haveTime) {
          isShowCallToBook = false;
        } else {
          isShowCallToBook = true;
        }
      } else {
        isShowCallToBook = false;
      }
    }
  }
  return isShowCallToBook;
};
var localeTypes = {
  "en-US": "en",
  "zh-CN": "zh-cn",
  "zh-TW": "zh-tw",
  "ja": "ja",
  "pt": "pt"
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ShowDayOnly,
  getCallToBookStatus,
  getNextSevenDaysList,
  getStatus,
  localeTypes,
  statusColor,
  weekListText
});
