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