import * as tslib_1 from "tslib";
import React from 'react';
import { Form, DatePicker } from 'antd';
import moment from 'moment';
import locale from 'antd/lib/date-picker/locale/zh_CN';
import 'moment/locale/zh-cn';
var FormDate = function (props) {
    var label = props.label, labelCol = props.labelCol, wrapperCol = props.wrapperCol, isRange = props.isRange, field = props.field, initialValue = props.initialValue, required = props.required, mountContainer = props.mountContainer, validator = props.validator, onChange = props.onChange, dateProps = props.dateProps, format = props.format, showTime = props.showTime;
    var _a = props.form, getFieldDecorator = _a.getFieldDecorator, getFieldValue = _a.getFieldValue, setFieldsValue = _a.setFieldsValue;
    return (React.createElement(Form.Item, tslib_1.__assign({}, {
        label: label,
        labelCol: labelCol,
        wrapperCol: wrapperCol,
    }, { className: props.className }), getFieldDecorator(field, {
        initialValue: initialValue,
        rules: [
            { required: required, message: "\u8BF7\u9009\u62E9" + label },
            {
                validator: function (rule, value, callback) {
                    return validator ? validator(rule, value, callback) : callback();
                },
            },
        ],
        normalize: function (value) {
            if (value && value.length > 0) {
                if (isRange && !moment.isMoment(value[0]))
                    return [moment(value[0]), moment(value[1])];
                if (!isRange && !moment.isMoment(value))
                    return moment(value);
            }
            return value;
        },
    })(props.readOnly ? (props.render ? (props.render(getFieldValue(field))) : (React.createElement("span", null, moment.isMoment(getFieldValue(field))
        ? getFieldValue(field).format('YYYY-MM-DD')
        : getFieldValue(field)))) : isRange ? (React.createElement(DatePicker.RangePicker, tslib_1.__assign({}, tslib_1.__assign({}, (mountContainer && {
        getPopupContainer: function () { return document.getElementById(mountContainer); },
    })), { onChange: function (date, dateString) {
            return onChange && onChange(date, dateString, setFieldsValue);
        } }, dateProps, { locale: locale }))) : (React.createElement(DatePicker, tslib_1.__assign({ style: { width: '100%' }, showTime: showTime }, dateProps, { format: format, placeholder: "\u8BF7\u9009\u62E9" + label, onChange: function (date, dateString) {
            return onChange && onChange(date, dateString, setFieldsValue);
        } }, (mountContainer && {
        getPopupContainer: function () { return document.getElementById(mountContainer); },
    })))))));
};
export default FormDate;
//# sourceMappingURL=index.js.map