var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
import React, { useContext, useLayoutEffect } from 'react';
import { useEmotion, useStyles } from '../../lib/renderEnvironment/index.js';
import { Sticky } from '../Sticky/index.js';
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
import { CommonWrapper } from '../../internal/CommonWrapper/index.js';
import { useResponsiveLayout } from '../ResponsiveLayout/index.js';
import { getStyles } from './Modal.styles.js';
import { ModalClose } from './ModalClose.js';
import { ModalContext } from './ModalContext.js';
import { ModalSeparator } from './ModalSeparator.js';
export var ModalHeaderDataTids = {
    root: 'ModalHeader__root',
};
/**
 * Шапка модального окна, состоит из заголовка и крестика закрытия.
 *
 * @visibleName Modal.Header
 */
function ModalHeader(props) {
    var theme = useContext(ThemeContext);
    var cx = useEmotion().cx;
    var styles = useStyles(getStyles);
    var modal = useContext(ModalContext);
    var layout = useResponsiveLayout();
    var _a = props.sticky, sticky = _a === void 0 ? !layout.isMobile : _a, _b = props.cutTitleOnStuck, cutTitleOnStuck = _b === void 0 ? false : _b, children = props.children;
    useLayoutEffect(function () {
        var _a;
        (_a = modal.setHasHeader) === null || _a === void 0 ? void 0 : _a.call(modal, true);
        return function () { var _a; return (_a = modal.setHasHeader) === null || _a === void 0 ? void 0 : _a.call(modal, false); };
    }, []);
    var renderContent = function (fixed) {
        if (fixed === void 0) { fixed = false; }
        return (React.createElement("div", null,
            React.createElement("div", { "data-tid": ModalHeaderDataTids.root, className: cx(styles.header(theme), layout.isMobile && styles.mobileHeader(theme), Boolean(modal.additionalPadding) && styles.headerAddPadding(theme), fixed && styles.fixedHeader(theme), cutTitleOnStuck && fixed && styles.titleCut(), fixed && layout.isMobile && styles.mobileFixedHeader(theme), Boolean(modal.close) && styles.headerWithClose(theme), Boolean(modal.close) && layout.isMobile && styles.mobileHeaderWithClose(theme)) },
                modal.close && (React.createElement(ModalClose, { requestClose: modal.close.requestClose, disableClose: modal.close.disableClose })),
                children),
            fixed && React.createElement(ModalSeparator, { fixed: fixed })));
    };
    var getStickyOffset = function () {
        if (layout.isMobile && !modal.mobileOnFullScreen) {
            return parseInt(theme.mobileModalContainerMarginTop);
        }
        return 0;
    };
    return (React.createElement(CommonWrapper, __assign({}, props), sticky ? (React.createElement(Sticky, { offset: getStickyOffset(), side: "top" }, renderContent)) : (renderContent())));
}
ModalHeader.__KONTUR_REACT_UI__ = 'ModalHeader';
ModalHeader.displayName = 'ModalHeader';
ModalHeader.__MODAL_HEADER__ = true;
export { ModalHeader };
//# sourceMappingURL=ModalHeader.js.map