import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
var _jsxFileName = 'src/form/FormItem.jsx';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Icon from '../icon';
import { Col, Row } from '../grid';

FormItem.propTypes = {
    /**
     * 是否为行内布局
     */
    inline: PropTypes.bool,
    prefixCls: PropTypes.string,
    /**
     * label 标签的文本
     */
    label: PropTypes.node,
    /**
     * 提示文本
     */
    helperText: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.string]),
    /**
     * 提示文本渲染函数 function(text) => textNode: reactNode
     */
    helperTextRender: PropTypes.func,
    /**
     * 附加信息，当需要错误信息和提示文案同时出现时使用
     */
    extraInfo: PropTypes.string,
    /**
     * 表单项校验结果状态
     */
    validateStatus: PropTypes.oneOf(['initial', 'success', 'error']),
    /**
     * 表单项尺寸
     */
    size: PropTypes.oneOf(['small', 'medium', 'large']),
    /**
     * 表单项师傅校验中
     */
    validating: PropTypes.bool,
    /**
     * 是否禁用
     */
    disabled: PropTypes.bool,
    /**
     * 表单项唯一表识，与formData, errorMsg, formValidatingStatus对应项关联
     */
    name: PropTypes.string,
    /**
     * input元素Id
     * */
    inputId: PropTypes.string,
    /**
     * 状态icon布局，同 Col 组件，设置 span offset 值，如 {span: 3, offset: 12}
     */
    statusIconLayout: PropTypes.object,
    /**
     * helperText 属性
     */
    helperTextProps: PropTypes.object,
    /**
     * label布局，同 Col 组件，设置 span offset 值，如 {span: 3, offset: 12}
     */
    labelLayout: PropTypes.object,
    /**
     * 表单项内容布局，同 Col 组件，设置 span offset 值，如 {span: 3, offset: 12}
     */
    inputLayout: PropTypes.object,
    /**
     * 初始状态icon
     */
    initialIcon: PropTypes.node,
    /**
     * 校验失败状态icon
     */
    errorIcon: PropTypes.node,
    /**
     * 校验通过状态icon
     */
    successIcon: PropTypes.node,
    /**
     * 校验中状态icon
     */
    validatingIcon: PropTypes.node,
    /**
     * 是否显示状态icon
     */
    showStatusIcon: PropTypes.bool
};
FormItem.defaultProps = {
    labelLayout: {
        size: 8
    },
    inputLayout: {},
    statusIconLayout: {
        size: 4
    },
    validating: false,
    helperText: [],
    helperTextProps: {},
    prefixCls: 'ne-form-item',
    validateStatus: 'initial',
    disabled: false,
    validatingIcon: React.createElement(Icon, { type: 'spin4', spin: true, __source: {
            fileName: _jsxFileName,
            lineNumber: 104
        },
        __self: this
    }),
    successIcon: React.createElement(Icon, { type: 'ok-o', __source: {
            fileName: _jsxFileName,
            lineNumber: 105
        },
        __self: this
    }),
    errorIcon: React.createElement(Icon, { type: 'cancel-o', __source: {
            fileName: _jsxFileName,
            lineNumber: 106
        },
        __self: this
    }),
    showStatusIcon: true,
    size: 'medium'
};

/**
 * FormItem
 * @description FormItem与校验函数无关，只负责表单样式。
 * */
export default function FormItem(props) {
    var _classNames;

    var prefixCls = props.prefixCls,
        label = props.label,
        className = props.className,
        validateStatus = props.validateStatus,
        validating = props.validating,
        children = props.children,
        name = props.name,
        disabled = props.disabled,
        helperTextProps = props.helperTextProps,
        initialIcon = props.initialIcon,
        validatingIcon = props.validatingIcon,
        successIcon = props.successIcon,
        errorIcon = props.errorIcon,
        helperTextRender = props.helperTextRender,
        labelLayout = props.labelLayout,
        inputLayout = props.inputLayout,
        statusIconLayout = props.statusIconLayout,
        inputId = props.inputId,
        extraInfo = props.extraInfo,
        inline = props.inline,
        showStatusIcon = props.showStatusIcon,
        size = props.size,
        other = _objectWithoutProperties(props, ['prefixCls', 'label', 'className', 'validateStatus', 'validating', 'children', 'name', 'disabled', 'helperTextProps', 'initialIcon', 'validatingIcon', 'successIcon', 'errorIcon', 'helperTextRender', 'labelLayout', 'inputLayout', 'statusIconLayout', 'inputId', 'extraInfo', 'inline', 'showStatusIcon', 'size']);

    var helperText = props.helperText;

    var classes = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, prefixCls + '-disabled', disabled), _defineProperty(_classNames, prefixCls + '-validating', validating), _defineProperty(_classNames, prefixCls + '-inline', inline), _classNames), prefixCls + '-' + validateStatus, className);
    var Label = label ? 'label' : 'span';
    var icons = {
        inital: initialIcon,
        success: successIcon,
        error: errorIcon
    };
    var icon = validating ? validatingIcon : icons[validateStatus];
    if (typeof helperText === 'string') {
        helperText = [helperText];
    }
    delete other.helperText;
    return React.createElement(
        Row,
        Object.assign({ className: classes }, other, {
            __source: {
                fileName: _jsxFileName,
                lineNumber: 164
            },
            __self: this
        }),
        inline && (label === '' || label === void 0) ? null : React.createElement(
            Col,
            Object.assign({}, labelLayout, { className: prefixCls + '-col', __source: {
                    fileName: _jsxFileName,
                    lineNumber: 166
                },
                __self: this
            }),
            React.createElement(
                Label,
                {
                    htmlFor: inputId || name,
                    className: classNames(prefixCls + '-label', _defineProperty({}, prefixCls + '-label-' + size, size)), __source: {
                        fileName: _jsxFileName,
                        lineNumber: 167
                    },
                    __self: this
                },
                label
            )
        ),
        React.createElement(
            Col,
            Object.assign({
                className: classNames(prefixCls + '-content', prefixCls + '-col', _defineProperty({}, prefixCls + '-content-' + size, size))
            }, inputLayout, {
                __source: {
                    fileName: _jsxFileName,
                    lineNumber: 174
                },
                __self: this
            }),
            React.createElement(
                'div',
                { className: prefixCls + '-input', __source: {
                        fileName: _jsxFileName,
                        lineNumber: 179
                    },
                    __self: this
                },
                children
            ),
            helperText.length > 0 && React.createElement(
                'span',
                Object.assign({ className: prefixCls + '-helper-text' }, helperTextProps, {
                    __source: {
                        fileName: _jsxFileName,
                        lineNumber: 181
                    },
                    __self: this
                }),
                helperTextRender ? helperTextRender(helperText) : helperText[helperText.length - 1]
            ),
            extraInfo ? React.createElement(
                'span',
                Object.assign({ className: prefixCls + '-extra-info' }, helperTextProps, {
                    __source: {
                        fileName: _jsxFileName,
                        lineNumber: 186
                    },
                    __self: this
                }),
                extraInfo
            ) : null
        ),
        showStatusIcon ? React.createElement(
            Col,
            Object.assign({}, statusIconLayout, {
                className: classNames(prefixCls + '-status', prefixCls + '-col', _defineProperty({}, prefixCls + '-status-' + size, size)), __source: {
                    fileName: _jsxFileName,
                    lineNumber: 192
                },
                __self: this
            }),
            icon
        ) : null
    );
}