"use strict";

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

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

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

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

var _lodash = require("lodash");

var _utils = require("../utils");

var setDefaultKeys = function setDefaultKeys() {
  var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var indexKey = Math.max.apply(Math, [-1].concat((0, _toConsumableArray2["default"])(elements.map(function (element) {
    return element === null || element === void 0 ? void 0 : element.key;
  }).map(Number).filter(_lodash.isFinite))));
  return elements.map(function (element) {
    return (element === null || element === void 0 ? void 0 : element.key) === undefined ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, element), {}, {
      key: String(++indexKey)
    }) : element;
  }).map(setElementDefaultKeys);
};

function setElementDefaultKeys(config) {
  return _utils.typesWithElements.includes(config.type) ? (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, config), {}, {
    elements: setDefaultKeys(config.elements)
  }) : config;
}
//# sourceMappingURL=setElementDefaultKeys.cjs.map