"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.serializeSchema = serializeSchema;
var _types = require("@inkline/inkline/types");
var _constants = require("@inkline/inkline/constants");
function serializeSchema(schema) {
  const serializedSchema = {};
  Object.keys(schema).forEach(key => {
    if (!schema.hasOwnProperty(key) || _constants.reservedValidationFields.includes(key)) {
      return;
    }
    const schemaField = schema[key];
    if (Array.isArray(schemaField)) {
      serializedSchema[key] = schemaField.map(item => {
        if ((0, _types.isFormGroup)(item)) {
          return serializeSchema(item);
        }
        return item.value;
      });
    } else if ((0, _types.isFormGroup)(schemaField)) {
      serializedSchema[key] = serializeSchema(schemaField);
    } else if ((0, _types.isFormField)(schemaField)) {
      serializedSchema[key] = schemaField.value;
    }
  });
  return serializedSchema;
}