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

var _utils = require("../../lib/utils");

var _CommonWrapper = require("../../internal/CommonWrapper");

var _rootNode = require("../../lib/rootNode");
var _createPropsGetter = require("../../lib/createPropsGetter");var _class, _Gapped;


















var GappedDataTids = exports.GappedDataTids = {
  vertical: 'Gapped__vertical',
  horizontal: 'Gapped__horizontal'
};



/**
 * Контейнер `Gapped` устанавливает расстояние равное `gap` между элементами.
 */var

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












    getProps = (0, _createPropsGetter.createPropsGetter)(Gapped.defaultProps);return _this;}(0, _inheritsLoose2.default)(Gapped, _React$Component);var _proto = Gapped.prototype;_proto.

  render = function render() {
    return /*#__PURE__*/(
      _react.default.createElement(_CommonWrapper.CommonWrapper, (0, _extends2.default)({ rootNodeRef: this.setRootNode }, this.props),
      this.getProps().vertical ? this.renderVertical() : this.renderHorizontal()
      ));

  };_proto.

  getGapValue = function getGapValue() {
    // DEPRECATED remove in 4.0
    var propsGap = this.props.gap;
    if ((0, _utils.isNonNullable)(propsGap)) {
      return propsGap;
    }

    return 8;
  };_proto.

  renderVertical = function renderVertical() {
    var subsequentItemStyle = {
      paddingTop: this.getGapValue()
    };
    var children = _react.default.Children.toArray(this.props.children).
    filter(this.filterChildren).
    map(function (child, index) {
      var style = index === 0 ? undefined : subsequentItemStyle;
      return /*#__PURE__*/(
        _react.default.createElement("div", { style: style, key: index },
        child
        ));

    });

    return /*#__PURE__*/_react.default.createElement("div", { "data-tid": GappedDataTids.vertical }, children);
  };_proto.

  renderHorizontal = function renderHorizontal() {
    var _this$props = this.props,children = _this$props.children,verticalAlign = _this$props.verticalAlign;
    var wrap = this.getProps().wrap;
    var gap = this.getGapValue();
    var itemStyle = (0, _extends2.default)({
      display: 'inline-block',
      verticalAlign: verticalAlign },
    wrap ? { marginLeft: gap, marginTop: gap } : {});

    var rootStyle = wrap ? { paddingTop: 1 } : {};
    var contStyle = wrap ? { marginTop: -gap - 1, marginLeft: -gap } : { whiteSpace: 'nowrap' };

    return /*#__PURE__*/(
      _react.default.createElement("div", { "data-tid": GappedDataTids.horizontal, style: rootStyle }, /*#__PURE__*/
      _react.default.createElement("div", { style: contStyle },
      _react.default.Children.toArray(children).
      filter(this.filterChildren).
      map(function (child, index) {
        var marginLeft = index === 0 ? undefined : gap;
        return /*#__PURE__*/(
          _react.default.createElement("span", { key: index, style: (0, _extends2.default)({ marginLeft: marginLeft }, itemStyle) },
          child
          ));

      })
      )
      ));

  };_proto.

  filterChildren = function filterChildren(child) {
    return Boolean(child) || typeof child === 'number';
  };return Gapped;}(_react.default.Component), _Gapped.__KONTUR_REACT_UI__ = 'Gapped', _Gapped.displayName = 'Gapped', _Gapped.defaultProps = { wrap: false, vertical: false, verticalAlign: 'baseline' }, _Gapped)) || _class;