import { defineComponent as $, reactive as b, watch as u, ref as y, toRef as x, computed as N, onUnmounted as P, createBlock as v, openBlock as p, resolveDynamicComponent as R, mergeProps as V, withCtx as k, renderSlot as h, createCommentVNode as w, Teleport as g, createVNode as C, Transition as j, createElementBlock as z, withModifiers as A, normalizeStyle as T, unref as W, createElementVNode as M, normalizeClass as q } from "vue";
/* empty css                */
import { useTooltipPosition as F } from "./useTooltipPosition.js";
import { throttle as K, delay as L, timeout as U } from "../../helpers/utils.js";
import { useClickOutside as G } from "../../composition/useClickOutside.js";
import H from "./Beak.vue.js";
import { tMap as m } from "./global.js";
const I = {
  name: "PlTooltip"
}, te = /* @__PURE__ */ $({
  ...I,
  props: {
    openDelay: { default: 100 },
    closeDelay: { default: 1e3 },
    position: { default: "top" },
    hide: { type: Boolean },
    gap: { default: 8 },
    element: { default: "div" },
    maxWidth: { default: "300px" }
  },
  emits: ["tooltip:close"],
  setup(i, { emit: B }) {
    const D = B, s = Symbol(), t = i, e = b({
      open: !1,
      over: !1,
      tooltipOpen: !1,
      key: Symbol()
    });
    m.set(s, () => l()), u(
      () => e.open,
      (o) => {
        requestAnimationFrame(() => {
          e.tooltipOpen = o;
        });
      }
    );
    let f = () => {
    };
    const O = K(() => window.dispatchEvent(new CustomEvent("adjust")), 1e3), S = () => {
      e.open = !0;
      for (const [o, n] of m.entries())
        o !== s && n();
    }, l = () => {
      e.open = !1, D("tooltip:close");
    }, r = async () => {
      t.hide || (O(), e.over = !0, f(), await L(t.openDelay ?? 100), e.over && S());
    }, c = () => {
      e.over = !1, f = U(() => {
        e.over || l();
      }, t.closeDelay);
    };
    u(
      () => t.hide,
      (o) => {
        o && l();
      }
    );
    const a = y(), d = y(), E = F(a, x(t));
    G([a, d], () => l());
    const _ = N(() => ({
      "--pl-tooltip-max-width": t.maxWidth
    }));
    return P(() => {
      m.delete(s);
    }), (o, n) => (p(), v(R(i.element), V(o.$attrs, {
      ref_key: "rootRef",
      ref: a,
      onClick: r,
      onMouseover: r,
      onMouseleave: c
    }), {
      default: k(() => [
        h(o.$slots, "default"),
        o.$slots.tooltip && e.open ? (p(), v(g, {
          key: 0,
          to: "body"
        }, [
          C(j, { name: "tooltip-transition" }, {
            default: k(() => [
              e.tooltipOpen ? (p(), z("div", {
                key: 0,
                class: "pl-tooltip__container",
                style: T(W(E)),
                onClick: n[0] || (n[0] = A(() => {
                }, ["stop"]))
              }, [
                M("div", {
                  ref_key: "tooltip",
                  ref: d,
                  class: q(["pl-tooltip", i.position]),
                  style: T(_.value),
                  onMouseover: r,
                  onMouseleave: c
                }, [
                  M("div", null, [
                    h(o.$slots, "tooltip")
                  ]),
                  C(H)
                ], 38)
              ], 4)) : w("", !0)
            ]),
            _: 3
          })
        ])) : w("", !0)
      ]),
      _: 3
    }, 16));
  }
});
export {
  te as default
};
//# sourceMappingURL=PlTooltip.vue.js.map
