const p = (r, s, c) => Math.min(c, Math.max(s, r));
function b(r) {
  const {
    horizontalContainerRef: s,
    verticalContainerRef: c,
    leftPaneSize: z,
    topPaneSize: m,
    horizontalMin: y = 20,
    horizontalMax: R = 80,
    verticalMin: S = 25,
    verticalMax: h = 75
  } = r;
  let l;
  const a = () => {
    l?.(), l = void 0;
  }, u = (o, e, n) => {
    o.preventDefault(), a();
    const t = document.body.style.userSelect, i = document.body.style.cursor;
    document.body.style.userSelect = "none", document.body.style.cursor = n;
    const d = (w) => {
      e(w);
    }, v = () => {
      a();
    };
    window.addEventListener("pointermove", d), window.addEventListener("pointerup", v, { once: !0 }), l = () => {
      window.removeEventListener("pointermove", d), window.removeEventListener("pointerup", v), document.body.style.userSelect = t, document.body.style.cursor = i;
    };
  };
  return {
    onHorizontalResizeStart: (o) => {
      const e = s.value;
      e && u(
        o,
        (n) => {
          const t = e.getBoundingClientRect(), i = (n.clientX - t.left) / t.width * 100;
          z.value = p(i, y, R);
        },
        "col-resize"
      );
    },
    onVerticalResizeStart: (o) => {
      const e = c.value;
      e && u(
        o,
        (n) => {
          const t = e.getBoundingClientRect(), i = (n.clientY - t.top) / t.height * 100;
          m.value = p(i, S, h);
        },
        "row-resize"
      );
    },
    stopActiveResize: a
  };
}
export {
  b as useSplitResize
};
