"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const Vue = require("vue");
const index = require("../../../../@popperjs/core/dist/index.js");
const fromPairs = require("../../../../lodash-es/fromPairs.js");
const P = (o, i, u = {}) => {
  const p = {
    name: "updateState",
    enabled: true,
    phase: "write",
    fn: ({ state: t }) => {
      const a = g(t);
      Object.assign(l.value, a);
    },
    requires: ["computeStyles"]
  }, s = Vue.computed(() => {
    const { onFirstUpdate: t, placement: a, strategy: m, modifiers: y } = Vue.unref(u);
    return {
      onFirstUpdate: t,
      placement: a || "bottom",
      strategy: m || "absolute",
      modifiers: [
        ...y || [],
        p,
        { name: "applyStyles", enabled: false }
      ]
    };
  }), r = Vue.shallowRef(), l = Vue.ref({
    styles: {
      popper: {
        position: Vue.unref(s).strategy,
        left: "0",
        top: "0"
      },
      arrow: {
        position: "absolute"
      }
    },
    attributes: {}
  }), c = () => {
    r.value && (r.value.destroy(), r.value = void 0);
  };
  return Vue.watch(s, (t) => {
    const a = Vue.unref(r);
    a && a.setOptions(t);
  }, {
    deep: true
  }), Vue.watch([o, i], ([t, a]) => {
    c(), !(!t || !a) && (r.value = index.createPopper(t, a, Vue.unref(s)));
  }), Vue.onBeforeUnmount(() => {
    c();
  }), {
    state: Vue.computed(() => {
      var t;
      return { ...((t = Vue.unref(r)) == null ? void 0 : t.state) || {} };
    }),
    styles: Vue.computed(() => Vue.unref(l).styles),
    attributes: Vue.computed(() => Vue.unref(l).attributes),
    update: () => {
      var t;
      return (t = Vue.unref(r)) == null ? void 0 : t.update();
    },
    forceUpdate: () => {
      var t;
      return (t = Vue.unref(r)) == null ? void 0 : t.forceUpdate();
    },
    instanceRef: Vue.computed(() => Vue.unref(r))
  };
};
function g(o) {
  const i = Object.keys(o.elements), u = fromPairs.default(i.map((s) => [s, o.styles[s] || {}])), p = fromPairs.default(i.map((s) => [s, o.attributes[s]]));
  return {
    styles: u,
    attributes: p
  };
}
exports.usePopper = P;
