import c from "./index-getNodeName.js";
import { isHTMLElement as f } from "./index-instanceOf.js";
function p(l) {
  var e = l.state;
  Object.keys(e.elements).forEach(function(t) {
    var r = e.styles[t] || {}, s = e.attributes[t] || {}, a = e.elements[t];
    !f(a) || !c(a) || (Object.assign(a.style, r), Object.keys(s).forEach(function(o) {
      var i = s[o];
      i === !1 ? a.removeAttribute(o) : a.setAttribute(o, i === !0 ? "" : i);
    }));
  });
}
function y(l) {
  var e = l.state, t = {
    popper: {
      position: e.options.strategy,
      left: "0",
      top: "0",
      margin: "0"
    },
    arrow: {
      position: "absolute"
    },
    reference: {}
  };
  return Object.assign(e.elements.popper.style, t.popper), e.styles = t, e.elements.arrow && Object.assign(e.elements.arrow.style, t.arrow), function() {
    Object.keys(e.elements).forEach(function(r) {
      var s = e.elements[r], a = e.attributes[r] || {}, o = Object.keys(e.styles.hasOwnProperty(r) ? e.styles[r] : t[r]), i = o.reduce(function(n, u) {
        return n[u] = "", n;
      }, {});
      !f(s) || !c(s) || (Object.assign(s.style, i), Object.keys(a).forEach(function(n) {
        s.removeAttribute(n);
      }));
    });
  };
}
const m = {
  name: "applyStyles",
  enabled: !0,
  phase: "write",
  fn: p,
  effect: y,
  requires: ["computeStyles"]
};
export {
  m as default
};
