"use strict";
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
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 (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        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 __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GridRow = void 0;
var react_1 = __importStar(require("react"));
var bem_react_classname_1 = require("bem-react-classname");
/**
 * Строка используется для создания сетки.
 * Сетка имеет резиновую систему разметки, которая масштабируется до 12 столбцов.
 */
var GridRow = /** @class */ (function (_super) {
    __extends(GridRow, _super);
    function GridRow() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.cn = bem_react_classname_1.createCn('grid-row');
        /**
         * Класс колонки
         */
        _this.classCol = 'grid-col';
        return _this;
    }
    GridRow.prototype.render = function () {
        var _a = this.props, Tag = _a.tag, gutter = _a.gutter, align = _a.align, justify = _a.justify, children = _a.children, props = __rest(_a, ["tag", "gutter", "align", "justify", "children"]);
        var gutters = {};
        if (typeof gutter === 'object') {
            Object.keys(gutter).forEach(function (breakpoint) {
                if (gutter[breakpoint] === null) {
                    return;
                }
                if (typeof gutter[breakpoint] === 'object') {
                    Object.keys(gutter[breakpoint]).forEach(function (size) {
                        if (gutter[breakpoint][size] === null) {
                            return;
                        }
                        gutters["gutter-" + breakpoint + "-" + size] = gutter[breakpoint][size].toString();
                    });
                }
                else {
                    gutters["gutter-" + breakpoint] = gutter[breakpoint].toString();
                }
            });
        }
        else {
            gutters = { gutter: gutter };
        }
        return (react_1.default.createElement(Tag, __assign({}, props, { className: this.cn(__assign(__assign({}, gutters), { align: align,
                justify: justify })) }), this.injectGutterClassNamesToChildren(gutters, children)));
    };
    /**
     * Добавляет модификаторы горизонтальных отступов в дочерний элемент.
     *
     * @param gutters Модификаторы горизонтальных отступов
     * @param children Дочерние элементы компонента.
     */
    GridRow.prototype.injectGutterClassNamesToChildren = function (gutters, children) {
        var _this = this;
        return (react_1.Children.map(children, function (col) {
            if (!col) {
                return null;
            }
            if (!col.props) {
                return col;
            }
            var gutterClassNames = Object.keys(gutters).map(function (gutter) { return _this.classCol + "_" + gutter + "_" + gutters[gutter]; });
            var classNameFromProps = col.props.className ? " " + col.props.className : '';
            return react_1.cloneElement(col, { className: "" + gutterClassNames.join(' ') + classNameFromProps });
        }));
    };
    GridRow.defaultProps = {
        tag: 'div',
        gutter: {
            mobile: {
                s: 16,
            },
            desktop: {
                m: 24,
            },
        },
        justify: 'between',
    };
    return GridRow;
}(react_1.default.PureComponent));
exports.GridRow = GridRow;
exports.default = GridRow;

//# sourceMappingURL=grid-row.js.map
