import { FormItem } from "/@/components/BasicForm";

export function createFormData(formItems: Array<FormItem>) {
  const formData: Record<string, any> = {};

  for (const item of formItems) {
    const isCheckBox = item.type === "checkbox";
    const isDatepicker = item.type === "date_picker";
    const isRange = item.type === "range";
    const isInputGroup = item.type === "input_group";

    if (isInputGroup) {
      const defaultSelectType = item.otherOptions?.inputGroupOptions[0]?.value || "";
      formData[item.field] = "";
      formData[item.type_field] = defaultSelectType;
    } else {

      const { field, defaultValue } = item;

      if(defaultValue) {
        formData[field] = defaultValue
      }else{
        formData[field] = isCheckBox || isDatepicker || isRange ? [] : "";
      }
    }
  }

  return formData;
}
