import { ref as l, onMounted as v, onUnmounted as y, computed as p, openBlock as b, createElementBlock as g, normalizeClass as x, normalizeStyle as h, unref as $, renderSlot as s, createElementVNode as C, createCommentVNode as S } from "vue";
import { w as k } from "./index-CguVaFlt.js";
function w({ tooltip: e, chart: o, clientPosition: t, positionPreference: r = "center", defaultOffsetY: a = 24 }) {
  const u = l(0), f = l(a);
  if (e && o) {
    const { width: n, height: c } = e.getBoundingClientRect(), { right: i, left: d, bottom: m } = o.getBoundingClientRect();
    r === "center" && (t.x + n / 2 > i ? u.value = -n + (i - t.x) : t.x - n / 2 < d ? u.value = -n + (n - (t.x - d)) : u.value = -n / 2), r === "right" && (t.x + n > i ? u.value = -n + (i - t.x) : u.value = 0), r === "left" && (t.x < d + n ? u.value = -n + (n - (t.x - d)) : u.value = -n), t.y + c > m && (f.value = -c - a);
  }
  return {
    top: t.y + f.value,
    left: t.x + u.value
  };
}
function N(e, o, t) {
  v(() => e.addEventListener(o, t)), y(() => e.removeEventListener(o, t));
}
function B() {
  const e = l(0), o = l(0);
  return N(window, "mousemove", (t) => {
    e.value = t.clientX, o.value = t.clientY;
  }), { x: e, y: o };
}
const F = ["innerHTML"], L = {
  __name: "Tooltip",
  props: {
    backgroundColor: {
      type: String,
      default: "#FFFFFF"
    },
    color: {
      type: String,
      default: "#000000"
    },
    content: String,
    maxWidth: {
      type: String,
      default: "300px"
    },
    parent: {
      type: Object
    },
    show: {
      type: Boolean,
      default: !1
    },
    isCustom: {
      type: Boolean,
      default: !1
    },
    fontSize: {
      type: [Number, String],
      default: 14
    },
    borderRadius: {
      type: Number,
      default: 4
    },
    borderColor: {
      type: String,
      default: "#e1e5e8"
    },
    borderWidth: {
      type: Number,
      default: 1
    },
    backgroundOpacity: {
      type: Number,
      default: 100
    },
    position: {
      type: String,
      default: "center"
    },
    offsetY: {
      type: Number,
      default: 24
    }
  },
  setup(e) {
    const o = e, t = l(null), r = l(B()), a = p(() => w({
      tooltip: t.value,
      chart: o.parent,
      clientPosition: r.value,
      positionPreference: o.position,
      defaultOffsetY: o.offsetY
    }));
    return (u, f) => e.show ? (b(), g("div", {
      key: 0,
      ref_key: "tooltip",
      ref: t,
      class: x({ "vue-data-ui-custom-tooltip": e.isCustom, "vue-data-ui-tooltip": !e.isCustom }),
      style: h(`pointer-events:none;top:${a.value.top}px;left:${a.value.left}px;${e.isCustom ? "" : `background:${e.backgroundColor}${$(k)[e.backgroundOpacity]};color:${e.color};max-width:${e.maxWidth};font-size:${e.fontSize}px`};border-radius:${e.borderRadius}px;border:${e.borderWidth}px solid ${e.borderColor};`)
    }, [
      s(u.$slots, "tooltip-before"),
      s(u.$slots, "default"),
      C("div", { innerHTML: e.content }, null, 8, F),
      s(u.$slots, "tooltip-after")
    ], 6)) : S("", !0);
  }
};
export {
  L as _,
  B as u
};
