"use client";
import { jsx } from "react/jsx-runtime";
import * as React from "react";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { translateWithFallback } from "@open-mercato/shared/lib/i18n/translate";
function LaneResizeHandle({ onResize, onResizeEnd, onReset }) {
  const t = useT();
  const dragStateRef = React.useRef(null);
  const [isActive, setIsActive] = React.useState(false);
  const stopDrag = React.useCallback(
    (handlers) => {
      window.removeEventListener("pointermove", handlers.move);
      window.removeEventListener("pointerup", handlers.up);
      window.removeEventListener("pointercancel", handlers.up);
      document.body.style.cursor = "";
      document.body.style.userSelect = "";
      setIsActive(false);
      onResizeEnd?.();
      dragStateRef.current = null;
    },
    [onResizeEnd]
  );
  const handlePointerDown = React.useCallback(
    (event) => {
      if (event.button !== 0 && event.pointerType === "mouse") return;
      event.preventDefault();
      event.stopPropagation();
      setIsActive(true);
      document.body.style.cursor = "col-resize";
      document.body.style.userSelect = "none";
      dragStateRef.current = { lastX: event.clientX };
      const handlers = {
        move: (e) => {
          if (!dragStateRef.current) return;
          const delta = e.clientX - dragStateRef.current.lastX;
          if (delta !== 0) {
            dragStateRef.current.lastX = e.clientX;
            onResize(delta);
          }
        },
        up: () => stopDrag(handlers)
      };
      window.addEventListener("pointermove", handlers.move);
      window.addEventListener("pointerup", handlers.up);
      window.addEventListener("pointercancel", handlers.up);
    },
    [onResize, stopDrag]
  );
  const handleDoubleClick = React.useCallback(
    (event) => {
      event.preventDefault();
      event.stopPropagation();
      onReset?.();
    },
    [onReset]
  );
  return /* @__PURE__ */ jsx(
    "div",
    {
      role: "separator",
      "aria-orientation": "vertical",
      "aria-label": translateWithFallback(
        t,
        "customers.deals.kanban.lane.resizeHandle",
        "Drag to resize column. Double-click to reset width."
      ),
      onPointerDown: handlePointerDown,
      onDoubleClick: handleDoubleClick,
      title: translateWithFallback(
        t,
        "customers.deals.kanban.lane.resizeHandle",
        "Drag to resize \xB7 double-click to reset"
      ),
      className: `absolute -right-0.5 top-0 z-20 h-full w-1.5 cursor-col-resize touch-none select-none ${isActive ? "bg-accent-indigo/40" : "bg-transparent hover:bg-accent-indigo/20"}`
    }
  );
}
var LaneResizeHandle_default = LaneResizeHandle;
export {
  LaneResizeHandle,
  LaneResizeHandle_default as default
};
//# sourceMappingURL=LaneResizeHandle.js.map
