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/components/pisellTimeNavigator/hooks/useTimeAxis.ts
var useTimeAxis_exports = {};
__export(useTimeAxis_exports, {
  useTimeAxis: () => useTimeAxis
});
module.exports = __toCommonJS(useTimeAxis_exports);
var import_react = require("react");
var import_utils = require("../utils");
function useTimeAxis(options) {
  const {
    range,
    stepMinutes,
    referenceDate,
    orientation,
    cellSizePx
  } = options;
  return (0, import_react.useMemo)(() => {
    const [rangeStart, rangeEnd] = (0, import_utils.getRangeBounds)(range, referenceDate);
    const ticks = (0, import_utils.getTicks)(rangeStart, rangeEnd, stepMinutes);
    const lastTick = ticks.length > 0 ? ticks[ticks.length - 1] : null;
    const needTailCell = orientation === "horizontal" && lastTick != null && rangeEnd.isAfter(lastTick);
    const noTailVertical = orientation === "vertical" && lastTick != null && !rangeEnd.isAfter(lastTick);
    const effectiveTicks = noTailVertical && ticks.length > 0 ? ticks.slice(0, -1) : ticks;
    const rawTotalPx = orientation === "vertical" ? effectiveTicks.length * cellSizePx : (ticks.length + (needTailCell ? 1 : 0)) * cellSizePx;
    const totalLengthPx = Math.min(rawTotalPx, 5e5);
    const dotOffsetPx = orientation === "vertical" ? 0 : cellSizePx / 2;
    const maxOffsetPx = orientation === "vertical" ? totalLengthPx : dotOffsetPx + (needTailCell ? ticks.length : Math.max(0, ticks.length - 1)) * cellSizePx;
    const timeToOffset = (t) => {
      const diffMs = t.diff(rangeStart);
      const diffMin = diffMs / (60 * 1e3);
      const index = diffMin / stepMinutes;
      const px = dotOffsetPx + index * cellSizePx;
      return Math.max(dotOffsetPx, Math.min(px, maxOffsetPx));
    };
    const offsetToTime = (offset) => {
      const index = Math.round((offset - dotOffsetPx) / cellSizePx);
      const tick = effectiveTicks[index];
      return tick ?? null;
    };
    const offsetToTimeContinuous = (offset) => {
      const index = (offset - dotOffsetPx) / cellSizePx;
      const minutesFromStart = index * stepMinutes;
      let t = rangeStart.add(minutesFromStart, "minute");
      if (t.isBefore(rangeStart)) return rangeStart;
      if (t.isAfter(rangeEnd)) return rangeEnd;
      return t;
    };
    return {
      rangeStart,
      rangeEnd,
      ticks: effectiveTicks,
      timeToOffset,
      offsetToTime,
      offsetToTimeContinuous,
      totalLengthPx
    };
  }, [
    range == null ? void 0 : range.start,
    range == null ? void 0 : range.end,
    stepMinutes,
    referenceDate.valueOf(),
    orientation,
    cellSizePx
  ]);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useTimeAxis
});
