"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.transformToKeySetStructure = exports.toKey = exports.toArray = exports.mkSet = exports.extendKeySet = void 0;

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

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

var _lodash = _interopRequireDefault(require("lodash"));

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; }

var mkSet = function mkSet(category) {
  return function (o) {
    return _objectSpread(_objectSpread({}, o), {}, {
      category: category
    });
  };
};

exports.mkSet = mkSet;

var toArray = function toArray(o) {
  return Object.keys(o).map(function (k) {
    return o[k];
  });
};

exports.toArray = toArray;

var toKey = function toKey(category) {
  return function (v) {
    if (typeof v === 'string') {
      return {
        name: v,
        label: v,
        category: category,
        write: v
      };
    } else {
      return _objectSpread(_objectSpread({}, v), {}, {
        category: category
      });
    }
  };
};

exports.toKey = toKey;

var transformToKeySetStructure = function transformToKeySetStructure() {
  var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var structure = [];

  _lodash["default"].times(5, function () {
    structure.push([]);
  });

  var ln = data.length;
  var i = 0;
  var j = 0;

  while (j < ln) {
    structure[i++].push(data[j++]);

    if (i === 5) {
      i = 0;
    }
  }

  return structure;
};

exports.transformToKeySetStructure = transformToKeySetStructure;

var latexAndNameDontExist = function latexAndNameDontExist(base) {
  return function (k) {
    var flattened = _lodash["default"].flatten(base);

    var latexExists = flattened.some(function (b) {
      return b.latex === k.latex;
    });
    var nameExists = flattened.some(function (b) {
      return b.name === k.name;
    });
    return !latexExists && !nameExists;
  };
};

var extendKeySet = function extendKeySet() {
  var base = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  var keySetData = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
  keySetData = keySetData.filter(latexAndNameDontExist(base));
  var _final = [];

  _lodash["default"].times(5 - base.length, function () {
    base.push([]);
  });

  _lodash["default"].times(5, function () {
    _final.push([]);
  });

  var extra = transformToKeySetStructure(keySetData);

  for (var i = 0; i < 5; i++) {
    _final[i] = [].concat((0, _toConsumableArray2["default"])(base[i]), (0, _toConsumableArray2["default"])(extra[i]));
  }

  return _final;
};

exports.extendKeySet = extendKeySet;
//# sourceMappingURL=utils.js.map