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/floorMap/ReservationHudDrawerHandle.tsx
var ReservationHudDrawerHandle_exports = {};
__export(ReservationHudDrawerHandle_exports, {
  ReservationHudDrawerHandle: () => ReservationHudDrawerHandle,
  default: () => ReservationHudDrawerHandle_default
});
module.exports = __toCommonJS(ReservationHudDrawerHandle_exports);
var import_react = __toESM(require("react"));
var DRAG_TRANSITION_NONE = "none";
var SETTLE_TRANSITION = "transform 0.2s ease-out";
var ReservationHudDrawerHandle = ({ onClose, closeOffsetPx = 80, drawerRef }) => {
  const startYRef = (0, import_react.useRef)(null);
  const movedRef = (0, import_react.useRef)(false);
  const lastDyRef = (0, import_react.useRef)(0);
  const [dragging, setDragging] = (0, import_react.useState)(false);
  const applyDrawerTranslate = (0, import_react.useCallback)(
    (dy, withTransition) => {
      const el = drawerRef == null ? void 0 : drawerRef.current;
      if (!el) return;
      const clamped = dy < 0 ? 0 : dy;
      el.style.transition = withTransition ? SETTLE_TRANSITION : DRAG_TRANSITION_NONE;
      el.style.transform = clamped === 0 ? "" : `translateY(${clamped}px)`;
    },
    [drawerRef]
  );
  const resetDrawerTranslate = (0, import_react.useCallback)(() => {
    const el = drawerRef == null ? void 0 : drawerRef.current;
    if (!el) return;
    el.style.transition = "";
    el.style.transform = "";
  }, [drawerRef]);
  const handlePointerDown = (0, import_react.useCallback)(
    (event) => {
      if (event.button !== 0) return;
      startYRef.current = event.clientY;
      movedRef.current = false;
      lastDyRef.current = 0;
      setDragging(true);
      event.currentTarget.setPointerCapture(event.pointerId);
    },
    []
  );
  const handlePointerMove = (0, import_react.useCallback)(
    (event) => {
      const startY = startYRef.current;
      if (startY == null) return;
      const dy = event.clientY - startY;
      lastDyRef.current = dy;
      if (Math.abs(dy) > 4) movedRef.current = true;
      if (dy > 0) applyDrawerTranslate(dy, false);
      else applyDrawerTranslate(0, false);
    },
    [applyDrawerTranslate]
  );
  const finishGesture = (0, import_react.useCallback)(
    (event) => {
      const startY = startYRef.current;
      startYRef.current = null;
      setDragging(false);
      try {
        event.currentTarget.releasePointerCapture(event.pointerId);
      } catch {
      }
      if (startY == null) {
        resetDrawerTranslate();
        return;
      }
      const dy = lastDyRef.current;
      if (!movedRef.current) {
        resetDrawerTranslate();
        onClose();
        return;
      }
      if (dy >= closeOffsetPx) {
        const el2 = drawerRef == null ? void 0 : drawerRef.current;
        if (el2) {
          el2.style.transition = SETTLE_TRANSITION;
          el2.style.transform = "translateY(100%)";
          window.setTimeout(() => {
            onClose();
          }, 200);
        } else {
          onClose();
        }
        return;
      }
      applyDrawerTranslate(0, true);
      const el = drawerRef == null ? void 0 : drawerRef.current;
      if (el) {
        const cleanup = () => {
          el.style.transition = "";
          el.removeEventListener("transitionend", cleanup);
        };
        el.addEventListener("transitionend", cleanup);
      }
    },
    [
      applyDrawerTranslate,
      closeOffsetPx,
      drawerRef,
      onClose,
      resetDrawerTranslate
    ]
  );
  const handleKeyDown = (0, import_react.useCallback)(
    (event) => {
      if (event.key === "Enter" || event.key === " ") {
        event.preventDefault();
        onClose();
      }
    },
    [onClose]
  );
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "pisell-reservation-hud-drawer-handle" + (dragging ? " pisell-reservation-hud-drawer-handle--dragging" : ""),
      role: "button",
      tabIndex: 0,
      "aria-label": "Close drawer",
      onPointerDown: handlePointerDown,
      onPointerMove: handlePointerMove,
      onPointerUp: finishGesture,
      onPointerCancel: finishGesture,
      onKeyDown: handleKeyDown
    },
    /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: "pisell-reservation-hud-drawer-handle-bar",
        "aria-hidden": "true"
      }
    )
  );
};
var ReservationHudDrawerHandle_default = ReservationHudDrawerHandle;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ReservationHudDrawerHandle
});
