import * as tslib_1 from "tslib";
import React, { useEffect, useImperativeHandle } from 'react';
import { Form } from 'antd';
import classNames from 'classnames';
import { usePrevious } from 'react-use';
import isEqual from 'react-fast-compare';
import { FormInput, FormDate, FormSelect, FormInputSearch, FormRadio, FormUpload, FormInputMultiple, FormCustom, FormCheckbox, FormGroup, } from '..';
var FormComps = {
    input: FormInput,
    date: FormDate,
    select: FormSelect,
    inputSearch: FormInputSearch,
    radio: FormRadio,
    upload: FormUpload,
    inputMultiple: FormInputMultiple,
    custom: FormCustom,
    checkbox: FormCheckbox,
    group: FormGroup,
};
var FormContainer = function (props, ref) {
    var data = props.data, labelCol = props.labelCol, wrapperCol = props.wrapperCol, form = props.form, rest = tslib_1.__rest(props, ["data", "labelCol", "wrapperCol", "form"]);
    var setFieldsValue = form.setFieldsValue;
    var prevData = usePrevious(data);
    var renderForm = function (Component, field) {
        var _labelCol = { xs: { span: 24 }, sm: { span: 5 } }, _wrapperCol = { xs: { span: 24 }, sm: { span: 12 } };
        var _props = tslib_1.__assign({ form: props.form, labelCol: labelCol || _labelCol, wrapperCol: wrapperCol || _wrapperCol }, field);
        return React.createElement(Component, tslib_1.__assign({}, _props));
    };
    useEffect(function () {
        if (!isEqual(data, prevData))
            setFieldsValue(data);
    }, [data, prevData, setFieldsValue]);
    useImperativeHandle(ref, function () { return ({
        form: props.form,
    }); });
    return (React.createElement(Form, tslib_1.__assign({}, rest, { className: classNames('rac_fc', rest.className) }), props.fields.map(function (field, index) { return (React.createElement("div", { key: field.field || index, style: tslib_1.__assign({ flexBasis: field.width || '50%' }, field.style) }, renderForm(FormComps[field.fieldType], field))); })));
};
export default Form.create({
    onValuesChange: function (props, changedValues, allValues) {
        props.onValuesChange && props.onValuesChange(changedValues, allValues);
    },
})(React.memo(React.forwardRef(FormContainer)));
//# sourceMappingURL=index.js.map