import * as tslib_1 from "tslib";
import React from 'react';
import { Form, Input } from 'antd';
import { PrototypeCheck } from '../utils';
import classNames from 'classnames';
import FormTextareaHint from '../form-textarea-hint';
var FormInput = function (_a) {
    var required = _a.required, label = _a.label, field = _a.field, placeholder = _a.placeholder, max = _a.max, readOnly = _a.readOnly, initialValue = _a.initialValue, valueFilter = _a.valueFilter, form = _a.form, disabled = _a.disabled, inputProps = _a.inputProps, validator = _a.validator, valueType = _a.valueType, allowClear = _a.allowClear, labelCol = _a.labelCol, wrapperCol = _a.wrapperCol, className = _a.className, textarea = _a.textarea, autoSize = _a.autoSize, restProps = tslib_1.__rest(_a, ["required", "label", "field", "placeholder", "max", "readOnly", "initialValue", "valueFilter", "form", "disabled", "inputProps", "validator", "valueType", "allowClear", "labelCol", "wrapperCol", "className", "textarea", "autoSize"]);
    var _b = form, getFieldDecorator = _b.getFieldDecorator, getFieldValue = _b.getFieldValue;
    var rules = [
        required && {
            required: required,
            message: "\u8BF7\u8F93\u5165" + label,
            transform: function (value) {
                if (value) {
                    if (PrototypeCheck.isString(value)) {
                        value.trim();
                    }
                    else if (PrototypeCheck.isNumber(value)) {
                        value = JSON.stringify(value);
                    }
                }
                return value;
            },
        },
    ].concat([
        {
            validator: function (rule, value, callback) {
                if (value && valueType === 'number' && !PrototypeCheck.isNumber(Number(value))) {
                    callback('请输入数字');
                }
                if (value && validator) {
                    validator(rule, value, callback);
                }
                else
                    callback();
            },
        }
    ], (max ? [{ max: max, message: "\u4E0D\u80FD\u8F93\u5165\u8D85\u8FC7" + max + "\u4E2A\u5B57\u7B26" }] : [])).filter(Boolean);
    var commonProps = tslib_1.__assign({ placeholder: placeholder || "\u8BF7\u8F93\u5165" + label }, inputProps, { disabled: disabled });
    return (React.createElement(Form.Item, tslib_1.__assign({}, {
        label: label,
        labelCol: labelCol,
        wrapperCol: wrapperCol,
    }, { className: classNames('rac_form_input', className) }), getFieldDecorator(field, {
        initialValue: initialValue,
        rules: rules,
        validateFirst: true,
        normalize: function (value) {
            if (valueFilter)
                return valueFilter(value);
            return value;
        },
    })(readOnly ? (restProps.render ? (restProps.render(getFieldValue(field))) : (React.createElement("span", null, getFieldValue(field)))) : textarea ? (React.createElement("div", { className: "rac_form_textarea-container" },
        React.createElement(Input.TextArea, tslib_1.__assign({}, commonProps, { value: getFieldValue(field), autosize: autoSize })),
        React.createElement(FormTextareaHint, { value: getFieldValue(field), maxLength: inputProps && inputProps.maxLength }))) : (React.createElement(Input, tslib_1.__assign({}, commonProps, { allowClear: allowClear }))))));
};
export default FormInput;
//# sourceMappingURL=index.js.map