import { ref as a, onMounted as b, nextTick as S, onBeforeUnmount as A, watch as E, createBlock as D, openBlock as M, unref as k, withCtx as s, renderSlot as i, createElementVNode as L, normalizeProps as I, guardReactiveProps as N } from "vue";
import { getUniqueString as $ } from "../../common/utils/index.js";
import { TOOLTIP_DELAY_MS as C, TOOLTIP_DIRECTIONS as j } from "../tooltip/tooltip-constants.js";
import B from "../popover/popover.js";
import { POPOVER_APPEND_TO_VALUES as F, POPOVER_PADDING_CLASSES as R } from "../popover/popover-constants.js";
const z = {
  __name: "hovercard",
  props: {
    /**
       * Fade transition when the content display is toggled.
       * @type boolean
       * @values true, false
       */
    transition: {
      type: Boolean,
      default: !1
    },
    /**
       * Controls whether the hovercard is shown. Leaving this null will have the hovercard trigger on hover by default.
       * If you set this value, the default trigger behavior will be disabled, and you can control it as you need.
       * Supports .sync modifier
       * @values null, true, false
       */
    open: {
      type: Boolean,
      default: null
    },
    /**
        * If the popover does not fit in the direction described by "placement",
       * it will attempt to change its direction to the "fallbackPlacements".
       * @see https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements"
       */
    fallbackPlacements: {
      type: Array,
      default: () => ["auto"]
    },
    /**
       * The direction the popover displays relative to the anchor.
       * @see https://atomiks.github.io/tippyjs/v6/all-props/#placement"
       * @values top, top-start, top-end,
       * right, right-start, right-end,
       * left, left-start, left-end,
       * bottom, bottom-start, bottom-end,
       * auto, auto-start, auto-end
       */
    placement: {
      type: String,
      default: "top-start",
      validator(e) {
        return j.includes(e);
      }
    },
    /**
       * Padding size class for the popover content.
       * @values none, small, medium, large
       */
    padding: {
      type: String,
      default: "large",
      validator: (e) => Object.keys(R).some((n) => n === e)
    },
    /**
       * Displaces the content box from its anchor element
       * by the specified number of pixels.
       * @see https://atomiks.github.io/tippyjs/v6/all-props/#offset"
       */
    offset: {
      type: Array,
      default: () => [0, 16]
    },
    /**
       * The id of the tooltip
       */
    id: {
      type: String,
      default() {
        return $();
      }
    },
    /**
       * Additional class name for the header content wrapper element.
       */
    headerClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
       * Additional class name for the footer content wrapper element.
       */
    footerClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
       * Additional class name for the dialog element.
       */
    dialogClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
       * Additional class name for the content wrapper element.
       */
    contentClass: {
      type: [String, Array, Object],
      default: ""
    },
    /**
       * Sets the element to which the popover is going to append to.
       * 'body' will append to the nearest body (supports shadow DOM).
       * @values 'body', 'parent', HTMLElement,
       */
    appendTo: {
      type: [HTMLElement, String],
      default: "body",
      validator: (e) => F.includes(e) || e instanceof HTMLElement
    },
    /**
     * The enter delay in milliseconds before the hovercard is shown.
     * @type number
     */
    enterDelay: {
      type: Number,
      default: C
    },
    /**
     * The leave delay in milliseconds before the hovercard is hidden.
     * @type number
     */
    leaveDelay: {
      type: Number,
      default: C
    }
  },
  emits: [
    /**
     * Emitted when hovercard is shown or hidden
     *
     * @event opened
     * @type {Boolean | Array}
     */
    "opened"
  ],
  setup(e) {
    const n = e, l = a(n.open), c = a(!1), d = a(!1), f = a(null), v = a(null), m = a(null), u = a(null), p = a(null);
    b(() => {
      S(() => {
        var t, r, o;
        m.value = (o = (r = (t = p.value) == null ? void 0 : t.$refs) == null ? void 0 : r.anchor) == null ? void 0 : o.firstElementChild, u.value = new MutationObserver(() => {
          m.value && !m.value.isConnected && (l.value = !1);
        }), u.value.observe(document.body, {
          childList: !0,
          subtree: !0
        });
      });
    }), A(() => {
      u.value && u.value.disconnect(), clearTimeout(f), clearTimeout(v);
    }), E(() => n.open, (t) => {
      l.value = t;
    }, { immediate: !0 });
    function y() {
      n.open === null && (clearTimeout(v.value), f.value = setTimeout(() => {
        l.value = !0;
      }, n.enterDelay));
    }
    function O() {
      n.open === null && (clearTimeout(f.value), v.value = setTimeout(() => {
        l.value = !1;
      }, n.leaveDelay));
    }
    function g() {
      d.value = !0, y();
    }
    function T() {
      d.value = !1, !c.value && O();
    }
    function h() {
      c.value = !0, y();
    }
    function P() {
      c.value = !1, d.value || O();
    }
    return (t, r) => (M(), D(k(B), {
      id: e.id,
      ref_key: "popover",
      ref: p,
      open: l.value,
      placement: e.placement,
      "content-class": e.contentClass,
      "dialog-class": e.dialogClass,
      "fallback-placements": e.fallbackPlacements,
      padding: e.padding,
      transition: e.transition ? "fade" : null,
      offset: e.offset,
      modal: !1,
      "initial-focus-element": "none",
      "header-class": e.headerClass,
      "footer-class": e.footerClass,
      "append-to": e.appendTo,
      "data-qa": "dt-hovercard",
      "enter-delay": e.enterDelay,
      "leave-delay": e.leaveDelay,
      onOpened: r[0] || (r[0] = (o) => t.$emit("opened", o)),
      onMouseenterPopover: g,
      onMouseleavePopover: T,
      onMouseenterPopoverAnchor: g,
      onMouseleavePopoverAnchor: T
    }, {
      anchor: s(({ attrs: o }) => [
        i(t.$slots, "anchor", I(N(o)))
      ]),
      content: s(() => [
        L("div", {
          onFocusin: h,
          onFocusout: P
        }, [
          i(t.$slots, "content")
        ], 32)
      ]),
      headerContent: s(() => [
        i(t.$slots, "headerContent")
      ]),
      footerContent: s(() => [
        i(t.$slots, "footerContent")
      ]),
      _: 3
    }, 8, ["id", "open", "placement", "content-class", "dialog-class", "fallback-placements", "padding", "transition", "offset", "header-class", "footer-class", "append-to", "enter-delay", "leave-delay"]));
  }
};
export {
  z as default
};
//# sourceMappingURL=hovercard.js.map
