"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../../../../hooks/use-popper/index.js");
const constants = require("../constants.js");
const utils = require("../utils.js");
const index$1 = require("../../../../../node_modules/@vueuse/core/index.js");
const Vue = require("vue");
const isUndefined = require("../../../../../../lodash-es/isUndefined.js");
const DEFAULT_ARROW_OFFSET = 0;
const usePopperContent = (props) => {
  const { popperInstanceRef, contentRef, triggerRef, role } = Vue.inject(constants.POPPER_INJECTION_KEY, void 0);
  const arrowRef = Vue.ref();
  const arrowOffset = Vue.computed(() => props.arrowOffset);
  const eventListenerModifier = Vue.computed(() => {
    return {
      name: "eventListeners",
      enabled: !!props.visible
    };
  });
  const arrowModifier = Vue.computed(() => {
    const arrowEl = Vue.unref(arrowRef);
    const offset = Vue.unref(arrowOffset) ?? DEFAULT_ARROW_OFFSET;
    return {
      name: "arrow",
      enabled: !isUndefined.default(arrowEl),
      options: {
        element: arrowEl,
        padding: offset
      }
    };
  });
  const options = Vue.computed(() => {
    return {
      onFirstUpdate: () => {
        update();
      },
      ...utils.buildPopperOptions(props, [Vue.unref(arrowModifier), Vue.unref(eventListenerModifier)])
    };
  });
  const computedReference = Vue.computed(() => utils.unwrapMeasurableEl(props.referenceEl) || Vue.unref(triggerRef));
  const { attributes, state, styles, update, forceUpdate, instanceRef } = index.usePopper(computedReference, contentRef, options);
  Vue.watch(instanceRef, (instance) => popperInstanceRef.value = instance, { flush: "sync" });
  Vue.onMounted(() => {
    Vue.watch(() => {
      var _a, _b;
      return (_b = (_a = Vue.unref(computedReference)) == null ? void 0 : _a.getBoundingClientRect) == null ? void 0 : _b.call(_a);
    }, () => {
      update();
    });
  });
  let stopResizeObserver;
  Vue.watch(() => props.visible, (visible) => {
    stopResizeObserver == null ? void 0 : stopResizeObserver();
    stopResizeObserver = void 0;
    if (visible) stopResizeObserver = index$1.useResizeObserver(contentRef, update).stop;
  });
  Vue.onBeforeUnmount(() => {
    popperInstanceRef.value = void 0;
    stopResizeObserver == null ? void 0 : stopResizeObserver();
    stopResizeObserver = void 0;
  });
  return {
    attributes,
    arrowRef,
    contentRef,
    instanceRef,
    state,
    styles,
    role,
    forceUpdate,
    update
  };
};
exports.usePopperContent = usePopperContent;
