import _extends from "@babel/runtime/helpers/esm/extends";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
var _class, _ModalBody;
import React from 'react';
import { ThemeContext } from "../../../lib/theming/ThemeContext";
import { ZIndex } from "../../../internal/ZIndex";
import { CommonWrapper } from "../../../internal/CommonWrapper";
import { cx } from "../../../lib/theming/Emotion";
import { responsiveLayout } from "../../ResponsiveLayout/decorator";
import * as LayoutEvents from "../../../lib/LayoutEvents";
import { ResizeDetector } from "../../../internal/ResizeDetector";
import { rootNode } from "../../../lib/rootNode";
import { isThemeGTE } from "../../../lib/theming/ThemeHelpers";
import { ModalContext } from "../ModalContext";
import { styles } from "../Modal.styles";
import { getModalBodyTheme } from "../getModalBodyTheme";
import { ModalZIndexPriority } from "../Modal";

/**
 * Контейнер с отступами для содержимого модального окна.
 *
 * @visibleName Modal.Body
 */
export var ModalBody = responsiveLayout(_class = rootNode(_class = (_ModalBody = /*#__PURE__*/function (_React$Component) {
  function ModalBody() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _this.handleResize = function () {
      LayoutEvents.emit();
    };
    return _this;
  }
  _inheritsLoose(ModalBody, _React$Component);
  var _proto = ModalBody.prototype;
  _proto.render = function render() {
    var _this2 = this;
    return /*#__PURE__*/React.createElement(ThemeContext.Consumer, null, function (theme) {
      _this2.theme = getModalBodyTheme(theme);
      return /*#__PURE__*/React.createElement(ThemeContext.Provider, {
        value: _this2.theme
      }, _this2.renderMain());
    });
  };
  _proto.renderMain = function renderMain() {
    var _this3 = this;
    var versionGTE5_2 = isThemeGTE(this.theme, '5.2');
    var noPadding = this.props.noPadding;
    return /*#__PURE__*/(
      React.createElement(ModalContext.Consumer, null, function (_ref) {
        var _cx;
        var additionalPadding = _ref.additionalPadding,
          hasHeader = _ref.hasHeader;
        return /*#__PURE__*/(
          React.createElement(CommonWrapper, _extends({
            rootNodeRef: _this3.setRootNode
          }, _this3.props), /*#__PURE__*/
          React.createElement(ZIndex, {
            priority: ModalZIndexPriority.Content,
            className: cx((_cx = {}, _cx[styles.body(_this3.theme)] = true, _cx[styles.mobileBody(_this3.theme)] = _this3.isMobileLayout, _cx[styles.bodyWithoutHeader(_this3.theme)] = !hasHeader, _cx[styles.mobileBodyWithoutHeader()] = !hasHeader && _this3.isMobileLayout, _cx[styles.bodyAddPaddingForPanel(_this3.theme)] = additionalPadding, _cx[styles.mobileBodyAddPaddingForPanel(_this3.theme)] = additionalPadding && _this3.isMobileLayout, _cx[styles.mobileBodyWithoutHeader5_2(_this3.theme)] = versionGTE5_2 && !hasHeader && _this3.isMobileLayout, _cx[styles.mobileBodyAddPaddingForPanel5_2(_this3.theme)] = versionGTE5_2 && additionalPadding && _this3.isMobileLayout, _cx[styles.bodyWithoutPadding()] = noPadding, _cx))
          }, _this3.isMobileLayout ? /*#__PURE__*/
          React.createElement(ResizeDetector, {
            onResize: _this3.handleResize
          }, _this3.props.children) : _this3.props.children))
        );
      })
    );
  };
  return ModalBody;
}(React.Component), _ModalBody.__KONTUR_REACT_UI__ = 'ModalBody', _ModalBody.displayName = 'ModalBody', _ModalBody.__MODAL_BODY__ = true, _ModalBody)) || _class) || _class;