import { watchEffect as f, unref as h } from "vue";
import { useColumn as a } from "./useColumn.js";
import { RESIZE_GAP as z, MIN_COLUMN_WIDTH as p } from "../constants.js";
import { useMouse as y } from "../../../composition/useMouse.js";
import { useHover as g } from "../../../composition/useHover.js";
import { tapIf as l, identity as w, clamp as T } from "@milaboratories/helpers";
function I(i) {
  var s;
  const r = l((s = h(i)) == null ? void 0 : s.querySelectorAll(".th-cell"), (o) => [...o]) ?? [];
  return r.map((o) => {
    const { width: e, x: n } = o.getBoundingClientRect(), c = o.getAttribute("data-col-id");
    return w({
      colId: c,
      width: e,
      x: n,
      right: n + e
    });
  }).slice(0, r.length - 1);
}
function E(i, r) {
  const s = y(), o = g(r, {}), { data: e } = i, n = a(
    (t) => {
      l(e.resizeTh, (u) => {
        const d = e.columns.find((m) => m.id === u.colId);
        d && (d.width = T(t.width + t.diff, p, 1e4), i.adjustWidth());
      });
    },
    () => {
      e.resize = !1, e.resizeTh = void 0, document.body.style.cursor = "";
    }
  ), c = (t) => {
    e.resizeTh && (e.resize = !0, n.start({
      x: t.x,
      width: e.resizeTh.width
    }));
  };
  return f(() => {
    if (!o.value) {
      document.body.style.cursor = "";
      return;
    }
    if (e.resize)
      return;
    const t = I(r).find((u) => Math.abs(s.x - u.right) < z);
    t ? (document.body.style.cursor = "col-resize", e.resizeTh = t) : (e.resizeTh = void 0, document.body.style.cursor = "");
  }), {
    mouseDown: c
  };
}
export {
  I as getColumnPositions,
  E as useResize
};
//# sourceMappingURL=useResize.js.map
