'use strict';

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

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = function (data) {
  // Sort items by the order field.

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

  if (!items) {
    return data;
  }

  var normalizedItems = void 0;

  if (!_immutable2.default.List.isList(items)) {
    normalizedItems = _immutable2.default.List.of(items);
  } else {
    normalizedItems = items.sortBy(function (item) {
      return item.get('order');
    });
  }

  return data.setIn(itemPath, normalizedItems);
};