"use strict";var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.ModalFooter = ModalFooter;exports.ModalFooterDataTids = void 0;
var _react = _interopRequireWildcard(require("react"));

var _getScrollWidth = require("../../lib/dom/getScrollWidth");
var _Sticky = require("../Sticky");
var _ThemeContext = require("../../lib/theming/ThemeContext");

var _CommonWrapper = require("../../internal/CommonWrapper");
var _Emotion = require("../../lib/theming/Emotion");
var _ResponsiveLayout = require("../ResponsiveLayout");

var _Gapped = require("../Gapped");
var _utils = require("../../lib/utils");
var _ThemeHelpers = require("../../lib/theming/ThemeHelpers");

var _Modal = require("./Modal.styles");
var _ModalContext = require("./ModalContext");
var _ModalSeparator = require("./ModalSeparator");
















var ModalFooterDataTids = exports.ModalFooterDataTids = {
  root: 'ModalFooter__root'
};

/**
 * Футер модального окна, где обычно располагаются кнопки основных действий.
 *
 * @visibleName Modal.Footer
 */
function ModalFooter(props) {
  var theme = (0, _react.useContext)(_ThemeContext.ThemeContext);
  var modal = (0, _react.useContext)(_ModalContext.ModalContext);
  var layout = (0, _ResponsiveLayout.useResponsiveLayout)();

  var _props$sticky = props.sticky,sticky = _props$sticky === void 0 ? !layout.isMobile : _props$sticky,gap = props.gap,panel = props.panel,children = props.children;

  (0, _react.useLayoutEffect)(function () {
    modal.setHasFooter == null || modal.setHasFooter(true);
    modal.setHasPanel == null || modal.setHasPanel(panel || false);

    return function () {
      modal.setHasFooter == null || modal.setHasFooter(false);
      modal.setHasPanel == null || modal.setHasPanel(false);
    };
  }, [panel]);

  var versionGTE5_2 = (0, _ThemeHelpers.isThemeGTE)(theme, '5.2');
  var renderContent = function renderContent(fixed) {if (fixed === void 0) {fixed = false;}
    return /*#__PURE__*/(
      _react.default.createElement("div", null,
      (panel || fixed) && /*#__PURE__*/_react.default.createElement(_ModalSeparator.ModalSeparator, { fixed: fixed }), /*#__PURE__*/
      _react.default.createElement("div", {
        "data-tid": ModalFooterDataTids.root,
        className: (0, _Emotion.cx)(
          _Modal.styles.footer(theme),
          fixed && _Modal.styles.fixedFooter(theme),
          versionGTE5_2 && fixed && _Modal.styles.fixedFooter5_2(),
          Boolean(panel) && _Modal.styles.panel(theme),
          fixed && Boolean(panel) && _Modal.styles.fixedPanel(theme),
          layout.isMobile && _Modal.styles.mobileFooter(theme),
          versionGTE5_2 && layout.isMobile && fixed && _Modal.styles.mobileFixedFooter5_2(theme)
        ) },

      (0, _utils.isNonNullable)(gap) ? /*#__PURE__*/
      _react.default.createElement(_Gapped.Gapped, { vertical: layout.isMobile, gap: gap },
      children
      ) :

      children

      )
      ));

  };

  var getStickyOffset = function getStickyOffset() {
    var offset = 0;
    if (modal.horizontalScroll) {
      offset += (0, _getScrollWidth.getScrollWidth)();
    }
    if (versionGTE5_2 && layout.isMobile && !modal.mobileOnFullScreen) {
      offset += parseInt(theme.mobileModalContainerMarginBottom);
    }
    return offset;
  };

  return /*#__PURE__*/(
    _react.default.createElement(_CommonWrapper.CommonWrapper, props,
    sticky ? /*#__PURE__*/
    _react.default.createElement(_Sticky.Sticky, { side: "bottom", offset: getStickyOffset() },
    renderContent
    ) :

    renderContent()

    ));

}

ModalFooter.__KONTUR_REACT_UI__ = 'ModalFooter';
ModalFooter.displayName = 'ModalFooter';
ModalFooter.__MODAL_FOOTER__ = true;