import { createFormFieldSchema } from "@inkline/inkline/validation";
import { defaultValidationStateValues } from "@inkline/inkline/constants";
export function createSchemaFromDefaults(defaultValues) {
  const resolved = {
    ...defaultValidationStateValues
  };
  for (const key of Object.keys(defaultValues)) {
    const field = defaultValues[key];
    if (Array.isArray(field)) {
      resolved[key] = field.map((item) => {
        if (typeof item === "object") {
          return createSchemaFromDefaults(item);
        }
        return createFormFieldSchema({ value: item });
      });
    } else if (typeof field === "object") {
      resolved[key] = createSchemaFromDefaults(field);
    } else {
      resolved[key] = createFormFieldSchema({
        value: field
      });
    }
  }
  return resolved;
}
