function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
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; }
import { extractTimeFromDateTime, sortTimePoints } from "./time";
/**
 * 从餐牌列表中提取所有 schedule IDs
 * @param menus 餐牌列表
 * @returns 去重后的日程ID数组
 */
export function extractScheduleIdsFromMenus(menus) {
  var scheduleIds = menus.reduce(function (ids, menu) {
    if (menu.schedule && Array.isArray(menu.schedule)) {
      return [].concat(_toConsumableArray(ids), _toConsumableArray(menu.schedule));
    }
    return ids;
  }, []);

  // 去重
  return Array.from(new Set(scheduleIds));
}

/**
 * 从日程列表中提取所有时间点
 * @param schedules 日程列表
 * @returns 排序后的时间点数组，格式为 ["10:00", "12:00", "14:00", "18:00"]
 */
export function extractTimePointsFromSchedules(schedules) {
  var timePointsSet = new Set();
  var _iterator = _createForOfIteratorHelper(schedules),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var schedule = _step.value;
      switch (schedule.type) {
        case 'standard':
          // 标准类型：从 start_time 和 end_time 中提取时间部分
          if (schedule.start_time) {
            var startTime = extractTimeFromDateTime(schedule.start_time);
            if (startTime) timePointsSet.add(startTime);
          }
          if (schedule.end_time) {
            var endTime = extractTimeFromDateTime(schedule.end_time);
            if (endTime) timePointsSet.add(endTime);
          }
          break;
        case 'time-slots':
          // 时间段类型：从 time_slot 数组中提取时间
          if (schedule.time_slot && Array.isArray(schedule.time_slot)) {
            var _iterator2 = _createForOfIteratorHelper(schedule.time_slot),
              _step2;
            try {
              for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
                var slot = _step2.value;
                if (slot.start_time) {
                  timePointsSet.add(slot.start_time);
                }
                if (slot.end_time) {
                  timePointsSet.add(slot.end_time);
                }
              }
            } catch (err) {
              _iterator2.e(err);
            } finally {
              _iterator2.f();
            }
          }
          break;
        case 'designation':
          // 指定日期类型：从 designation 中提取时间
          if (schedule.designation) {
            var designations = Array.isArray(schedule.designation) ? schedule.designation : [schedule.designation];
            var _iterator3 = _createForOfIteratorHelper(designations),
              _step3;
            try {
              for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
                var des = _step3.value;
                if (des.start_time) {
                  timePointsSet.add(des.start_time);
                }
                if (des.end_time) {
                  timePointsSet.add(des.end_time);
                }
              }
            } catch (err) {
              _iterator3.e(err);
            } finally {
              _iterator3.f();
            }
          }
          break;
        default:
          console.warn("[ScheduleUtils] \u672A\u77E5\u7684\u65E5\u7A0B\u7C7B\u578B: ".concat(schedule.type));
      }
    }

    // 转换为数组并排序
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  var timePoints = Array.from(timePointsSet);
  return sortTimePoints(timePoints);
}