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 safeStep = Math.max(1, stepMinutes);
    const cells = (0, import_utils.getAxisCells)(rangeStart, rangeEnd, safeStep);
    const ticks = cells.map((c) => c.start);
    const cellWidthsPx = cells.map(
      (c) => c.widthMinutes / safeStep * cellSizePx
    );
    const cellsTotalPx = cellWidthsPx.reduce((s, w) => s + w, 0);
    const dotOffsetPx = orientation === "vertical" ? 0 : cellSizePx / 2;
    const rawTotalPx = orientation === "horizontal" ? cellsTotalPx + cellSizePx : cellsTotalPx;
    const totalLengthPx = Math.min(rawTotalPx, 5e5);
    const maxOffsetPx = orientation === "vertical" ? cellsTotalPx : dotOffsetPx + cellsTotalPx;
    const timeToOffset = (t) => {
      const diffMs = t.diff(rangeStart);
      const diffMin = diffMs / (60 * 1e3);
      const index = diffMin / safeStep;
      const px = dotOffsetPx + index * cellSizePx;
      return Math.max(dotOffsetPx, Math.min(px, maxOffsetPx));
    };
    const offsetToTime = (offset) => {
      if (ticks.length === 0) return null;
      let bestIdx = 0;
      let bestDist = Infinity;
      for (let i = 0; i < ticks.length; i += 1) {
        const px = timeToOffset(ticks[i]);
        const d = Math.abs(px - offset);
        if (d < bestDist) {
          bestDist = d;
          bestIdx = i;
        }
      }
      return ticks[bestIdx];
    };
    const offsetToTimeContinuous = (offset) => {
      const index = (offset - dotOffsetPx) / cellSizePx;
      const minutesFromStart = index * safeStep;
      const t = rangeStart.add(minutesFromStart, "minute");
      if (t.isBefore(rangeStart)) return rangeStart;
      if (t.isAfter(rangeEnd)) return rangeEnd;
      return t;
    };
    return {
      rangeStart,
      rangeEnd,
      ticks,
      cellWidthsPx,
      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
});
