"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;
