"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _core = require("@popperjs/core");
const maxSize = {
  name: 'maxSize',
  enabled: true,
  phase: 'main',
  requiresIfExists: ['offset', 'preventOverflow', 'flip'],
  // setting proper types is problematic due to the override at the end of this function
  // we are also importing ref from popper, so we do not have control over it

  fn: function fn(_ref) {
    const state = _ref.state;
    const name = _ref.name;
    const options = _ref.options;
    const overflow = (0, _core.detectOverflow)(state, options);
    const secondRef = state.modifiersData.preventOverflow || {
      x: 0,
      y: 0
    };
    const x = secondRef.x;
    const y = secondRef.y;
    const stateRectsPopper = state.rects.popper;
    const width = stateRectsPopper.width;
    const height = stateRectsPopper.height;
    const statePlacementSplit = state.placement.split('-');
    const basePlacement = statePlacementSplit[0];
    const widthProp = basePlacement === 'left' ? 'left' : 'right';
    const heightProp = basePlacement === 'top' ? 'top' : 'bottom';
    state.modifiersData[name] = {
      width: width - overflow[widthProp] - x,
      height: height - overflow[heightProp] - y
    };
  }
};
var _default = exports.default = maxSize;