import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
import { isFinite } from 'lodash';
import { typesWithElements } from '../utils';

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

export default function setElementDefaultKeys(config) {
  return typesWithElements.includes(config.type) ? _objectSpread(_objectSpread({}, config), {}, {
    elements: setDefaultKeys(config.elements)
  }) : config;
}
//# sourceMappingURL=setElementDefaultKeys.js.map