"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.normalizeChoices = exports.firstAvailableIndex = void 0;

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

var _includes = _interopRequireDefault(require("lodash/includes"));

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

/**
 * Add value to every model.choices.
 * @param {Object} model the model to normalize
 * @return {Object} the updated model
 */
var normalizeChoices = function normalizeChoices(model) {
  var choices = model.choices.map(function (c, index) {
    if (!c.value) {
      c.value = "".concat(index);
    }

    return c;
  });
  return _objectSpread(_objectSpread({}, model), {}, {
    choices: choices
  });
};
/**
 * Find the first available index.
 * @param {string[]} values
 * @param {number} index
 * @return {string}
 */


exports.normalizeChoices = normalizeChoices;

var firstAvailableIndex = function firstAvailableIndex(values, index) {
  if ((0, _includes["default"])(values, "".concat(index))) {
    return firstAvailableIndex(values, index + 1);
  } else {
    return "".concat(index);
  }
};

exports.firstAvailableIndex = firstAvailableIndex;
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb2RlL2NvbmZpZy11aS9jaG9pY2UtdXRpbHMuanMiXSwibmFtZXMiOlsibm9ybWFsaX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