"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createFormArraySchema = createFormArraySchema;
exports.createFormFieldSchema = createFormFieldSchema;
exports.createFormSchema = createFormSchema;
exports.createSchema = createSchema;
var _constants = require("@inkline/inkline/constants");
var _types = require("@inkline/inkline/types");
function createFormFieldSchema(field) {
  return {
    ..._constants.defaultValidationStateValues,
    ..._constants.defaultValidationFieldValues,
    ...field
  };
}
function createFormArraySchema(items) {
  return items.map(item => {
    if ((0, _types.isFormGroup)(item)) {
      return createSchema(item);
    }
    return createFormFieldSchema(item);
  });
}
function createFormSchema(schema) {
  const resolved = {
    ..._constants.defaultValidationStateValues
  };
  for (const key of Object.keys(schema)) {
    const field = schema[key];
    if (Array.isArray(field)) {
      resolved[key] = createFormArraySchema(field);
    } else if ((0, _types.isFormGroup)(field)) {
      resolved[key] = createSchema(field);
    } else if ((0, _types.isFormField)(field)) {
      resolved[key] = createFormFieldSchema(field);
    }
  }
  return resolved;
}
function createSchema(schema) {
  return createFormSchema(schema);
}