"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.getModifiers = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var getUnit = value => {
  if (!value) {
    return;
  }
  if (typeof value === 'string') {
    return value;
  }
  return "".concat(value, "px");
};
var calculateOffset = _ref => {
  var {
    moveBy,
    placement
  } = _ref;
  /*
   * For `right` and `left` placements, we need to flip the `x` and `y` values as Popper.JS will use
   * the first value for the main axis. As per Popper.js docs:
   *
   *   if the placement is top or bottom, the length will be the width. In case of left or right, it
   *   will be the height.
   *
   */
  if (placement != null && placement.includes('right') || placement != null && placement.includes('left')) {
    return "".concat(moveBy ? moveBy.y : 0, "px, ").concat(moveBy ? moveBy.x : 0, "px");
  }
  return "".concat(moveBy ? moveBy.x : 0, "px, ").concat(moveBy ? moveBy.y : 0, "px");
};
var resolveWidth = _ref2 => {
  var {
    width,
    minWidth,
    dynamicWidth,
    referenceWidth
  } = _ref2;
  return {
    minWidth: dynamicWidth ? "".concat(referenceWidth, "px") : getUnit(minWidth),
    width: getUnit(width) || 'auto'
  };
};
var getModifiers = _ref3 => {
  var {
    width,
    moveBy,
    appendTo,
    shouldAnimate,
    flip,
    fixed,
    placement,
    isTestEnv,
    minWidth,
    dynamicWidth
  } = _ref3;
  var preventOverflow = !fixed;
  var modifiers = {
    offset: {
      offset: calculateOffset({
        moveBy,
        placement
      })
    },
    computeStyle: {
      gpuAcceleration: !shouldAnimate
    },
    flip: {
      enabled: typeof flip !== 'undefined' ? flip : !moveBy
    },
    preventOverflow: {
      enabled: preventOverflow
    },
    hide: {
      enabled: preventOverflow
    }
  };
  if (dynamicWidth || minWidth || width) {
    modifiers.setPopperWidth = {
      enabled: true,
      order: 840,
      fn: data => {
        var {
          width: referenceWidth
        } = data.offsets.reference;
        data.styles = _objectSpread(_objectSpread({}, data.styles), resolveWidth({
          width,
          referenceWidth,
          minWidth,
          dynamicWidth
        }));
        return data;
      }
    };
  }
  if (isTestEnv) {
    modifiers.computeStyle = {
      enabled: false
    };
  }
  if (appendTo) {
    modifiers.preventOverflow = _objectSpread(_objectSpread({}, modifiers.preventOverflow), {}, {
      boundariesElement: appendTo
    });
  }
  return modifiers;
};
exports.getModifiers = getModifiers;
//# sourceMappingURL=getModifiers.js.map