"use strict";var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;exports.__esModule = true;exports.SidePageFooterDataTids = exports.SidePageFooter = void 0;var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));var _react = _interopRequireDefault(require("react"));

var LayoutEvents = _interopRequireWildcard(require("../../lib/LayoutEvents"));
var _ThemeContext = require("../../lib/theming/ThemeContext");


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

var _rootNode = require("../../lib/rootNode");
var _getDOMRect = require("../../lib/dom/getDOMRect");

var _Gapped = require("../Gapped");
var _utils = require("../../lib/utils");
var _ModalSeparator = require("../Modal/ModalSeparator");

var _SidePage = require("./SidePage.styles");

var _SidePageContext = require("./SidePageContext");var _class, _SidePageFooter;



















var SidePageFooterDataTids = exports.SidePageFooterDataTids = {
  root: 'SidePageFooter__root'
};

/**
 * Футер сайдпейджа.
 *
 * @visibleName SidePage.Footer
 */var


SidePageFooter = exports.SidePageFooter = (0, _decorator.responsiveLayout)(_class = (0, _rootNode.rootNode)(_class = (_SidePageFooter = /*#__PURE__*/function (_React$Component) {function SidePageFooter() {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.




    context = _this.context;_this.


    state = {
      fixed: false
    };_this.


    content = null;_this.
    layoutSub = null;_this.















































    update = function () {
      _this.setProperStyles();
    };_this.

















































    refContent = function (node) {
      _this.content = node;
    };_this.

    setProperStyles = function () {
      var wrapper = (0, _rootNode.getRootNode)(_this);
      if (wrapper && _this.content) {
        var wrapperRect = (0, _getDOMRect.getDOMRect)(wrapper);
        var contentRect = (0, _getDOMRect.getDOMRect)(_this.content);
        var fixed = wrapperRect.top > contentRect.top;
        _this.setState({ fixed: fixed });
      }
    };return _this;}(0, _inheritsLoose2.default)(SidePageFooter, _React$Component);var _proto = SidePageFooter.prototype;_proto.componentDidMount = function componentDidMount() {var _this$context$setHasF, _this$context, _this$context$setHasP, _this$context2;this.context.footerRef(this);this.update();this.layoutSub = LayoutEvents.addListener(this.update);(_this$context$setHasF = (_this$context = this.context).setHasFooter) == null || _this$context$setHasF.call(_this$context);(_this$context$setHasP = (_this$context2 = this.context).setHasPanel) == null || _this$context$setHasP.call(_this$context2, this.props.panel);};_proto.componentDidUpdate = function componentDidUpdate(prevProps) {var _this$context$setHasP2, _this$context3;this.props.panel !== prevProps.panel && ((_this$context$setHasP2 = (_this$context3 = this.context).setHasPanel) == null ? void 0 : _this$context$setHasP2.call(_this$context3, this.props.panel));};_proto.componentWillUnmount = function componentWillUnmount() {var _this$context$setHasF2, _this$context4, _this$context$setHasP3, _this$context5;this.context.footerRef(null);if (this.layoutSub) {this.layoutSub.remove();}(_this$context$setHasF2 = (_this$context4 = this.context).setHasFooter) == null || _this$context$setHasF2.call(_this$context4, false);(_this$context$setHasP3 = (_this$context5 = this.context).setHasPanel) == null || _this$context$setHasP3.call(_this$context5, false);};_proto.getSticky = function getSticky() {if (typeof this.props.sticky !== 'undefined') {return this.props.sticky;}if (this.isMobileLayout) {return false;}return true;};_proto.render = function render() {var _this2 = this;return /*#__PURE__*/_react.default.createElement(_ThemeContext.ThemeContext.Consumer, null, function (theme) {_this2.theme = theme;return _this2.renderMain();});};_proto.renderMain = function renderMain() {var _this3 = this;var separator = (this.props.panel || this.state.fixed) && /*#__PURE__*/_react.default.createElement(_ModalSeparator.ModalSeparator, { fixed: this.state.fixed });return /*#__PURE__*/_react.default.createElement(_CommonWrapper.CommonWrapper, (0, _extends2.default)({ rootNodeRef: this.setRootNode }, this.props), /*#__PURE__*/_react.default.createElement("div", { "data-tid": SidePageFooterDataTids.root, style: { height: this.getContentHeight() }, className: _SidePage.styles.footerWrapper() }, /*#__PURE__*/_react.default.createElement(_SidePageContext.SidePageContext.Consumer, null, function (_ref) {var _cx, _cx2;var getWidth = _ref.getWidth;return /*#__PURE__*/_react.default.createElement("div", { className: (0, _Emotion.cx)(_SidePage.styles.footer(_this3.theme), (_cx = {}, _cx[_SidePage.styles.positionStatic()] = !_this3.getSticky(), _cx)), style: { width: getWidth() } }, separator, /*#__PURE__*/_react.default.createElement("div", { className: (0, _Emotion.cx)(_SidePage.styles.footerContent(_this3.theme), (_cx2 = {}, _cx2[_SidePage.styles.footerFixed(_this3.theme)] = _this3.state.fixed, _cx2[_SidePage.styles.panel(_this3.theme)] = !!_this3.props.panel, _cx2[_SidePage.styles.panelFixed(_this3.theme)] = !!_this3.props.panel && _this3.state.fixed, _cx2[_SidePage.styles.mobileFooterContent(_this3.theme)] = _this3.isMobileLayout, _cx2)), ref: _this3.refContent }, (0, _utils.isNonNullable)(_this3.props.gap) ? /*#__PURE__*/_react.default.createElement(_Gapped.Gapped, { vertical: _this3.isMobileLayout, gap: _this3.props.gap }, _this3.props.children) : _this3.props.children));})));};_proto.

  getContentHeight = function getContentHeight() {
    if (!this.content) {
      return 'auto';
    }
    return (0, _getDOMRect.getDOMRect)(this.content).height;
  };return SidePageFooter;}(_react.default.Component), _SidePageFooter.__KONTUR_REACT_UI__ = 'SidePageFooter', _SidePageFooter.displayName = 'SidePageFooter', _SidePageFooter.contextType = _SidePageContext.SidePageContext, _SidePageFooter)) || _class) || _class;