'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

exports.default = function (data) {
  // Set the order on each term to its position in the list.

  var termsPath = ['document', 'ns2:abstract-common-list', 'list-item'];
  var terms = data.getIn(termsPath);

  if (!terms) {
    return data;
  }

  var updatedTerms = terms.filter(function (term) {
    return !!term;
  }).map(function (term, index) {
    return term.set('order', index.toString().padStart(4, '0'))
    // Remove fields that the services layer would ignore anyway.
    .delete('rev').delete('sas').delete('proposed').delete('uri').delete('updatedAt').delete('workflowState').delete('refName').delete('deprecated');
  });

  if (updatedTerms.size === 0) {
    return data.deleteIn(termsPath);
  }

  return data.setIn(termsPath, updatedTerms);
};