var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        if (typeof b !== "function" && b !== null)
            throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import React from 'react';
import { Transition } from 'react-transition-group';
import { ThemeContext } from '../../lib/theming/ThemeContext.js';
import { RenderContainer } from '../RenderContainer/index.js';
import { HideBodyVerticalScroll } from '../HideBodyVerticalScroll/index.js';
import { ZIndex } from '../ZIndex/index.js';
import { RenderLayer } from '../RenderLayer/index.js';
import { rootNode } from '../../lib/rootNode/index.js';
import { withRenderEnvironment } from '../../lib/renderEnvironment/index.js';
import { getJsStyles } from './MobilePopup.styles.js';
import { MobilePopupHeader } from './MobilePopupHeader/index.js';
import { MobilePopupFooter } from './MobilePopupFooter/index.js';
export var MobilePopupDataTids = {
    root: 'MobilePopup__root',
    container: 'MobilePopup__container',
    backdrop: 'MobilePopup__backdrop',
};
var MobilePopup = /** @class */ (function (_super) {
    __extends(MobilePopup, _super);
    function MobilePopup() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.refForTransition = React.createRef();
        _this.close = function () {
            if (_this.props.onCloseRequest) {
                _this.props.onCloseRequest();
            }
        };
        /** Не даём событию дойти до document (`RenderLayer` / «клик сквозь» вуаль).
         *  В мобильных браузерах pointerup может породить click по нижележащему элементу.
         *  Гасим его на вуали, а закрытие остаётся на обычном click по backdrop.
         */
        _this.backdropStopPropagation = function (event) {
            event.preventDefault();
            event.stopPropagation();
        };
        _this.backdropClick = function (event) {
            _this.backdropStopPropagation(event);
            _this.close();
        };
        return _this;
    }
    MobilePopup.prototype.render = function () {
        var _this = this;
        this.jsStyles = getJsStyles(this.emotion);
        return (React.createElement(ThemeContext.Consumer, null, function (theme) {
            _this.theme = theme;
            return _this.renderMain();
        }));
    };
    MobilePopup.prototype.renderMain = function () {
        var content = (React.createElement(ZIndex, { id: this.props.id, className: this.jsStyles.zIndex(), priority: 'MobilePopup' },
            React.createElement(Transition, { in: this.props.opened, onExited: this.props.onClose, mountOnEnter: true, unmountOnExit: true, timeout: 0, nodeRef: this.refForTransition },
                React.createElement("div", { className: this.jsStyles.wrapper(), ref: this.refForTransition },
                    React.createElement(RenderLayer, { onClickOutside: this.close },
                        React.createElement("div", { ref: this.setRootNode, "data-tid": MobilePopupDataTids.container, className: this.jsStyles.container(this.theme) },
                            React.createElement("div", { "data-tid": MobilePopupDataTids.root, className: this.jsStyles.root(this.theme) },
                                React.createElement(MobilePopupHeader, { caption: this.props.caption }, this.props.headerChildComponent),
                                React.createElement("div", { className: this.jsStyles.content(this.theme) }, this.props.children),
                                React.createElement(MobilePopupFooter, null, this.props.footerChildComponent)),
                            React.createElement("div", { onClick: this.close, className: this.jsStyles.bottomIndent() }))),
                    React.createElement("div", { "data-tid": MobilePopupDataTids.backdrop, className: this.jsStyles.bg(), onClick: this.backdropClick, onMouseDown: this.backdropStopPropagation, onPointerDownCapture: this.backdropStopPropagation, onPointerUpCapture: this.backdropStopPropagation }),
                    React.createElement(HideBodyVerticalScroll, null)))));
        if (this.props.withoutRenderContainer) {
            return content;
        }
        return React.createElement(RenderContainer, null, content);
    };
    MobilePopup.__KONTUR_REACT_UI__ = 'MobileMenuHeader';
    MobilePopup.displayName = 'MobileMenuHeader';
    // see #2873 and #2895
    MobilePopup.defaultRootNode = null;
    MobilePopup = __decorate([
        withRenderEnvironment,
        rootNode
    ], MobilePopup);
    return MobilePopup;
}(React.Component));
export { MobilePopup };
//# sourceMappingURL=MobilePopup.js.map