import {
  defaultValidationFieldValues,
  defaultValidationStateValues
} from "@inkline/inkline/constants";
import { isFormField, isFormGroup } from "@inkline/inkline/types";
export function createFormFieldSchema(field) {
  return {
    ...defaultValidationStateValues,
    ...defaultValidationFieldValues,
    ...field
  };
}
export function createFormArraySchema(items) {
  return items.map((item) => {
    if (isFormGroup(item)) {
      return createSchema(item);
    }
    return createFormFieldSchema(item);
  });
}
export function createFormSchema(schema) {
  const resolved = {
    ...defaultValidationStateValues
  };
  for (const key of Object.keys(schema)) {
    const field = schema[key];
    if (Array.isArray(field)) {
      resolved[key] = createFormArraySchema(
        field
      );
    } else if (isFormGroup(field)) {
      resolved[key] = createSchema(
        field
      );
    } else if (isFormField(field)) {
      resolved[key] = createFormFieldSchema(field);
    }
  }
  return resolved;
}
export function createSchema(schema) {
  return createFormSchema(schema);
}
