import { __assign, __rest } from "tslib";
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var spaceSize = {
    sm: 8,
    md: 16,
    lg: 24,
};
var Space = React.forwardRef(function (props, ref) {
    var _a = props.direction, direction = _a === void 0 ? 'horizontal' : _a, _b = props.align, align = _b === void 0 ? 'center' : _b, className = props.className, children = props.children, customisedCls = props.prefixCls, otherProps = __rest(props, ["direction", "align", "className", "children", "prefixCls"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('space', configContext.prefixCls, customisedCls);
    var size = props.size || configContext.space || 'sm';
    var cls = classNames(prefixCls, className, prefixCls + "_" + direction, prefixCls + "_" + align);
    var getItemStyle = function (idx) {
        var _a;
        if (React.Children.count(children) - 1 !== idx) {
            return _a = {},
                _a[direction === 'vertical' ? 'marginBottom' : 'marginRight'] = typeof props.size === 'number' ? size : spaceSize[size],
                _a;
        }
        return {};
    };
    return (React.createElement("div", __assign({}, otherProps, { ref: ref, className: cls }), React.Children.map(children, function (child, idx) { return (React.createElement("div", { key: idx, className: prefixCls + "__item", style: getItemStyle(idx) }, child)); })));
});
Space.displayName = 'Space';
export default Space;
//# sourceMappingURL=index.js.map