import { top as g, left as O, right as F, end as $, bottom as B } from "../enums.js";
import T from "../dom-utils/getOffsetParent.js";
import H from "../dom-utils/getWindow.js";
import k from "../dom-utils/getDocumentElement.js";
import q from "../dom-utils/getComputedStyle.js";
import z from "../utils/getBasePlacement.js";
import G from "../utils/getVariation.js";
import { round as X } from "../utils/math.js";
var I = {
  top: "auto",
  right: "auto",
  bottom: "auto",
  left: "auto"
};
function J(e, t) {
  var p = e.x, s = e.y, o = t.devicePixelRatio || 1;
  return {
    x: X(p * o) / o || 0,
    y: X(s * o) / o || 0
  };
}
function Y(e) {
  var t, p = e.popper, s = e.popperRect, o = e.placement, c = e.variation, l = e.offsets, d = e.position, u = e.gpuAcceleration, m = e.adaptive, f = e.roundOffsets, w = e.isFixed, h = l.x, i = h === void 0 ? 0 : h, b = l.y, a = b === void 0 ? 0 : b, S = typeof f == "function" ? f({
    x: i,
    y: a
  }) : {
    x: i,
    y: a
  };
  i = S.x, a = S.y;
  var A = l.hasOwnProperty("x"), D = l.hasOwnProperty("y"), y = O, x = g, n = window;
  if (m) {
    var r = T(p), R = "clientHeight", j = "clientWidth";
    if (r === H(p) && (r = k(p), q(r).position !== "static" && d === "absolute" && (R = "scrollHeight", j = "scrollWidth")), r = r, o === g || (o === O || o === F) && c === $) {
      x = B;
      var C = w && r === n && n.visualViewport ? n.visualViewport.height : (
        // $FlowFixMe[prop-missing]
        r[R]
      );
      a -= C - s.height, a *= u ? 1 : -1;
    }
    if (o === O || (o === g || o === B) && c === $) {
      y = F;
      var E = w && r === n && n.visualViewport ? n.visualViewport.width : (
        // $FlowFixMe[prop-missing]
        r[j]
      );
      i -= E - s.width, i *= u ? 1 : -1;
    }
  }
  var V = Object.assign({
    position: d
  }, m && I), W = f === !0 ? J({
    x: i,
    y: a
  }, H(p)) : {
    x: i,
    y: a
  };
  if (i = W.x, a = W.y, u) {
    var v;
    return Object.assign({}, V, (v = {}, v[x] = D ? "0" : "", v[y] = A ? "0" : "", v.transform = (n.devicePixelRatio || 1) <= 1 ? "translate(" + i + "px, " + a + "px)" : "translate3d(" + i + "px, " + a + "px, 0)", v));
  }
  return Object.assign({}, V, (t = {}, t[x] = D ? a + "px" : "", t[y] = A ? i + "px" : "", t.transform = "", t));
}
function K(e) {
  var t = e.state, p = e.options, s = p.gpuAcceleration, o = s === void 0 ? !0 : s, c = p.adaptive, l = c === void 0 ? !0 : c, d = p.roundOffsets, u = d === void 0 ? !0 : d, m = {
    placement: z(t.placement),
    variation: G(t.placement),
    popper: t.elements.popper,
    popperRect: t.rects.popper,
    gpuAcceleration: o,
    isFixed: t.options.strategy === "fixed"
  };
  t.modifiersData.popperOffsets != null && (t.styles.popper = Object.assign({}, t.styles.popper, Y(Object.assign({}, m, {
    offsets: t.modifiersData.popperOffsets,
    position: t.options.strategy,
    adaptive: l,
    roundOffsets: u
  })))), t.modifiersData.arrow != null && (t.styles.arrow = Object.assign({}, t.styles.arrow, Y(Object.assign({}, m, {
    offsets: t.modifiersData.arrow,
    position: "absolute",
    adaptive: !1,
    roundOffsets: u
  })))), t.attributes.popper = Object.assign({}, t.attributes.popper, {
    "data-popper-placement": t.placement
  });
}
const tt = {
  name: "computeStyles",
  enabled: !0,
  phase: "beforeWrite",
  fn: K,
  data: {}
};
export {
  tt as default,
  Y as mapToStyles
};
//# sourceMappingURL=computeStyles.js.map
