'use strict';

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

exports.default = configContext => data => {
  const Immutable = configContext.lib.Immutable;

  // Sort items by the order field.

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

  if (!items) {
    return data;
  }

  let normalizedItems;

  if (!Immutable.List.isList(items)) {
    normalizedItems = Immutable.List.of(items);
  } else {
    normalizedItems = items.sortBy(item => item.get('order'));
  }

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