import InputType from "./InputType";
import SelectType from "./SelectType";
import DateType from "./DateType";
import { Grid } from "@mui/material";

const componentMap = {
    input: InputType,
    select: SelectType,
    date: DateType,
};

const FormMaker = ({ formInfo, defaultValues, setDefaultValues }) => {
    return (
        <Grid container spacing={1}>
            {formInfo?.map((itemInfo) => {
                const Component = componentMap[itemInfo.type] || null;
                return (
                    <Grid item xs={12} sm={6} md={4} key={itemInfo.id}>
                        {Component ? (
                            <Component
                                itemInfo={itemInfo}
                                defaultValues={defaultValues}
                                setDefaultValues={setDefaultValues}
                            />
                        ) : null}
                    </Grid>
                );
            })}
        </Grid>
    );
};

export default FormMaker;
