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/pisellTimeNavigator/utils/index.ts
var utils_exports = {};
__export(utils_exports, {
  getHorizontalAxisSlotCount: () => getHorizontalAxisSlotCount,
  getRangeBounds: () => getRangeBounds,
  getTicks: () => getTicks,
  isInDisabledRanges: () => isInDisabledRanges,
  parseValue: () => parseValue,
  snapToStepMinutes: () => snapToStepMinutes
});
module.exports = __toCommonJS(utils_exports);
var import_dayjs = __toESM(require("dayjs"));
function parseTimeOfDay(timeStr, reference) {
  const [h, m, s] = timeStr.trim().split(":").map(Number);
  return reference.hour(isNaN(h) ? 0 : h).minute(isNaN(m) ? 0 : m).second(isNaN(s) ? 0 : s).millisecond(0);
}
var TIME_ONLY_REGEX = /^\s*\d{1,2}:\d{2}(:\d{2})?\s*$/;
function parseValue(value, reference) {
  if (value == null) return null;
  const ref = reference ?? (0, import_dayjs.default)();
  if (typeof value === "string" && TIME_ONLY_REGEX.test(value)) {
    return parseTimeOfDay(value, ref);
  }
  const d = (0, import_dayjs.default)(value);
  return d.isValid() ? d : null;
}
function getRangeBounds(range, reference) {
  if (!range) {
    return [reference.startOf("day"), reference.endOf("day")];
  }
  const start = parseTimeOfDay(range.start, reference);
  let end = parseTimeOfDay(range.end, reference);
  if (end.isBefore(start) || end.isSame(start)) {
    end = parseTimeOfDay(range.end, reference.add(1, "day"));
  }
  return [start, end];
}
function snapToStepMinutes(t, stepMinutes) {
  const m = t.minute();
  const snapped = Math.round(m / stepMinutes) * stepMinutes;
  if (snapped >= 60) {
    return t.add(1, "hour").minute(0).second(0).millisecond(0);
  }
  return t.minute(snapped).second(0).millisecond(0);
}
function isInDisabledRanges(t, disabledRanges) {
  if (!(disabledRanges == null ? void 0 : disabledRanges.length)) return false;
  const tMin = t.startOf("minute");
  for (const r of disabledRanges) {
    const [s, e] = getRangeBounds(r, t.startOf("day"));
    if ((tMin.isAfter(s) || tMin.isSame(s)) && tMin.isBefore(e)) return true;
  }
  return false;
}
function getTicks(rangeStart, rangeEnd, stepMinutes) {
  const out = [];
  let cur = rangeStart;
  while (!cur.isAfter(rangeEnd)) {
    out.push(cur);
    cur = cur.add(stepMinutes, "minute");
  }
  return out;
}
function getHorizontalAxisSlotCount(range, referenceDate, stepMinutes) {
  const [rangeStart, rangeEnd] = getRangeBounds(range, referenceDate);
  const ticks = getTicks(rangeStart, rangeEnd, stepMinutes);
  const lastTick = ticks.length > 0 ? ticks[ticks.length - 1] : null;
  const needTailCell = lastTick != null && rangeEnd.isAfter(lastTick);
  return ticks.length + (needTailCell ? 1 : 0);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getHorizontalAxisSlotCount,
  getRangeBounds,
  getTicks,
  isInDisabledRanges,
  parseValue,
  snapToStepMinutes
});
