"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _excluded = ["title", "default"],
    _excluded2 = ["ui:description", "ui:help"];
var nonListFields = ['boolean', 'consent', 'tableField'];

var getDefaultByType = function getDefaultByType(type) {
  switch (type) {
    case 'text':
    case 'textarea':
    case 'richtext':
    case 'email':
    case 'password':
      return '';

    case 'formGroup':
      return {};

    default:
      return undefined;
  }
};

var _default = function _default(config) {
  return function (props) {
    if (config.list && !nonListFields.includes(config.type)) {
      var _itemsUISchema$uiOpt, _itemsUISchema$uiOpt$;

      var _props$schema = props.schema,
          title = _props$schema.title,
          defaults = _props$schema["default"],
          itemsSchema = (0, _objectWithoutProperties2["default"])(_props$schema, _excluded);
      var _config$emptyDefault = config.emptyDefault,
          emptyDefault = _config$emptyDefault === void 0 ? false : _config$emptyDefault;
      var _props$uiSchema = props.uiSchema,
          description = _props$uiSchema['ui:description'],
          help = _props$uiSchema['ui:help'],
          itemsUISchema = (0, _objectWithoutProperties2["default"])(_props$uiSchema, _excluded2);
      var type = itemsUISchema === null || itemsUISchema === void 0 ? void 0 : (_itemsUISchema$uiOpt = itemsUISchema['ui:options']) === null || _itemsUISchema$uiOpt === void 0 ? void 0 : (_itemsUISchema$uiOpt$ = _itemsUISchema$uiOpt.element) === null || _itemsUISchema$uiOpt$ === void 0 ? void 0 : _itemsUISchema$uiOpt$.type;
      var defaultByType = defaults !== null && defaults !== void 0 ? defaults : getDefaultByType(type);
      props.schema = {
        title: title,
        type: 'array',
        items: itemsSchema,
        maxItems: config.maxItems,
        minItems: config.minItems,
        extraListOptions: config.extraListOptions,
        "default": emptyDefault ? [] : config.minItems > 1 ? Array(config.minItems).fill(defaultByType) : [defaultByType]
      };
      props.uiSchema = {
        'ui:description': description,
        'ui:help': help,
        items: itemsUISchema
      };
    }
  };
};

exports["default"] = _default;
//# sourceMappingURL=repeatableFieldSupport.cjs.map