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

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 _ThemeHelpers = require("../../lib/theming/ThemeHelpers");

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















var ModalHeaderDataTids = exports.ModalHeaderDataTids = {
  root: 'ModalHeader__root'
};

/**
 * Шапка модального окна, состоит из заголовка и крестика закрытия.
 *
 * @visibleName Modal.Header
 */
function ModalHeader(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,_props$cutTitleOnStuc = props.cutTitleOnStuck,cutTitleOnStuck = _props$cutTitleOnStuc === void 0 ? false : _props$cutTitleOnStuc,children = props.children;

  (0, _react.useLayoutEffect)(function () {
    modal.setHasHeader == null || modal.setHasHeader(true);

    return function () {return modal.setHasHeader == null ? void 0 : modal.setHasHeader(false);};
  }, []);

  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, /*#__PURE__*/
      _react.default.createElement("div", {
        "data-tid": ModalHeaderDataTids.root,
        className: (0, _Emotion.cx)(
          _Modal.styles.header(theme),
          versionGTE5_2 && _Modal.styles.header5_2(theme),
          layout.isMobile && _Modal.styles.mobileHeader(theme),
          Boolean(modal.additionalPadding) && _Modal.styles.headerAddPadding(theme),
          fixed && _Modal.styles.fixedHeader(theme),
          cutTitleOnStuck && fixed && _Modal.styles.titleCut(),
          versionGTE5_2 && fixed && _Modal.styles.fixedHeader5_2(),
          fixed && layout.isMobile && _Modal.styles.mobileFixedHeader(theme),
          versionGTE5_2 && fixed && layout.isMobile && _Modal.styles.mobileFixedHeader5_2(theme),
          Boolean(modal.close) && _Modal.styles.headerWithClose(theme),
          Boolean(modal.close) && layout.isMobile && _Modal.styles.mobileHeaderWithClose(theme)
        ) },

      modal.close && /*#__PURE__*/
      _react.default.createElement(_ModalClose.ModalClose, { requestClose: modal.close.requestClose, disableClose: modal.close.disableClose }),

      children
      ),
      fixed && /*#__PURE__*/_react.default.createElement(_ModalSeparator.ModalSeparator, { fixed: fixed })
      ));

  };

  var getStickyOffset = function getStickyOffset() {
    if (versionGTE5_2 && layout.isMobile && !modal.mobileOnFullScreen) {
      return parseInt(theme.mobileModalContainerMarginTop);
    }
    return 0;
  };

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

    renderContent()

    ));

}

ModalHeader.__KONTUR_REACT_UI__ = 'ModalHeader';
ModalHeader.displayName = 'ModalHeader';
ModalHeader.__MODAL_HEADER__ = true;