import BasicForm, { DefaultValidateFunction, } from "./BasicForm";
import React, { useEffect, useState, } from "react";
const BasicModelForm = (props) => {
    const [formFields, setFormFields] = useState([]);
    let initialValues = {};
    if (props.initialValues) {
        initialValues = Object.assign({}, props.initialValues);
    }
    useEffect(() => {
        const fields = [];
        // Prep
        for (const field of props.fields) {
            if (Object.keys(field.field || {}).length > 0) {
                if (props.model.getDisplayColumnTitleAs(Object.keys(field.field || {})[0]) &&
                    !field.title) {
                    field.title = props.model.getDisplayColumnTitleAs(Object.keys(field.field || {})[0]);
                }
                if (props.model.getDisplayColumnDescriptionAs(Object.keys(field.field || {})[0]) &&
                    !field.description) {
                    field.description = props.model.getDisplayColumnDescriptionAs(Object.keys(field.field || {})[0]);
                }
            }
            fields.push(field);
        }
        setFormFields(fields);
    }, [props.fields]);
    return (React.createElement(BasicForm, { values: props.values, isLoading: props.isLoading || false, fields: formFields, id: props.id, onChange: props.onChange, onValidate: props.onValidate ? props.onValidate : DefaultValidateFunction, disableAutofocus: props.disableAutofocus, steps: props.steps, name: props.name, onFormStepChange: props.onFormStepChange, submitButtonStyleType: props.submitButtonStyleType, onSubmit: props.onSubmit, initialValues: initialValues, submitButtonText: props.submitButtonText || "Save", title: props.title || "", description: props.description || "", footer: props.footer, showAsColumns: props.showAsColumns || 1, onCancel: props.onCancel, cancelButtonText: props.cancelButtonText, maxPrimaryButtonWidth: props.maxPrimaryButtonWidth || false, error: props.error, onIsLastFormStep: props.onIsLastFormStep, hideSubmitButton: props.hideSubmitButton, ref: props.formRef, summary: props.summary }));
};
export default BasicModelForm;
//# sourceMappingURL=BasicModelForm.js.map