import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';

function sortRobotMapByRobot() {
  var robotMap = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  if (!robotMap) {
    return robotMap;
  }
  var list = Object.keys(robotMap).map(function (branch) {
    return Object.assign(Object.assign({}, robotMap[branch]), {
      branch: branch
    });
  });
  list.sort(function (a, b) {
    return a.test - b.test;
  });
  var result = list.reduce(function (acc, item) {
    var branch = item.branch;
    acc[branch] = Object.assign({}, item);
    delete acc[branch].branch;
    return acc;
  }, {});
  return result;
}
function findEmptyLine(lines) {
  // 3,4,5 ... 102
  var fakeList = Array.from({
    length: 100
  }).map(function (_, i) {
    return i + 3;
  });
  var rest = fakeList.filter(function (item) {
    return !lines.includes(item);
  });
  return rest;
}
function updateQQTencentSheetLine(rainbowConfig) {
  var _ref = rainbowConfig || {},
    _ref$qqRobotMap = _ref.qqRobotMap,
    qqRobotMap = _ref$qqRobotMap === void 0 ? {} : _ref$qqRobotMap;
  var lines = [];
  Object.keys(qqRobotMap).forEach(function (branch) {
    var value = qqRobotMap[branch] || {};
    var _value$tencentDocsLin = value.tencentDocsLine,
      tencentDocsLine = _value$tencentDocsLin === void 0 ? {} : _value$tencentDocsLin;
    var curLines = Object.values(tencentDocsLine).map(function (item) {
      return +item;
    });
    lines.push.apply(lines, _toConsumableArray(curLines));
  });
  var restLines = findEmptyLine(lines);
  var cur = 0;
  Object.keys(qqRobotMap).forEach(function (branch) {
    var value = qqRobotMap[branch] || {};
    if (!value.tencentDocsLine || !Object.keys(value.tencentDocsLine).length) {
      var temp = {};
      if (value.test) {
        temp.test = restLines[cur];
        cur += 1;
      }
      if (value.release) {
        temp.release = restLines[cur];
        cur += 1;
      }
      value.tencentDocsLine = temp;
    }
  });
}

export { sortRobotMapByRobot, updateQQTencentSheetLine };
