import L from "./dom-utils/getCompositeRect.es.js";
import U from "./dom-utils/getLayoutRect.es.js";
import D from "./dom-utils/listScrollParents.es.js";
import V from "./dom-utils/getOffsetParent.es.js";
import j from "./dom-utils/getComputedStyle.es.js";
import B from "./utils/orderModifiers.es.js";
import q from "./utils/debounce.es.js";
import A from "./utils/validateModifiers.es.js";
import C from "./utils/uniqueBy.es.js";
import S from "./utils/getBasePlacement.es.js";
import x from "./utils/mergeByName.es.js";
import { isElement as G } from "./dom-utils/instanceOf.es.js";
import { auto as $ } from "./enums.es.js";
var T = "Popper: Invalid reference or popper argument provided. They must be either a DOM element or virtual element.", z = "Popper: An infinite loop in the modifiers cycle has been detected! The cycle has been interrupted to prevent a browser crash.", F = {
  placement: "bottom",
  modifiers: [],
  strategy: "absolute"
};
function I() {
  for (var m = arguments.length, u = new Array(m), f = 0; f < m; f++)
    u[f] = arguments[f];
  return !u.some(function(g) {
    return !(g && typeof g.getBoundingClientRect == "function");
  });
}
function ie(m) {
  m === void 0 && (m = {});
  var u = m, f = u.defaultModifiers, g = f === void 0 ? [] : f, R = u.defaultOptions, h = R === void 0 ? F : R;
  return function(d, E, l) {
    l === void 0 && (l = h);
    var e = {
      placement: "bottom",
      orderedModifiers: [],
      options: Object.assign({}, F, h),
      modifiersData: {},
      elements: {
        reference: d,
        popper: E
      },
      attributes: {},
      styles: {}
    }, O = [], y = !1, s = {
      state: e,
      setOptions: function(n) {
        var p = typeof n == "function" ? n(e.options) : n;
        w(), e.options = Object.assign({}, h, e.options, p), e.scrollParents = {
          reference: G(d) ? D(d) : d.contextElement ? D(d.contextElement) : [],
          popper: D(E)
        };
        var i = B(x([].concat(g, e.options.modifiers)));
        if (e.orderedModifiers = i.filter(function(t) {
          return t.enabled;
        }), process.env.NODE_ENV !== "production") {
          var c = C([].concat(i, e.options.modifiers), function(t) {
            var P = t.name;
            return P;
          });
          if (A(c), S(e.options.placement) === $) {
            var a = e.orderedModifiers.find(function(t) {
              var P = t.name;
              return P === "flip";
            });
            a || console.error(['Popper: "auto" placements require the "flip" modifier be', "present and enabled to work."].join(" "));
          }
          var o = j(E), v = o.marginTop, b = o.marginRight, N = o.marginBottom, M = o.marginLeft;
          [v, b, N, M].some(function(t) {
            return parseFloat(t);
          }) && console.warn(['Popper: CSS "margin" styles cannot be used to apply padding', "between the popper and its reference element or boundary.", "To replicate margin, use the `offset` modifier, as well as", "the `padding` option in the `preventOverflow` and `flip`", "modifiers."].join(" "));
        }
        return _(), s.update();
      },
      forceUpdate: function() {
        if (!y) {
          var n = e.elements, p = n.reference, i = n.popper;
          if (!I(p, i)) {
            process.env.NODE_ENV !== "production" && console.error(T);
            return;
          }
          e.rects = {
            reference: L(p, V(i), e.options.strategy === "fixed"),
            popper: U(i)
          }, e.reset = !1, e.placement = e.options.placement, e.orderedModifiers.forEach(function(t) {
            return e.modifiersData[t.name] = Object.assign({}, t.data);
          });
          for (var c = 0, a = 0; a < e.orderedModifiers.length; a++) {
            if (process.env.NODE_ENV !== "production" && (c += 1, c > 100)) {
              console.error(z);
              break;
            }
            if (e.reset === !0) {
              e.reset = !1, a = -1;
              continue;
            }
            var o = e.orderedModifiers[a], v = o.fn, b = o.options, N = b === void 0 ? {} : b, M = o.name;
            typeof v == "function" && (e = v({
              state: e,
              options: N,
              name: M,
              instance: s
            }) || e);
          }
        }
      },
      update: q(function() {
        return new Promise(function(r) {
          s.forceUpdate(), r(e);
        });
      }),
      destroy: function() {
        w(), y = !0;
      }
    };
    if (!I(d, E))
      return process.env.NODE_ENV !== "production" && console.error(T), s;
    s.setOptions(l).then(function(r) {
      !y && l.onFirstUpdate && l.onFirstUpdate(r);
    });
    function _() {
      e.orderedModifiers.forEach(function(r) {
        var n = r.name, p = r.options, i = p === void 0 ? {} : p, c = r.effect;
        if (typeof c == "function") {
          var a = c({
            state: e,
            name: n,
            instance: s,
            options: i
          }), o = function() {
          };
          O.push(a || o);
        }
      });
    }
    function w() {
      O.forEach(function(r) {
        return r();
      }), O = [];
    }
    return s;
  };
}
export {
  ie as popperGenerator
};
//# sourceMappingURL=createPopper.es.js.map
