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/plus/pisellReservation/data/reservationOperatingDayRange.ts
var reservationOperatingDayRange_exports = {};
__export(reservationOperatingDayRange_exports, {
  boundaryClockFromOperatingDayBoundary: () => boundaryClockFromOperatingDayBoundary,
  normalizeBoundaryClock: () => normalizeBoundaryClock,
  resolveOperatingDayBoundaryFromCoreModel: () => resolveOperatingDayBoundaryFromCoreModel,
  timelineRangeFromOperatingDayBoundary: () => timelineRangeFromOperatingDayBoundary,
  timelineReferenceDateForScheduleDay: () => timelineReferenceDateForScheduleDay
});
module.exports = __toCommonJS(reservationOperatingDayRange_exports);
var import_dayjs = __toESM(require("dayjs"));
var import_reservationConstants = require("../reservationConstants");
function normalizeOperatingDayBoundaryRaw(raw) {
  if (raw == null) return void 0;
  if (!Array.isArray(raw)) return raw;
  const pick = (t) => raw.find(
    (x) => x != null && typeof x === "object" && String(x.type) === t
  );
  return pick("start_time") ?? pick("end_time") ?? raw[0];
}
function resolveOperatingDayBoundaryFromCoreModel(coreModel) {
  if (coreModel == null || typeof coreModel !== "object") {
    return void 0;
  }
  const root = coreModel;
  let raw;
  if (root.core != null && typeof root.core === "object") {
    raw = root.core.operating_day_boundary;
  }
  if (raw == null) {
    raw = root.operating_day_boundary;
  }
  return normalizeOperatingDayBoundaryRaw(raw);
}
function normalizeBoundaryClock(raw) {
  const t = raw.trim();
  if (!t) return null;
  const parts = t.split(":").map((p) => p.trim());
  const h = Number(parts[0]);
  const m = Number(parts[1] ?? "0");
  const s = Number(parts[2] ?? "0");
  if (!Number.isFinite(h) || !Number.isFinite(m) || !Number.isFinite(s))
    return null;
  if (h < 0 || h > 23 || m < 0 || m > 59 || s < 0 || s > 59) return null;
  return `${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
}
function boundaryClockFromOperatingDayBoundary(operatingDayBoundary) {
  const b = operatingDayBoundary;
  const type = b == null ? void 0 : b.type;
  if (type !== "start_time" && type !== "end_time") return null;
  return normalizeBoundaryClock(String((b == null ? void 0 : b.time) ?? ""));
}
function timelineReferenceDateForScheduleDay(scheduleDate, operatingDayBoundary) {
  const d = (0, import_dayjs.default)(scheduleDate).startOf("day");
  const b = operatingDayBoundary;
  if (String((b == null ? void 0 : b.type) ?? "") === "end_time") {
    return d.subtract(1, "day");
  }
  return d;
}
function timelineRangeFromOperatingDayBoundary(operatingDayBoundary) {
  const normalized = boundaryClockFromOperatingDayBoundary(operatingDayBoundary);
  if (!normalized) {
    return {
      start: import_reservationConstants.RESERVATION_TIMELINE_BUSINESS_RANGE.start,
      end: import_reservationConstants.RESERVATION_TIMELINE_BUSINESS_RANGE.end
    };
  }
  return { start: normalized, end: normalized };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  boundaryClockFromOperatingDayBoundary,
  normalizeBoundaryClock,
  resolveOperatingDayBoundaryFromCoreModel,
  timelineRangeFromOperatingDayBoundary,
  timelineReferenceDateForScheduleDay
});
