'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var reactTransitionGroup = require('react-transition-group');
var classNames = require('clsx');
var Backdrop = require('@prom-ui/core/Backdrop');
var KeyPress = require('@prom-ui/core/KeyPress');
var Portal = require('@prom-ui/core/Portal');
var Media = require('@prom-ui/core/Media');
var Button = require('@prom-ui/core/Button');
var Icon = require('@prom-ui/core/Icon');
var useBodyTTag = require('@prom-ui/core/useBodyTTag');
var Close = require('@prom-ui/icons/Close');
var ArrowBack = require('@prom-ui/icons/ArrowBack');
var errcatch = require('@evo/errcatch');
var Link = require('@prom-ui/core/Link');
var PromTroubleHappens = require('@prom-ui/icons/colors/PromTroubleHappens');
var PromNoSignal = require('@prom-ui/icons/colors/PromNoSignal');
var Swipe = require('react-easy-swipe');

function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }

function _interopNamespaceCompat(e) {
  if (e && typeof e === 'object' && 'default' in e) return e;
  var n = Object.create(null);
  if (e) {
    Object.keys(e).forEach(function (k) {
      if (k !== 'default') {
        var d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: function () { return e[k]; }
        });
      }
    });
  }
  n.default = e;
  return Object.freeze(n);
}

var React__namespace = /*#__PURE__*/_interopNamespaceCompat(React);
var classNames__default = /*#__PURE__*/_interopDefaultCompat(classNames);
var Swipe__default = /*#__PURE__*/_interopDefaultCompat(Swipe);

function _iterableToArrayLimit(arr, i) {
  var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
  if (null != _i) {
    var _s,
      _e,
      _x,
      _r,
      _arr = [],
      _n = !0,
      _d = !1;
    try {
      if (_x = (_i = _i.call(arr)).next, 0 === i) {
        if (Object(_i) !== _i) return;
        _n = !1;
      } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
    } catch (err) {
      _d = !0, _e = err;
    } finally {
      try {
        if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
}
function _defineProperty(obj, key, value) {
  key = _toPropertyKey(key);
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }
  return obj;
}
function _extends() {
  _extends = Object.assign ? Object.assign.bind() : function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];
      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }
    return target;
  };
  return _extends.apply(this, arguments);
}
function _objectWithoutPropertiesLoose(source, excluded) {
  if (source == null) return {};
  var target = {};
  var sourceKeys = Object.keys(source);
  var key, i;
  for (i = 0; i < sourceKeys.length; i++) {
    key = sourceKeys[i];
    if (excluded.indexOf(key) >= 0) continue;
    target[key] = source[key];
  }
  return target;
}
function _objectWithoutProperties(source, excluded) {
  if (source == null) return {};
  var target = _objectWithoutPropertiesLoose(source, excluded);
  var key, i;
  if (Object.getOwnPropertySymbols) {
    var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
    for (i = 0; i < sourceSymbolKeys.length; i++) {
      key = sourceSymbolKeys[i];
      if (excluded.indexOf(key) >= 0) continue;
      if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
      target[key] = source[key];
    }
  }
  return target;
}
function _taggedTemplateLiteral(strings, raw) {
  if (!raw) {
    raw = strings.slice(0);
  }
  return Object.freeze(Object.defineProperties(strings, {
    raw: {
      value: Object.freeze(raw)
    }
  }));
}
function _slicedToArray(arr, i) {
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}
function _unsupportedIterableToArray(o, minLen) {
  if (!o) return;
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  var n = Object.prototype.toString.call(o).slice(8, -1);
  if (n === "Object" && o.constructor) n = o.constructor.name;
  if (n === "Map" || n === "Set") return Array.from(o);
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
  if (len == null || len > arr.length) len = arr.length;
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
  return arr2;
}
function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _toPrimitive(input, hint) {
  if (typeof input !== "object" || input === null) return input;
  var prim = input[Symbol.toPrimitive];
  if (prim !== undefined) {
    var res = prim.call(input, hint || "default");
    if (typeof res !== "object") return res;
    throw new TypeError("@@toPrimitive must return a primitive value.");
  }
  return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
  var key = _toPrimitive(arg, "string");
  return typeof key === "symbol" ? key : String(key);
}

var css = {"root":"Overlay__root___v0oYp","backdrop":"Overlay__backdrop___RvRWz","popup":"Overlay__popup___elIqJ","popup_placement_top":"Overlay__popup_placement_top___Llv4b","popup_placement_bottom":"Overlay__popup_placement_bottom___DJyNc","popup_placement_right":"Overlay__popup_placement_right___4DX3c","popup_placement_left":"Overlay__popup_placement_left___OwkR7","content":"Overlay__content___5qQ0k","header":"Overlay__header___LIk9z","header__grid":"Overlay__header__grid___SShy4","header__item":"Overlay__header__item___9fUzS","header__title":"Overlay__header__title___Vuilz Overlay__header__item___9fUzS","header__titleText":"Overlay__header__titleText___pW2Vz","header__action":"Overlay__header__action___c-A8d Overlay__header__item___9fUzS","header__actionButton":"Overlay__header__actionButton___yYG24","header__actionIcon":"Overlay__header__actionIcon___La2ok","footer":"Overlay__footer___3Ca-G","enter":"Overlay__enter___OjeZp","exit":"Overlay__exit___HiHMU","enterActive":"Overlay__enterActive___Ne-Vn","exitActive":"Overlay__exitActive___6f7f1","errorContainer":"Overlay__errorContainer___8HVeJ","errorContainerLoading":"Overlay__errorContainerLoading___zsRUN","errorIcon":"Overlay__errorIcon___w5VL8","errorTitle":"Overlay__errorTitle___DJcp4","errorDescription":"Overlay__errorDescription___5bUeF","errorWrapReloadButton":"Overlay__errorWrapReloadButton___gwpLD","errorWrapCloseButton":"Overlay__errorWrapCloseButton___jM9l9","errorCloseButtonLoading":"Overlay__errorCloseButtonLoading___IXlT4"};

var _templateObject$1, _templateObject2$1;
var OverlayHeader = function OverlayHeader(_ref) {
  var isShowPrevButton = _ref.isShowPrevButton,
    isShowCloseButton = _ref.isShowCloseButton,
    children = _ref.children,
    title = _ref.title,
    onClose = _ref.onClose,
    onPrev = _ref.onPrev;
  var _useBodyTTag = useBodyTTag.useBodyTTag(),
    t = _useBodyTTag.t;
  return /*#__PURE__*/React__namespace.default.createElement("header", {
    className: css.header
  }, typeof children !== 'undefined' ? children : /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.header__grid
  }, /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.header__action
  }, isShowPrevButton && /*#__PURE__*/React__namespace.default.createElement(Button.Button, {
    className: css.header__actionButton,
    "button-theme": "black-inherit",
    type: "button",
    onClick: onPrev,
    "aria-label": t(_templateObject$1 || (_templateObject$1 = _taggedTemplateLiteral(["\u041D\u0430\u0437\u0430\u0434"]))),
    "data-qaid": "prev"
  }, /*#__PURE__*/React__namespace.default.createElement(Icon.Icon, {
    "icon-as": ArrowBack.SvgArrowBack,
    className: css.header__actionIcon
  }))), /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.header__title
  }, typeof title === 'string' ? /*#__PURE__*/React__namespace.default.createElement("span", {
    className: css.header__titleText,
    "data-qaid": "title"
  }, title) : title), /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.header__action
  }, isShowCloseButton && onClose && /*#__PURE__*/React__namespace.default.createElement(Button.Button, {
    className: css.header__actionButton,
    "button-theme": "black-inherit",
    type: "button",
    onClick: onClose,
    "aria-label": t(_templateObject2$1 || (_templateObject2$1 = _taggedTemplateLiteral(["\u0417\u0430\u043A\u0440\u044B\u0442\u044C"]))),
    "data-qaid": "close"
  }, /*#__PURE__*/React__namespace.default.createElement(Icon.Icon, {
    "icon-as": Close.SvgClose,
    className: css.header__actionIcon
  })))));
};

var getPopupStyle = function getPopupStyle(placement, size, maxSize) {
  if (['top', 'bottom'].includes(placement)) {
    return {
      height: size,
      maxHeight: maxSize
    };
  }
  return {
    width: size,
    maxWidth: maxSize
  };
};
var TIMEOUT_RELOAD_ERROR = 600;
var getErrorType = function getErrorType() {
  var _navigator;
  return Boolean((_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.onLine) ? 'default' : 'offline';
};

var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6;
var ErrorComponent = function ErrorComponent(_ref) {
  var onClickReload = _ref.onClickReload,
    onClose = _ref.onClose,
    _ref$errorType = _ref.errorType,
    errorType = _ref$errorType === void 0 ? 'default' : _ref$errorType,
    _ref$loading = _ref.loading,
    loading = _ref$loading === void 0 ? false : _ref$loading;
  var _useBodyTTag = useBodyTTag.useBodyTTag(),
    t = _useBodyTTag.t;
  var errorData = {
    "default": {
      icon: PromTroubleHappens.SvgPromTroubleHappens,
      title: t(_templateObject || (_templateObject = _taggedTemplateLiteral(["\u041E\u0439, \u043A\u0430\u0436\u0435\u0442\u0441\u044F \u0447\u0442\u043E-\u0442\u043E \u043F\u043E\u0448\u043B\u043E \u043D\u0435 \u0442\u0430\u043A"]))),
      description: t(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\u041C\u044B \u0443\u0436\u0435 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0435\u043C\u0441\u044F \u0441 \u044D\u0442\u0438\u043C"])))
    },
    offline: {
      icon: PromNoSignal.SvgPromNoSignal,
      title: t(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\u041D\u0435\u0442 \u0441\u043E\u0435\u0434\u0438\u043D\u0435\u043D\u0438\u044F"]))),
      description: t(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\u041F\u0440\u043E\u0432\u0435\u0440\u044C\u0442\u0435 \u043F\u043E\u0434\u043A\u043B\u044E\u0447\u0435\u043D\u0438\u0435 \u043A \u0418\u043D\u0442\u0435\u0440\u043D\u0435\u0442\u0443"])))
    }
  };
  return /*#__PURE__*/React__namespace.default.createElement("div", {
    className: classNames__default.default(css.errorContainer, _defineProperty({}, css.errorContainerLoading, loading)),
    "data-qaid": "overlay_error_catch",
    "data-testid": "overlay_error_catch"
  }, /*#__PURE__*/React__namespace.default.createElement(Icon.Icon, {
    className: css.errorIcon,
    "icon-as": errorData[errorType].icon,
    "data-qaid": "overlay_error_catch_icon",
    "data-testid": "overlay_error_catch_icon"
  }), /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.errorTitle,
    "data-qaid": "overlay_error_catch_title",
    "data-testid": "overlay_error_catch_title"
  }, errorData[errorType].title), /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.errorDescription,
    "data-qaid": "overlay_error_catch_description",
    "data-testid": "overlay_error_catch_description"
  }, errorData[errorType].description), /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.errorWrapReloadButton
  }, /*#__PURE__*/React__namespace.default.createElement(Button.Button, {
    "button-theme": "violet",
    "button-padding-left": "4xl",
    "button-padding-right": "4xl",
    type: "button",
    onClick: onClickReload,
    loading: loading,
    "data-qaid": "overlay_error_catch_reload_button",
    "data-testid": "overlay_error_catch_reload_button"
  }, t(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\u041F\u043E\u043F\u0440\u043E\u0431\u043E\u0432\u0430\u0442\u044C \u0435\u0449\u0435 \u0440\u0430\u0437"]))))), /*#__PURE__*/React__namespace.default.createElement("div", {
    className: css.errorWrapCloseButton
  }, /*#__PURE__*/React__namespace.default.createElement(Link.Link, {
    className: loading ? css.errorCloseButtonLoading : undefined,
    "link-as": "button",
    "link-color": "blue-500",
    type: "button",
    onClick: onClose,
    "data-qaid": "overlay_error_catch_close_button",
    "data-testid": "overlay_error_catch_close_button"
  }, t(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\u0417\u0430\u043A\u0440\u044B\u0442\u044C"]))))));
};
ErrorComponent.displayName = 'ErrorComponent';
var OverlayErrCatch = function OverlayErrCatch(_ref2) {
  var children = _ref2.children,
    name = _ref2.name,
    onClose = _ref2.onClose;
  var _useState = React.useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isReload = _useState2[0],
    setReload = _useState2[1];
  var _useState3 = React.useState('default'),
    _useState4 = _slicedToArray(_useState3, 2),
    errorType = _useState4[0],
    setErrorType = _useState4[1];
  React.useEffect(function () {
    if (isReload) {
      setTimeout(function () {
        setErrorType(getErrorType());
        setReload(false);
      }, TIMEOUT_RELOAD_ERROR);
    } else {
      setErrorType(getErrorType());
    }
  }, [isReload]);
  if (isReload) {
    return /*#__PURE__*/React__namespace.default.createElement(ErrorComponent, {
      errorType: errorType,
      loading: true
    });
  }
  return /*#__PURE__*/React__namespace.default.createElement(errcatch.ErrCatch, {
    name: name,
    errorComponent: /*#__PURE__*/React__namespace.default.createElement(ErrorComponent, {
      onClose: onClose,
      errorType: errorType,
      onClickReload: function onClickReload() {
        return setReload(true);
      }
    })
  }, children);
};
OverlayErrCatch.displayName = 'OverlayErrCatch';

var VENDOR_PREFIX = ['-webkit', '-moz', '-ms', '-o'];
var PROPERTYES_VENDOR_PREFIX = ['transform', 'transition'];
var setStyle = function setStyle(element, style) {
  if (!element) return;
  for (var property in style) {
    var isVendorPrefix = PROPERTYES_VENDOR_PREFIX.indexOf(property) !== -1;
    if (!!!style[property]) {
      element.style.removeProperty(property);
      if (isVendorPrefix) {
        for (var _i = 0, _VENDOR_PREFIX = VENDOR_PREFIX; _i < _VENDOR_PREFIX.length; _i++) {
          var vendor = _VENDOR_PREFIX[_i];
          element.style.removeProperty("".concat(vendor, "-").concat(property));
        }
      }
    } else {
      element.style.setProperty(property, style[property]);
      if (isVendorPrefix) {
        for (var _i2 = 0, _VENDOR_PREFIX2 = VENDOR_PREFIX; _i2 < _VENDOR_PREFIX2.length; _i2++) {
          var _vendor = _VENDOR_PREFIX2[_i2];
          element.style.setProperty("".concat(_vendor, "-").concat(property), style[property]);
        }
      }
    }
  }
};
var SWIPE_TIME_RATE = 250;
var SWIPE_MIN_POS = 70;
var SWIPE_TRANSITION_DURATION = 225;
var SwipeClose = function SwipeClose(_ref) {
  var _ref$isActive = _ref.isActive,
    isActive = _ref$isActive === void 0 ? true : _ref$isActive,
    children = _ref.children,
    onClose = _ref.onClose,
    placement = _ref.placement,
    rootRef = _ref.rootRef,
    contentRef = _ref.contentRef;
  var isAllowSwipe = React__namespace.useRef(null);
  var isAllowClose = React__namespace.useRef(false);
  var startTime = React__namespace.useRef(0);
  if (!isActive) {
    return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, children);
  }
  var onSwipeMove = function onSwipeMove(_ref2, e) {
    var _contentRef$current, _contentRef$current2, _contentRef$current3;
    var x = _ref2.x,
      y = _ref2.y;
    var contentsScrollHeight = ((_contentRef$current = contentRef.current) === null || _contentRef$current === void 0 ? void 0 : _contentRef$current.scrollHeight) || 0;
    var contentOffsetHeight = ((_contentRef$current2 = contentRef.current) === null || _contentRef$current2 === void 0 ? void 0 : _contentRef$current2.offsetHeight) || 0;
    var contentScrollTop = ((_contentRef$current3 = contentRef.current) === null || _contentRef$current3 === void 0 ? void 0 : _contentRef$current3.scrollTop) || 0;
    var contentScrollBottom = contentsScrollHeight - (contentScrollTop + contentOffsetHeight);
    var transform = null;
    var isAllowSwipeCords = false;
    var isAllowCloseCords = false;
    var xAbs = Math.abs(x);
    var yAbs = Math.abs(y);
    if (placement === 'top') {
      transform = "translateY(".concat(y >= 0 ? 0 : y, "px)");
      isAllowSwipeCords = contentScrollBottom <= 1 && y <= 0 && yAbs > xAbs;
      isAllowCloseCords = yAbs > SWIPE_MIN_POS;
    } else if (placement === 'bottom') {
      transform = "translateY(".concat(y <= 0 ? 0 : y, "px)");
      isAllowSwipeCords = contentScrollTop <= 1 && y >= 0 && yAbs > xAbs;
      isAllowCloseCords = yAbs > SWIPE_MIN_POS;
    } else if (placement === 'left') {
      transform = "translateX(".concat(x >= 0 ? 0 : x, "px)");
      isAllowSwipeCords = x <= 0 && xAbs > yAbs;
      isAllowCloseCords = xAbs > SWIPE_MIN_POS;
    } else if (placement === 'right') {
      transform = "translateX(".concat(x <= 0 ? 0 : x, "px)");
      isAllowSwipeCords = x >= 0 && xAbs > yAbs;
      isAllowCloseCords = xAbs > SWIPE_MIN_POS;
    }
    if (isAllowSwipe.current === null) {
      if (isAllowSwipeCords) {
        isAllowSwipe.current = true;
      } else {
        isAllowSwipe.current = false;
      }
    }
    if (isAllowSwipe.current) {
      if (!startTime.current) {
        startTime.current = new Date().getTime();
      }
      if (!isAllowClose.current && isAllowCloseCords) {
        isAllowClose.current = true;
      }
      e === null || e === void 0 ? void 0 : e.preventDefault();
      setStyle(rootRef.current, {
        transform: transform
      });
      setStyle(contentRef.current, {
        'pointer-events': "none",
        overflow: 'hidden'
      });
    }
  };
  var onSwipeEnd = function onSwipeEnd() {
    if (isAllowSwipe.current) {
      setStyle(rootRef.current, {
        transition: "transform ".concat(SWIPE_TRANSITION_DURATION, "ms cubic-bezier(0, 0, 0.2, 1) 0ms"),
        transform: null
      });
      setStyle(contentRef.current, {
        'pointer-events': null,
        overflow: null
      });
      setTimeout(function () {
        setStyle(rootRef.current, {
          transition: null
        });
      }, SWIPE_TRANSITION_DURATION);
      var timeRate = new Date().getTime() - startTime.current;
      if (isAllowClose.current && timeRate < SWIPE_TIME_RATE && onClose) {
        onClose({});
      }
    }
    startTime.current = 0;
    isAllowSwipe.current = null;
    isAllowClose.current = false;
  };
  return /*#__PURE__*/React__namespace.createElement(Swipe__default.default, {
    onSwipeMove: onSwipeMove,
    onSwipeEnd: onSwipeEnd
  }, children);
};

var _excluded = ["children", "onClose", "onOpen", "onPrev", "onOpened", "onClosed", "isOpen", "isBodyScrollLock", "isShowCloseButton", "isShowPrevButton", "isCloseOnEscape", "isCloseOnSwipe", "isCloseOutsideClick", "isAnimated", "isRenderPortal", "header", "footer", "padding", "title", "placement", "size", "maxSize", "zIndex", "contentRef", "dataQaId", "errCatchName"];
var DEFAULT_SIZE = 400;

/**
 * Компонент используется для создания оверлея (накладывающегося слоя) на верху содержимого.
 * Он может использоваться, например, для создания модальных окон, выпадающих списков и других элементов интерфейса.
 */
var Overlay = function Overlay(_ref) {
  var children = _ref.children,
    onClose = _ref.onClose,
    onOpen = _ref.onOpen,
    onPrev = _ref.onPrev,
    onOpened = _ref.onOpened,
    onClosed = _ref.onClosed,
    isOpen = _ref.isOpen,
    _ref$isBodyScrollLock = _ref.isBodyScrollLock,
    isBodyScrollLock = _ref$isBodyScrollLock === void 0 ? true : _ref$isBodyScrollLock,
    _ref$isShowCloseButto = _ref.isShowCloseButton,
    isShowCloseButton = _ref$isShowCloseButto === void 0 ? true : _ref$isShowCloseButto,
    _ref$isShowPrevButton = _ref.isShowPrevButton,
    isShowPrevButton = _ref$isShowPrevButton === void 0 ? false : _ref$isShowPrevButton,
    _ref$isCloseOnEscape = _ref.isCloseOnEscape,
    isCloseOnEscape = _ref$isCloseOnEscape === void 0 ? true : _ref$isCloseOnEscape,
    _ref$isCloseOnSwipe = _ref.isCloseOnSwipe,
    isCloseOnSwipe = _ref$isCloseOnSwipe === void 0 ? true : _ref$isCloseOnSwipe,
    _ref$isCloseOutsideCl = _ref.isCloseOutsideClick,
    isCloseOutsideClick = _ref$isCloseOutsideCl === void 0 ? true : _ref$isCloseOutsideCl,
    _ref$isAnimated = _ref.isAnimated,
    isAnimated = _ref$isAnimated === void 0 ? true : _ref$isAnimated,
    _ref$isRenderPortal = _ref.isRenderPortal,
    isRenderPortal = _ref$isRenderPortal === void 0 ? true : _ref$isRenderPortal,
    header = _ref.header,
    footer = _ref.footer,
    _ref$padding = _ref.padding,
    padding = _ref$padding === void 0 ? '20px 20px 20px 20px' : _ref$padding,
    title = _ref.title,
    _ref$placement = _ref.placement,
    placement = _ref$placement === void 0 ? 'adaptive' : _ref$placement,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'adaptive' : _ref$size,
    _ref$maxSize = _ref.maxSize,
    maxSize = _ref$maxSize === void 0 ? '90%' : _ref$maxSize,
    _ref$zIndex = _ref.zIndex,
    zIndex = _ref$zIndex === void 0 ? 5000 : _ref$zIndex,
    contentRef = _ref.contentRef,
    dataQaId = _ref.dataQaId,
    _ref$errCatchName = _ref.errCatchName,
    errCatchName = _ref$errCatchName === void 0 ? 'OverlayErrCatch' : _ref$errCatchName,
    props = _objectWithoutProperties(_ref, _excluded);
  var popupRef = React__namespace.useRef(null);
  var currentContentRef = contentRef || React__namespace.useRef(null);
  var isMinWidthMedium = Media.useMedia({
    minWidth: 'medium'
  });
  var currentPlacement = placement;
  var currentSize = size;
  if (size === 'adaptive') {
    if (placement === 'top' || placement === 'bottom') {
      currentSize = 'auto';
    } else if (placement === 'adaptive') {
      currentSize = isMinWidthMedium ? DEFAULT_SIZE : 'auto';
    } else {
      currentSize = DEFAULT_SIZE;
    }
  }
  if (placement === 'adaptive') {
    currentPlacement = isMinWidthMedium ? 'right' : 'bottom';
  }
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(Backdrop.Backdrop, {
    isOpen: isOpen,
    isAnimated: isAnimated,
    zIndex: zIndex,
    isRenderPortal: isRenderPortal,
    isBodyScrollLock: isBodyScrollLock
  }), /*#__PURE__*/React__namespace.createElement(reactTransitionGroup.CSSTransition, {
    "in": isOpen,
    timeout: isAnimated ? 225 : 0,
    classNames: css,
    unmountOnExit: true,
    onEnter: onOpen,
    onEntered: onOpened,
    onExited: onClosed
  }, /*#__PURE__*/React__namespace.createElement(Portal.Portal, {
    isActive: isRenderPortal
  }, /*#__PURE__*/React__namespace.createElement(SwipeClose, {
    isActive: isBodyScrollLock && isCloseOnSwipe,
    rootRef: popupRef,
    contentRef: currentContentRef,
    placement: currentPlacement,
    onClose: onClose
  }, /*#__PURE__*/React__namespace.createElement("div", _extends({
    className: css.root,
    role: "presentation",
    style: {
      zIndex: zIndex
    }
  }, props), /*#__PURE__*/React__namespace.createElement(KeyPress.KeyPress, {
    isActive: isCloseOnEscape,
    code: "Escape",
    onKeyDown: onClose
  }), /*#__PURE__*/React__namespace.createElement("div", {
    className: css.backdrop,
    "aria-hidden": true,
    onClick: function onClick(e) {
      if (isCloseOutsideClick && onClose) {
        onClose(e);
      }
    }
  }), /*#__PURE__*/React__namespace.createElement("div", {
    ref: popupRef,
    className: classNames__default.default(css.popup, css["popup_placement_".concat(currentPlacement)]),
    "aria-modal": true,
    role: "dialog",
    style: getPopupStyle(currentPlacement, currentSize, maxSize),
    "data-qaid": dataQaId
  }, /*#__PURE__*/React__namespace.createElement(OverlayHeader, {
    isShowCloseButton: isShowCloseButton,
    isShowPrevButton: isShowPrevButton,
    onClose: onClose,
    onPrev: onPrev,
    title: title
  }, header), /*#__PURE__*/React__namespace.createElement("footer", {
    className: css.footer
  }, footer), /*#__PURE__*/React__namespace.createElement("div", {
    className: css.content,
    ref: currentContentRef,
    style: {
      padding: padding
    }
  }, /*#__PURE__*/React__namespace.createElement(OverlayErrCatch, {
    onClose: onClose,
    name: errCatchName
  }, children))))))));
};
Overlay.displayName = 'Overlay';

exports.Overlay = Overlay;

require('./style.development.css');
