"use strict";
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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var PropTypes = __importStar(require("prop-types"));
var classnames_1 = __importDefault(require("classnames"));
var FlexBlockItem_1 = require("./FlexBlockItem");
var FlexBlockDirectionProperty;
(function (FlexBlockDirectionProperty) {
    FlexBlockDirectionProperty["ROW"] = "row";
    FlexBlockDirectionProperty["COLUMN"] = "column";
})(FlexBlockDirectionProperty || (FlexBlockDirectionProperty = {}));
var FlexBlockAlignProperty;
(function (FlexBlockAlignProperty) {
    FlexBlockAlignProperty["CENTER"] = "center";
    FlexBlockAlignProperty["START"] = "start";
    FlexBlockAlignProperty["END"] = "end";
})(FlexBlockAlignProperty || (FlexBlockAlignProperty = {}));
var FlexBlockJustifyProperty;
(function (FlexBlockJustifyProperty) {
    FlexBlockJustifyProperty["CENTER"] = "center";
    FlexBlockJustifyProperty["START"] = "start";
    FlexBlockJustifyProperty["END"] = "end";
    FlexBlockJustifyProperty["SPACE_BETWEEN"] = "space-between";
    FlexBlockJustifyProperty["SPACE_AROUND"] = "space-around";
    FlexBlockJustifyProperty["SPACE_EVENLY"] = "space-evenly";
})(FlexBlockJustifyProperty || (FlexBlockJustifyProperty = {}));
var FlexBlock = /** @class */ (function (_super) {
    __extends(FlexBlock, _super);
    function FlexBlock() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.wrapChild = function (child) {
            var _a = _this.props, gutterWidth = _a.gutterWidth, shouldFlexChildren = _a.shouldFlexChildren, childWrapperStyle = _a.childWrapperStyle;
            if (!child) {
                return child;
            }
            var style = {};
            var className = classnames_1.default(child.props.className, 'rc-flex-block-child', {
                'rc-flex-block-child-flex': shouldFlexChildren
            });
            if (gutterWidth) {
                style.padding = gutterWidth / 2 + "px";
            }
            return child.type === FlexBlockItem_1.FlexBlockItem ? (React.cloneElement(child, {
                style: __assign({}, style, childWrapperStyle, child.props.style)
            })) : (React.createElement("div", { className: className, style: __assign({}, style, childWrapperStyle) }, child));
        };
        return _this;
    }
    FlexBlock.prototype.renderChildren = function () {
        var _a = this.props, children = _a.children, shouldUnwrapChildren = _a.shouldUnwrapChildren;
        if (shouldUnwrapChildren) {
            return children;
        }
        return React.Children.map(children, this.wrapChild);
    };
    FlexBlock.prototype.render = function () {
        var _a = this.props, direction = _a.direction, align = _a.align, justify = _a.justify, shouldWrap = _a.shouldWrap, gutterWidth = _a.gutterWidth, style = _a.style;
        var className = classnames_1.default('rc-flex-block', this.props.className, {
            'rc-flex-block-vertical': direction === FlexBlockDirectionProperty.COLUMN,
            'rc-flex-block-wrap': shouldWrap,
            'rc-flex-block-align-start': align === FlexBlockAlignProperty.START,
            'rc-flex-block-align-center': align === FlexBlockAlignProperty.CENTER,
            'rc-flex-block-align-end': align === FlexBlockAlignProperty.END,
            'rc-flex-block-justify-start': justify === FlexBlockJustifyProperty.START,
            'rc-flex-block-justify-center': justify === FlexBlockJustifyProperty.CENTER,
            'rc-flex-block-justify-end': justify === FlexBlockJustifyProperty.END,
            'rc-flex-block-justify-space-around': justify === FlexBlockJustifyProperty.SPACE_AROUND,
            'rc-flex-block-justify-space-between': justify === FlexBlockJustifyProperty.SPACE_BETWEEN,
            'rc-flex-block-justify-space-evenly': justify === FlexBlockJustifyProperty.SPACE_EVENLY
        });
        var containerStyle = __assign({}, style);
        if (gutterWidth) {
            containerStyle.margin = "-" + gutterWidth / 2 + "px";
        }
        return (React.createElement("div", { className: className, style: containerStyle }, this.renderChildren()));
    };
    FlexBlock.ROW = FlexBlockDirectionProperty.ROW;
    FlexBlock.COLUMN = FlexBlockDirectionProperty.COLUMN;
    FlexBlock.CENTER = FlexBlockJustifyProperty.CENTER;
    FlexBlock.START = FlexBlockJustifyProperty.START;
    FlexBlock.END = FlexBlockJustifyProperty.END;
    FlexBlock.SPACE_BETWEEN = FlexBlockJustifyProperty.SPACE_BETWEEN;
    FlexBlock.SPACE_AROUND = FlexBlockJustifyProperty.SPACE_AROUND;
    FlexBlock.SPACE_EVENLY = FlexBlockJustifyProperty.SPACE_EVENLY;
    FlexBlock.propTypes = {
        children: PropTypes.node,
        className: PropTypes.string,
        direction: PropTypes.oneOf([
            FlexBlockDirectionProperty.ROW,
            FlexBlockDirectionProperty.COLUMN
        ]),
        align: PropTypes.oneOf([
            FlexBlockJustifyProperty.CENTER,
            FlexBlockJustifyProperty.START,
            FlexBlockJustifyProperty.END
        ]),
        justify: PropTypes.oneOf([
            FlexBlockAlignProperty.CENTER,
            FlexBlockAlignProperty.START,
            FlexBlockAlignProperty.END
        ]),
        gutterWidth: PropTypes.number,
        shouldFlexChildren: PropTypes.bool,
        shouldWrap: PropTypes.bool,
        shouldUnwrapChildren: PropTypes.bool,
        childWrapperStyle: PropTypes.object,
        style: PropTypes.object
    };
    FlexBlock.defaultProps = {
        children: null,
        className: null,
        direction: FlexBlockDirectionProperty.ROW,
        align: null,
        justify: null,
        gutterWidth: 5,
        shouldFlexChildren: false,
        shouldWrap: false,
        shouldUnwrapChildren: false,
        childWrapperStyle: {},
        style: {}
    };
    return FlexBlock;
}(React.PureComponent));
exports.FlexBlock = FlexBlock;
//# sourceMappingURL=FlexBlock.js.map