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/components/GestureLayer.tsx
var GestureLayer_exports = {};
__export(GestureLayer_exports, {
  GestureLayer: () => GestureLayer
});
module.exports = __toCommonJS(GestureLayer_exports);
var import_react = __toESM(require("react"));
function GestureLayer({
  orientation,
  cellSizePx,
  axisStartMarginPx,
  offsetToTime,
  onSelectTime,
  isInDisabledRanges,
  snapToStep,
  stepMinutes,
  snapFn,
  scrollPosition,
  viewportSize,
  onPointerDown,
  onPointerMove,
  onPointerUp,
  onPointerLeave,
  onUserInteraction,
  children
}) {
  const isHorizontal = orientation === "horizontal";
  const handleClick = (0, import_react.useCallback)(
    (e) => {
      onUserInteraction == null ? void 0 : onUserInteraction();
      const viewport = e.currentTarget.parentElement;
      if (!viewport) return;
      const vRect = viewport.getBoundingClientRect();
      const scroll = isHorizontal ? viewport.scrollLeft : viewport.scrollTop;
      const scrollContentPos = isHorizontal ? scroll + (e.clientX - vRect.left) : scroll + (e.clientY - vRect.top);
      const offset = Math.max(0, scrollContentPos - axisStartMarginPx);
      const t = offsetToTime(offset);
      if (t == null) return;
      const candidate = snapToStep ? snapFn(t) : t;
      if (isInDisabledRanges(candidate)) return;
      onSelectTime(candidate);
    },
    [
      isHorizontal,
      axisStartMarginPx,
      offsetToTime,
      onSelectTime,
      isInDisabledRanges,
      snapToStep,
      snapFn,
      onUserInteraction
    ]
  );
  const handleKeyDown = (0, import_react.useCallback)(
    (e) => {
      const scrollContentCenter = orientation === "horizontal" ? scrollPosition.scrollLeft + viewportSize.w / 2 : scrollPosition.scrollTop + viewportSize.h / 2;
      const centerOffset = Math.max(0, scrollContentCenter - axisStartMarginPx);
      const currentTime = offsetToTime(centerOffset);
      if (currentTime == null) return;
      if (e.key === "Enter") {
        const candidate = snapToStep ? snapFn(currentTime) : currentTime;
        if (!isInDisabledRanges(candidate)) {
          onUserInteraction == null ? void 0 : onUserInteraction();
          onSelectTime(candidate);
        }
        e.preventDefault();
        return;
      }
      const step = stepMinutes * 60 * 1e3;
      let next;
      if (orientation === "horizontal") {
        if (e.key === "ArrowLeft") next = currentTime.subtract(step, "ms");
        else if (e.key === "ArrowRight") next = currentTime.add(step, "ms");
        else return;
      } else {
        if (e.key === "ArrowUp") next = currentTime.subtract(step, "ms");
        else if (e.key === "ArrowDown") next = currentTime.add(step, "ms");
        else return;
      }
      e.preventDefault();
      const snapped = snapToStep ? snapFn(next) : next;
      if (!isInDisabledRanges(snapped)) {
        onUserInteraction == null ? void 0 : onUserInteraction();
        onSelectTime(snapped);
      }
    },
    [
      orientation,
      axisStartMarginPx,
      offsetToTime,
      onSelectTime,
      isInDisabledRanges,
      snapToStep,
      snapFn,
      stepMinutes,
      scrollPosition.scrollLeft,
      scrollPosition.scrollTop,
      viewportSize.w,
      viewportSize.h,
      onUserInteraction
    ]
  );
  const handlePointerDown = (0, import_react.useCallback)(
    (e) => {
      onUserInteraction == null ? void 0 : onUserInteraction();
      if (onPointerDown) {
        e.currentTarget.setPointerCapture(e.pointerId);
        onPointerDown(e);
      }
    },
    [onPointerDown, onUserInteraction]
  );
  const handlePointerUp = (0, import_react.useCallback)(
    (e) => {
      if (onPointerUp) {
        e.currentTarget.releasePointerCapture(e.pointerId);
        onPointerUp(e);
      }
    },
    [onPointerUp]
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `pisell-time-navigator-gesture pisell-time-navigator-gesture--${orientation}`,
      onClick: handleClick,
      onKeyDown: handleKeyDown,
      onPointerDown: handlePointerDown,
      onPointerMove,
      onPointerUp: handlePointerUp,
      onPointerLeave,
      role: "slider",
      tabIndex: 0,
      "aria-label": "Time"
    },
    children
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  GestureLayer
});
