var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/walletPassGallery/utils.ts
var utils_exports = {};
__export(utils_exports, {
  formatScheduleText: () => formatScheduleText
});
module.exports = __toCommonJS(utils_exports);
function formatDateTime(dateTime, isAll = false, locale = "zh-CN") {
  const date = new Date(dateTime);
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, "0");
  const day = String(date.getDate()).padStart(2, "0");
  const hours = date.getHours();
  const minutes = String(date.getMinutes()).padStart(2, "0");
  if (isAll) {
    if (locale === "en") {
      return `${day}/${month}/${year}`;
    } else {
      return `${year}-${month}-${day}`;
    }
  }
  if (locale === "en") {
    const period = hours >= 12 ? "PM" : "AM";
    const displayHours = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;
    return `${day}/${month}/${year} ${displayHours}:${minutes} ${period}`;
  } else {
    const displayHours = String(hours).padStart(2, "0");
    return `${year}-${month}-${day} ${displayHours}:${minutes}`;
  }
}
var textConfig = {
  "zh-HK": {
    weekdays: ["日", "一", "二", "三", "四", "五", "六"],
    separator: "、",
    timeSeparator: "–",
    rangeSeparator: " 至 ",
    periodSeparator: "；",
    timeSlotSeparator: "，",
    every: "每",
    day: "天",
    week: "周",
    month: "月",
    year: "年",
    available: "可用",
    unlimited: "无限期",
    weekPrefix: "周"
  },
  "zh-CN": {
    weekdays: ["日", "一", "二", "三", "四", "五", "六"],
    separator: "、",
    timeSeparator: "–",
    rangeSeparator: " 至 ",
    periodSeparator: "；",
    timeSlotSeparator: "，",
    every: "每",
    day: "天",
    week: "周",
    month: "月",
    year: "年",
    available: "可用",
    unlimited: "无限期",
    weekPrefix: "周"
  },
  "en": {
    weekdays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
    separator: ", ",
    timeSeparator: "–",
    rangeSeparator: " - ",
    periodSeparator: "; ",
    timeSlotSeparator: ", ",
    every: "every ",
    day: "day",
    week: "week",
    month: "month",
    year: "year",
    available: "available",
    unlimited: "unlimited",
    weekPrefix: ""
  }
};
function getWeekdayText(dayNumbers, locale) {
  const config = textConfig[locale];
  return dayNumbers.map((day) => config.weekdays[day]).join(config.separator);
}
function getRepeatFrequencyText(repeatType, frequency, locale) {
  const config = textConfig[locale];
  const typeMap = {
    "daily": config.day,
    "weekly": config.week,
    "monthly": config.month,
    "yearly": config.year
  };
  if (locale === "en") {
    if (frequency === 1) {
      return `${config.every}${typeMap[repeatType]}`;
    }
    return `${config.every}${frequency} ${typeMap[repeatType]}s`;
  } else {
    if (frequency === 1) {
      return `${config.every}${typeMap[repeatType]}`;
    }
    return `${config.every}${frequency}${typeMap[repeatType]}`;
  }
}
function formatScheduleText(scheduleList, locale = "en") {
  const results = [];
  const config = textConfig[locale];
  scheduleList.forEach((schedule) => {
    var _a, _b;
    const validityTexts = [];
    const excluded_date = [];
    const included_date = [];
    if ((_a = schedule.repeat_rule) == null ? void 0 : _a.excluded_date) {
      schedule.repeat_rule.excluded_date.forEach((excludeItem) => {
        const startDate = formatDateTime(excludeItem.start, true, locale);
        const endDate = formatDateTime(excludeItem.end, true, locale);
        if (excludeItem.start === excludeItem.end) {
          excluded_date.push(startDate);
        } else {
          excluded_date.push(`${startDate}${config.rangeSeparator}${endDate}`);
        }
      });
    }
    if ((_b = schedule.repeat_rule) == null ? void 0 : _b.included_date) {
      schedule.repeat_rule.included_date.forEach((includeItem) => {
        const startDate = formatDateTime(includeItem.start, true, locale);
        const endDate = formatDateTime(includeItem.end, true, locale);
        if (includeItem.start === includeItem.end) {
          included_date.push(startDate);
        } else {
          included_date.push(`${startDate}${config.rangeSeparator}${endDate}`);
        }
      });
    }
    const isAllDay = schedule.is_all === 1;
    let validityText = "";
    if (schedule.repeat_type === "none") {
      if (schedule.type === "standard") {
        const startDateTime = formatDateTime(schedule.start_time, isAllDay, locale);
        const endDateTime = formatDateTime(schedule.end_time, isAllDay, locale);
        validityText = `${startDateTime}${config.rangeSeparator}${endDateTime}`;
      } else if (schedule.type === "time-slots" && schedule.time_slot.length > 0) {
        const baseDate = formatDateTime(schedule.start_time, true, locale);
        if (isAllDay) {
          validityText = `${baseDate}`;
        } else {
          const timeSlots = schedule.time_slot.map(
            (slot) => `${slot.start_time}${config.timeSeparator}${slot.end_time}`
          );
          validityText = `${baseDate} ${timeSlots.join(config.timeSlotSeparator)}`;
        }
      } else if (schedule.type === "designation" && schedule.designation) {
        const designationTexts = schedule.designation.map((item) => {
          if (isAllDay || item.start_time === "00:00" && item.end_time === "23:59") {
            const startDate = formatDateTime(item.start_date, true, locale);
            const endDate = formatDateTime(item.end_date, true, locale);
            return `${startDate}${config.rangeSeparator}${endDate}`;
          } else {
            const startDate = formatDateTime(item.start_date, true, locale);
            return `${startDate} ${item.start_time}${config.timeSeparator}${item.end_time}`;
          }
        });
        validityTexts.push(...designationTexts);
      }
    } else if (schedule.repeat_rule) {
      const { frequency, frequency_date } = schedule.repeat_rule;
      const startText = isAllDay ? formatDateTime(schedule.start_time, true, locale) : formatDateTime(schedule.start_time, false, locale);
      let endDateText = "";
      if (schedule.repeat_rule.end.type === "never") {
        endDateText = config.unlimited;
      } else if (schedule.repeat_rule.end.end_date) {
        endDateText = formatDateTime(schedule.repeat_rule.end.end_date, true, locale);
      }
      if (schedule.type === "standard") {
        if (schedule.repeat_type === "daily") {
          if (isAllDay) {
            const frequencyText = getRepeatFrequencyText("daily", frequency, locale);
            if (locale === "en") {
              validityText = `${startText}${config.rangeSeparator}${endDateText}, ${config.available} ${frequencyText}`;
            } else {
              validityText = `${startText}${config.rangeSeparator}${endDateText}，${frequencyText}${config.available}`;
            }
          } else {
            const startTime = formatDateTime(schedule.start_time, false, locale);
            const endTime = formatDateTime(schedule.end_time, false, locale);
            const timeRange = locale === "en" ? `${startTime.split(" ")[1]} ${startTime.split(" ")[2]}${config.timeSeparator}${endTime.split(" ")[1]} ${endTime.split(" ")[2]}` : `${startTime.split(" ")[1]}${config.timeSeparator}${endTime.split(" ")[1]}`;
            const frequencyText = getRepeatFrequencyText("daily", frequency, locale);
            const dateRange = locale === "en" ? `${startTime.split(" ")[0]}${config.rangeSeparator}${endDateText}` : `${startText.split(" ")[0]}${config.rangeSeparator}${endDateText}`;
            if (locale === "en") {
              validityText = `${dateRange}, ${config.available} ${frequencyText} ${timeRange}`;
            } else {
              validityText = `${dateRange}，${frequencyText} ${timeRange} ${config.available}`;
            }
          }
        } else if (schedule.repeat_type === "weekly") {
          const weekdaysText = getWeekdayText(frequency_date, locale);
          if (isAllDay) {
            if (locale === "en") {
              const frequencyText = frequency === 1 ? "every week" : `every ${frequency} weeks`;
              validityText = `${startText}${config.rangeSeparator}${endDateText}, ${frequencyText} on ${weekdaysText} `;
            } else {
              const frequencyText = frequency === 1 ? "每周" : `每${frequency}周的`;
              validityText = `${startText}${config.rangeSeparator}${endDateText}，${frequencyText}${config.weekPrefix}${weekdaysText}${config.available}`;
            }
          } else {
            const startTime = formatDateTime(schedule.start_time, false, locale);
            const endTime = formatDateTime(schedule.end_time, false, locale);
            const timeRange = locale === "en" ? `${startTime.split(" ")[1]} ${startTime.split(" ")[2]}${config.timeSeparator}${endTime.split(" ")[1]} ${endTime.split(" ")[2]}` : `${startTime.split(" ")[1]}${config.timeSeparator}${endTime.split(" ")[1]}`;
            const dateRange = locale === "en" ? `${startTime.split(" ")[0]}${config.rangeSeparator}${endDateText}` : `${startText.split(" ")[0]}${config.rangeSeparator}${endDateText}`;
            if (locale === "en") {
              const frequencyText = frequency === 1 ? "every week" : `every ${frequency} weeks`;
              validityText = `${dateRange}, ${frequencyText} on ${weekdaysText} ${timeRange}`;
            } else {
              const frequencyText = frequency === 1 ? "每周" : `每${frequency}周的`;
              validityText = `${dateRange}，${frequencyText}${config.weekPrefix}${weekdaysText} ${timeRange}`;
            }
          }
        }
      } else if (schedule.type === "time-slots" && schedule.time_slot.length > 0) {
        const baseDate = formatDateTime(schedule.start_time, true, locale);
        const timeSlots = schedule.time_slot.map(
          (slot) => `${slot.start_time}${config.timeSeparator}${slot.end_time}`
        );
        const timeSlotsText = timeSlots.join(config.timeSlotSeparator);
        if (schedule.repeat_type === "daily") {
          const frequencyText = getRepeatFrequencyText("daily", frequency, locale);
          if (locale === "en") {
            validityText = `${baseDate}${config.rangeSeparator}${endDateText}, ${config.available} ${frequencyText} ${timeSlotsText}`;
          } else {
            validityText = `${baseDate}${config.rangeSeparator}${endDateText}，${frequencyText} ${timeSlotsText} ${config.available}`;
          }
        } else if (schedule.repeat_type === "weekly") {
          const weekdaysText = getWeekdayText(frequency_date, locale);
          if (locale === "en") {
            const frequencyText = frequency === 1 ? "every week" : `every ${frequency} weeks`;
            validityText = `${baseDate}${config.rangeSeparator}${endDateText}, ${frequencyText} on ${weekdaysText} ${timeSlotsText}`;
          } else {
            const frequencyText = frequency === 1 ? "每周" : `每${frequency}周的`;
            validityText = `${baseDate}${config.rangeSeparator}${endDateText}，${frequencyText}${config.weekPrefix}${weekdaysText} ${timeSlotsText} ${config.available}`;
          }
        }
      }
    } else if (schedule.type === "designation" && schedule.designation) {
      const designationTexts = schedule.designation.map((item) => {
        if (isAllDay || item.start_time === "00:00" && item.end_time === "23:59") {
          const startDate = formatDateTime(item.start_date, true, locale);
          const endDate = formatDateTime(item.end_date, true, locale);
          return `${startDate}${config.rangeSeparator}${endDate}`;
        } else {
          const startDate = formatDateTime(item.start_date, true, locale);
          return `${startDate} ${item.start_time}${config.timeSeparator}${item.end_time}`;
        }
      });
      validityTexts.push(...designationTexts);
    }
    if (validityText) {
      validityTexts.push(validityText);
    }
    results.push({
      validityTexts,
      excluded_date,
      included_date
    });
  });
  return results;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  formatScheduleText
});
