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 __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);
};
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 { isNonNullable } from '../../lib/utils.js';
import { CommonWrapper } from '../../internal/CommonWrapper/index.js';
import { rootNode } from '../../lib/rootNode/index.js';
import { createPropsGetter } from '../../lib/createPropsGetter.js';
export var GappedDataTids = {
    vertical: 'Gapped__vertical',
    horizontal: 'Gapped__horizontal',
};
/**
 * Контейнер `Gapped` устанавливает расстояние равное `gap` между элементами.
 */
var Gapped = /** @class */ (function (_super) {
    __extends(Gapped, _super);
    function Gapped() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.getProps = createPropsGetter(Gapped_1.defaultProps);
        return _this;
    }
    Gapped_1 = Gapped;
    Gapped.prototype.render = function () {
        return (React.createElement(CommonWrapper, __assign({ rootNodeRef: this.setRootNode }, this.props), this.getProps().vertical ? this.renderVertical() : this.renderHorizontal()));
    };
    Gapped.prototype.getGapValue = function () {
        var propsGap = this.props.gap;
        if (isNonNullable(propsGap)) {
            return propsGap;
        }
        return 8;
    };
    Gapped.prototype.renderVertical = function () {
        var subsequentItemStyle = {
            paddingTop: this.getGapValue(),
        };
        var children = React.Children.toArray(this.props.children)
            .filter(this.filterChildren)
            .map(function (child, index) {
            var style = index === 0 ? undefined : subsequentItemStyle;
            return (React.createElement("div", { style: style, key: index }, child));
        });
        return React.createElement("div", { "data-tid": GappedDataTids.vertical }, children);
    };
    Gapped.prototype.renderHorizontal = function () {
        var _a = this.props, children = _a.children, verticalAlign = _a.verticalAlign;
        var wrap = this.getProps().wrap;
        var gap = this.getGapValue();
        var itemStyle = __assign({ 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 (React.createElement("div", { "data-tid": GappedDataTids.horizontal, style: rootStyle },
            React.createElement("div", { style: contStyle }, React.Children.toArray(children)
                .filter(this.filterChildren)
                .map(function (child, index) {
                var marginLeft = index === 0 ? undefined : gap;
                return (React.createElement("span", { key: index, style: __assign({ marginLeft: marginLeft }, itemStyle) }, child));
            }))));
    };
    Gapped.prototype.filterChildren = function (child) {
        return Boolean(child) || typeof child === 'number';
    };
    var Gapped_1;
    Gapped.__KONTUR_REACT_UI__ = 'Gapped';
    Gapped.displayName = 'Gapped';
    Gapped.defaultProps = {
        wrap: false,
        vertical: false,
        verticalAlign: 'baseline',
    };
    Gapped = Gapped_1 = __decorate([
        rootNode
    ], Gapped);
    return Gapped;
}(React.Component));
export { Gapped };
//# sourceMappingURL=Gapped.js.map