function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
// 日程文案格式化接口

// 日程项接口定义

// 格式化日期时间函数
function formatDateTime(dateTime) {
  var isAll = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'zh-CN';
  var date = new Date(dateTime);
  var year = date.getFullYear();
  var month = String(date.getMonth() + 1).padStart(2, '0');
  var day = String(date.getDate()).padStart(2, '0');
  var hours = date.getHours();
  var minutes = String(date.getMinutes()).padStart(2, '0');
  if (isAll) {
    // 全天情况下的日期格式
    if (locale === 'en') {
      return "".concat(day, "/").concat(month, "/").concat(year);
    } else {
      return "".concat(year, "-").concat(month, "-").concat(day);
    }
  }

  // 非全天情况下的日期时间格式
  if (locale === 'en') {
    // DD/MM/YYYY h:mm A 格式
    var period = hours >= 12 ? 'PM' : 'AM';
    var displayHours = hours === 0 ? 12 : hours > 12 ? hours - 12 : hours;
    return "".concat(day, "/").concat(month, "/").concat(year, " ").concat(displayHours, ":").concat(minutes, " ").concat(period);
  } else {
    // YYYY-MM-DD HH:mm 格式
    var _displayHours = String(hours).padStart(2, '0');
    return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(_displayHours, ":").concat(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) {
  var config = textConfig[locale];
  return dayNumbers.map(function (day) {
    return config.weekdays[day];
  }).join(config.separator);
}

// 获取重复频率文案
function getRepeatFrequencyText(repeatType, frequency, locale) {
  var config = textConfig[locale];
  var typeMap = {
    'daily': config.day,
    'weekly': config.week,
    'monthly': config.month,
    'yearly': config.year
  };
  if (locale === 'en') {
    if (frequency === 1) {
      return "".concat(config.every).concat(typeMap[repeatType]);
    }
    return "".concat(config.every).concat(frequency, " ").concat(typeMap[repeatType], "s");
  } else {
    if (frequency === 1) {
      return "".concat(config.every).concat(typeMap[repeatType]);
    }
    return "".concat(config.every).concat(frequency).concat(typeMap[repeatType]);
  }
}

/**
 * 根据scheduleList格式化文案展示
 * @param scheduleList 日程列表
 * @returns 格式化后的文案结果数组，每个日程对应一个结果
 */
export function formatScheduleText(scheduleList) {
  var locale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'en';
  var results = [];
  var config = textConfig[locale];
  scheduleList.forEach(function (schedule) {
    var _schedule$repeat_rule, _schedule$repeat_rule2;
    var validityTexts = [];
    var excluded_date = [];
    var included_date = [];

    // 处理排除日期
    if ((_schedule$repeat_rule = schedule.repeat_rule) !== null && _schedule$repeat_rule !== void 0 && _schedule$repeat_rule.excluded_date) {
      schedule.repeat_rule.excluded_date.forEach(function (excludeItem) {
        var startDate = formatDateTime(excludeItem.start, true, locale);
        var endDate = formatDateTime(excludeItem.end, true, locale);
        if (excludeItem.start === excludeItem.end) {
          // 开始和结束日期相同，只显示开始日期
          excluded_date.push(startDate);
        } else {
          // 开始和结束日期不同，显示范围格式
          excluded_date.push("".concat(startDate).concat(config.rangeSeparator).concat(endDate));
        }
      });
    }

    // 处理包含日期
    if ((_schedule$repeat_rule2 = schedule.repeat_rule) !== null && _schedule$repeat_rule2 !== void 0 && _schedule$repeat_rule2.included_date) {
      schedule.repeat_rule.included_date.forEach(function (includeItem) {
        var startDate = formatDateTime(includeItem.start, true, locale);
        var endDate = formatDateTime(includeItem.end, true, locale);
        if (includeItem.start === includeItem.end) {
          // 开始和结束日期相同，只显示开始日期
          included_date.push(startDate);
        } else {
          // 开始和结束日期不同，显示范围格式
          included_date.push("".concat(startDate).concat(config.rangeSeparator).concat(endDate));
        }
      });
    }
    var isAllDay = schedule.is_all === 1;
    var validityText = '';

    // 1. 非循环日程处理
    if (schedule.repeat_type === 'none') {
      // 1.1 单个标准日程（单日单段）
      if (schedule.type === 'standard') {
        var startDateTime = formatDateTime(schedule.start_time, isAllDay, locale);
        var endDateTime = formatDateTime(schedule.end_time, isAllDay, locale);
        validityText = "".concat(startDateTime).concat(config.rangeSeparator).concat(endDateTime);
      }
      // 1.2 多时间段日程（单日多段）
      else if (schedule.type === 'time-slots' && schedule.time_slot.length > 0) {
        var baseDate = formatDateTime(schedule.start_time, true, locale);
        if (isAllDay) {
          // 全天情况下，不显示时分
          validityText = "".concat(baseDate);
        } else {
          // 非全天情况下，按新格式显示时间段
          var timeSlots = schedule.time_slot.map(function (slot) {
            return "".concat(slot.start_time).concat(config.timeSeparator).concat(slot.end_time);
          });
          validityText = "".concat(baseDate, " ").concat(timeSlots.join(config.timeSlotSeparator));
        }
      } else if (schedule.type === 'designation' && schedule.designation) {
        var designationTexts = schedule.designation.map(function (item) {
          if (isAllDay || item.start_time === '00:00' && item.end_time === '23:59') {
            // 全天情况：只显示日期
            var startDate = formatDateTime(item.start_date, true, locale);
            var endDate = formatDateTime(item.end_date, true, locale);
            return "".concat(startDate).concat(config.rangeSeparator).concat(endDate);
          } else {
            // 非全天情况：按新格式显示日期时间
            var _startDate = formatDateTime(item.start_date, true, locale);
            return "".concat(_startDate, " ").concat(item.start_time).concat(config.timeSeparator).concat(item.end_time);
          }
        });
        validityTexts.push.apply(validityTexts, _toConsumableArray(designationTexts));
      }
    }

    // 2. 循环日程处理
    else if (schedule.repeat_rule) {
      var _schedule$repeat_rule3 = schedule.repeat_rule,
        frequency = _schedule$repeat_rule3.frequency,
        frequency_date = _schedule$repeat_rule3.frequency_date;

      // 根据 is_all 决定是否显示时分
      var startText = isAllDay ? formatDateTime(schedule.start_time, true, locale) : formatDateTime(schedule.start_time, false, locale);

      // 结束日期处理
      var 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);
      }

      // 2.1 标准类型循环日程
      if (schedule.type === 'standard') {
        // 按天循环
        if (schedule.repeat_type === 'daily') {
          if (isAllDay) {
            var frequencyText = getRepeatFrequencyText('daily', frequency, locale);
            if (locale === 'en') {
              validityText = "".concat(startText).concat(config.rangeSeparator).concat(endDateText, ", ").concat(config.available, " ").concat(frequencyText);
            } else {
              validityText = "".concat(startText).concat(config.rangeSeparator).concat(endDateText, "\uFF0C").concat(frequencyText).concat(config.available);
            }
          } else {
            var startTime = formatDateTime(schedule.start_time, false, locale);
            var endTime = formatDateTime(schedule.end_time, false, locale);
            var timeRange = locale === 'en' ? "".concat(startTime.split(' ')[1], " ").concat(startTime.split(' ')[2]).concat(config.timeSeparator).concat(endTime.split(' ')[1], " ").concat(endTime.split(' ')[2]) : "".concat(startTime.split(' ')[1]).concat(config.timeSeparator).concat(endTime.split(' ')[1]);
            var _frequencyText = getRepeatFrequencyText('daily', frequency, locale);
            var dateRange = locale === 'en' ? "".concat(startTime.split(' ')[0]).concat(config.rangeSeparator).concat(endDateText) : "".concat(startText.split(' ')[0]).concat(config.rangeSeparator).concat(endDateText);
            if (locale === 'en') {
              validityText = "".concat(dateRange, ", ").concat(config.available, " ").concat(_frequencyText, " ").concat(timeRange);
            } else {
              validityText = "".concat(dateRange, "\uFF0C").concat(_frequencyText, " ").concat(timeRange, " ").concat(config.available);
            }
          }
        }

        // 按周循环
        else if (schedule.repeat_type === 'weekly') {
          var weekdaysText = getWeekdayText(frequency_date, locale);
          if (isAllDay) {
            if (locale === 'en') {
              var _frequencyText2 = frequency === 1 ? 'every week' : "every ".concat(frequency, " weeks");
              validityText = "".concat(startText).concat(config.rangeSeparator).concat(endDateText, ", ").concat(_frequencyText2, " on ").concat(weekdaysText, " ");
            } else {
              var _frequencyText3 = frequency === 1 ? '每周' : "\u6BCF".concat(frequency, "\u5468\u7684");
              validityText = "".concat(startText).concat(config.rangeSeparator).concat(endDateText, "\uFF0C").concat(_frequencyText3).concat(config.weekPrefix).concat(weekdaysText).concat(config.available);
            }
          } else {
            var _startTime = formatDateTime(schedule.start_time, false, locale);
            var _endTime = formatDateTime(schedule.end_time, false, locale);
            var _timeRange = locale === 'en' ? "".concat(_startTime.split(' ')[1], " ").concat(_startTime.split(' ')[2]).concat(config.timeSeparator).concat(_endTime.split(' ')[1], " ").concat(_endTime.split(' ')[2]) : "".concat(_startTime.split(' ')[1]).concat(config.timeSeparator).concat(_endTime.split(' ')[1]);
            var _dateRange = locale === 'en' ? "".concat(_startTime.split(' ')[0]).concat(config.rangeSeparator).concat(endDateText) : "".concat(startText.split(' ')[0]).concat(config.rangeSeparator).concat(endDateText);
            if (locale === 'en') {
              var _frequencyText4 = frequency === 1 ? 'every week' : "every ".concat(frequency, " weeks");
              validityText = "".concat(_dateRange, ", ").concat(_frequencyText4, " on ").concat(weekdaysText, " ").concat(_timeRange);
            } else {
              var _frequencyText5 = frequency === 1 ? '每周' : "\u6BCF".concat(frequency, "\u5468\u7684");
              validityText = "".concat(_dateRange, "\uFF0C").concat(_frequencyText5).concat(config.weekPrefix).concat(weekdaysText, " ").concat(_timeRange);
            }
          }
        }
      }

      // 2.2 多时间段类型循环日程
      else if (schedule.type === 'time-slots' && schedule.time_slot.length > 0) {
        var _baseDate = formatDateTime(schedule.start_time, true, locale);

        // 格式化时间段
        var _timeSlots = schedule.time_slot.map(function (slot) {
          return "".concat(slot.start_time).concat(config.timeSeparator).concat(slot.end_time);
        });
        var timeSlotsText = _timeSlots.join(config.timeSlotSeparator);

        // 按天循环
        if (schedule.repeat_type === 'daily') {
          var _frequencyText6 = getRepeatFrequencyText('daily', frequency, locale);
          if (locale === 'en') {
            validityText = "".concat(_baseDate).concat(config.rangeSeparator).concat(endDateText, ", ").concat(config.available, " ").concat(_frequencyText6, " ").concat(timeSlotsText);
          } else {
            validityText = "".concat(_baseDate).concat(config.rangeSeparator).concat(endDateText, "\uFF0C").concat(_frequencyText6, " ").concat(timeSlotsText, " ").concat(config.available);
          }
        }

        // 按周循环
        else if (schedule.repeat_type === 'weekly') {
          var _weekdaysText = getWeekdayText(frequency_date, locale);
          if (locale === 'en') {
            var _frequencyText7 = frequency === 1 ? 'every week' : "every ".concat(frequency, " weeks");
            validityText = "".concat(_baseDate).concat(config.rangeSeparator).concat(endDateText, ", ").concat(_frequencyText7, " on ").concat(_weekdaysText, " ").concat(timeSlotsText);
          } else {
            var _frequencyText8 = frequency === 1 ? '每周' : "\u6BCF".concat(frequency, "\u5468\u7684");
            validityText = "".concat(_baseDate).concat(config.rangeSeparator).concat(endDateText, "\uFF0C").concat(_frequencyText8).concat(config.weekPrefix).concat(_weekdaysText, " ").concat(timeSlotsText, " ").concat(config.available);
          }
        }
      }
    }

    // 4. 指定日期日程（多天多段）
    else if (schedule.type === 'designation' && schedule.designation) {
      var _designationTexts = schedule.designation.map(function (item) {
        if (isAllDay || item.start_time === '00:00' && item.end_time === '23:59') {
          // 全天情况：只显示日期
          var startDate = formatDateTime(item.start_date, true, locale);
          var endDate = formatDateTime(item.end_date, true, locale);
          return "".concat(startDate).concat(config.rangeSeparator).concat(endDate);
        } else {
          // 非全天情况：按新格式显示日期时间
          var _startDate2 = formatDateTime(item.start_date, true, locale);
          return "".concat(_startDate2, " ").concat(item.start_time).concat(config.timeSeparator).concat(item.end_time);
        }
      });
      // 多天多段情况，每个时间段作为独立元素添加到validityTexts中
      validityTexts.push.apply(validityTexts, _toConsumableArray(_designationTexts));
    }
    if (validityText) {
      validityTexts.push(validityText);
    }

    // 为每个日程创建一个结果
    results.push({
      validityTexts: validityTexts,
      excluded_date: excluded_date,
      included_date: included_date
    });
  });
  return results;
}