import _defineProperty from 'babel-runtime/helpers/defineProperty';
var _jsxFileName = 'src/grid/Row.jsx';
/**
 * row.jsx
 *
 * @Author: jruif
 * @Date: 2017/7/5 下午4:38
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { isObject } from '../util/isType';
import extend from 'object-assign';

var propTypes = {
    /** 水平对齐，`left`以及`right` 将被移除*/
    justify: PropTypes.oneOf(['start', 'end', 'center', 'between', 'around', 'left', 'right']),
    /** 垂直对齐*/
    align: PropTypes.oneOf(['top', 'bottom', 'middle', 'stretch']),
    /** 栅格间隔*/
    gutter: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), //栅格间隔 20
    /** @ignore*/
    number: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), //个数 24
    /** @ignore*/
    prefixCls: PropTypes.string,
    /** 是否不设置最大宽*/
    expanded: PropTypes.bool,
    /** 是否折叠（Row的marginLeft、marginRight和Col的paddingLeft、paddingRight叠加）*/
    collapse: PropTypes.bool
};

var defaultProps = {
    prefixCls: 'row',
    gutter: 20,
    number: 24,
    expanded: false,
    collapse: false
};

/**
 * Row
 * */
export default function Row(props) {
    var _classNames;

    var prefixCls = props.prefixCls,
        children = props.children,
        expanded = props.expanded,
        collapse = props.collapse,
        justify = props.justify,
        align = props.align,
        className = props.className,
        gutter = props.gutter,
        style = props.style;

    var classes = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-justify-' + (justify === 'left' ? 'start' : justify === 'right' ? 'end' : justify), justify), _defineProperty(_classNames, prefixCls + '-align-' + align, align), _defineProperty(_classNames, 'expanded', expanded), _defineProperty(_classNames, 'collapse', collapse), _classNames), className);

    var preGutter = Number(gutter) / 2;

    return React.createElement(
        'div',
        {
            className: classes,
            style: extend(preGutter !== 10 // 20使用默认样式处理
            ? {
                marginLeft: -preGutter,
                marginRight: -preGutter
            } : {}, style), __source: {
                fileName: _jsxFileName,
                lineNumber: 58
            },
            __self: this
        },
        React.Children.map(children, function (child) {
            var childType = child ? isObject(child.type) || typeof child.type === 'function' ? child.type.displayName || child.type.name : child.type : child;
            if (childType === 'NeatUI.Col' && preGutter !== 10) {
                return React.cloneElement(child, {
                    colStyle: {
                        paddingLeft: preGutter,
                        paddingRight: preGutter
                    }
                });
            }
            return child;
        })
    );
}

Row.propTypes = propTypes;
Row.defaultProps = defaultProps;
Row.displayName = 'NeatUI.Row';