function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

var ungroupBy = function ungroupBy(data, dataSeriesKeys, dataSeriesLabels) {
  var arr = [];
  var labels = [];

  if (!dataSeriesLabels) {
    labels.push.apply(labels, _toConsumableArray(dataSeriesKeys));
  } else if (dataSeriesKeys.length === dataSeriesLabels.length) {
    labels.push.apply(labels, _toConsumableArray(dataSeriesLabels));
  } else {
    labels.push.apply(labels, _toConsumableArray(dataSeriesKeys));
  }

  dataSeriesKeys.forEach(function (key, index) {
    arr.push.apply(arr, _toConsumableArray(data.map(function (obj) {
      var retObj = Object.assign({}, obj);
      retObj.value = obj[key];
      retObj.type = labels[index];
      dataSeriesKeys.forEach(function (k) {
        return delete retObj[k];
      });
      return retObj;
    })));
  });
  return arr;
};

export default ungroupBy;