"use strict";

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

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

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

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

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

var _editableHtml = require("@pie-lib/editable-html");

var _modals = require("./modals");

var _excluded = ["scorePointsDescriptors"],
    _excluded2 = ["scorePointsDescriptors"],
    _excluded3 = ["scorePointsDescriptors"],
    _excluded4 = ["scorePointsDescriptors"];

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 filteredDefaultPlugins = (_editableHtml.DEFAULT_PLUGINS || []).filter(function (p) {
  return p !== 'table' && p !== 'bulleted-list' && p !== 'numbered-list';
});
exports.filteredDefaultPlugins = filteredDefaultPlugins;

var addOrRemoveScaleColumn = function addOrRemoveScaleColumn(scales, excludeZeroType) {
  if (!scales || !scales.length) {
    return [];
  }

  return scales.reduce(function (acc, scale) {
    var _ref = scale || {},
        scorePointsLabels = _ref.scorePointsLabels,
        traits = _ref.traits;

    if (scorePointsLabels.length < 1) {
      return acc;
    }

    switch (excludeZeroType) {
      case _modals.excludeZeroTypes.remove0:
        {
          // removes column 0
          scorePointsLabels = scorePointsLabels.slice(1);
          traits = traits.map(function (_ref2) {
            var scorePointsDescriptors = _ref2.scorePointsDescriptors,
                trait = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
            return _objectSpread(_objectSpread({}, trait), {}, {
              scorePointsDescriptors: scorePointsDescriptors.slice(1)
            });
          });
          break;
        }

      case _modals.excludeZeroTypes.add0:
        {
          // adds empty column at start
          scorePointsLabels = [''].concat((0, _toConsumableArray2["default"])(scorePointsLabels));
          traits = traits.map(function (_ref3) {
            var scorePointsDescriptors = _ref3.scorePointsDescriptors,
                trait = (0, _objectWithoutProperties2["default"])(_ref3, _excluded2);
            return _objectSpread(_objectSpread({}, trait), {}, {
              scorePointsDescriptors: [''].concat((0, _toConsumableArray2["default"])(scorePointsDescriptors))
            });
          });
          break;
        }

      case _modals.excludeZeroTypes.shiftLeft:
        {
          // removes last column
          scorePointsLabels = scorePointsLabels.slice(0, -1);
          traits = traits.map(function (_ref4) {
            var scorePointsDescriptors = _ref4.scorePointsDescriptors,
                trait = (0, _objectWithoutProperties2["default"])(_ref4, _excluded3);
            return _objectSpread(_objectSpread({}, trait), {}, {
              scorePointsDescriptors: scorePointsDescriptors.slice(0, -1)
            });
          });
          break;
        }

      case _modals.excludeZeroTypes.shiftRight:
        {
          // adds empty column at end
          scorePointsLabels = [].concat((0, _toConsumableArray2["default"])(scorePointsLabels), ['']);
          traits = traits.map(function (_ref5) {
            var scorePointsDescriptors = _ref5.scorePointsDescriptors,
                trait = (0, _objectWithoutProperties2["default"])(_ref5, _excluded4);
            return _objectSpread(_objectSpread({}, trait), {}, {
              scorePointsDescriptors: [].concat((0, _toConsumableArray2["default"])(scorePointsDescriptors), [''])
            });
          });
          break;
        }

      default:
        break;
    }

    acc.push(_objectSpread(_objectSpread({}, scale), {}, {
      scorePointsLabels: scorePointsLabels,
      traits: traits
    }));
    return acc;
  }, []);
};

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