import { debounce as v } from "es-toolkit";
import { nextTick as d } from "vue";
import m from "../utils/calculateElementOverflow.js";
var u = /* @__PURE__ */ ((t) => (t.Bottom = "bottom", t.Left = "left", t.Right = "right", t.Top = "top", t))(u || {});
const p = "top", b = Object.values(u);
function y(t) {
  let o = p;
  return b.forEach((e) => {
    if (t[e])
      return o = e, !1;
  }), o;
}
function c(t, o) {
  if (o.value) {
    const e = document.createElement("div"), r = `tooltip tooltip--${y(o.modifiers)}`;
    e.classList.value = r, e.setAttribute("role", "tooltip"), e.innerHTML = o.value, t.appendChild(e), t.classList.add("tooltip-toggle"), t.tabIndex = 0, d().then(() => {
      if (r.includes("bottom") || r.includes("top")) {
        const s = m(e);
        if (s != null && s.value) {
          const l = s.side === "right" ? "-" : "";
          e.style.setProperty("--offset", `${l}${s.value}`);
        }
      }
    });
  }
}
function n(t) {
  const o = t.querySelector(".tooltip");
  t.classList.remove("tooltip-toggle"), t.style.removeProperty("--offset"), o && o.remove();
}
function i(t, o) {
  n(t), c(t, o), t.cachedVal !== o.value && (t.cachedVal = o.value, f(t), a(t, o));
}
function a(t, o) {
  t.cachedVal = o.value, "ResizeObserver" in window && "body" in document && (t.observer = new ResizeObserver(
    v(() => {
      i(t, o);
    }, 300)
  ), t.observer.observe(document.body));
}
function f(t) {
  t.observer && document.body && (t.observer.unobserve(document.body), t.observer.disconnect(), t.observer = void 0);
}
const V = {
  beforeMount(t, o) {
    c(t, o), a(t, o);
  },
  updated(t, o) {
    const { oldValue: e, value: r } = o;
    e !== r && i(t, o);
  },
  unmounted(t) {
    f(t), n(t);
  }
};
export {
  u as Positions,
  V as default
};
//# sourceMappingURL=tooltip.js.map
