'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
var normalizeDate = function normalizeDate(date) {
  if (!date) {
    return null;
  }

  var index = date.indexOf('T');

  if (index >= 0) {
    return date.substring(0, index);
  }

  return date;
};

exports.default = function (pluginContext) {
  return function (cspaceDocument) {
    var getPart = pluginContext.recordDataHelpers.getPart;
    var getDisplayName = pluginContext.refNameHelpers.getDisplayName;


    if (!cspaceDocument) {
      return '';
    }

    var common = getPart(cspaceDocument, 'movements_common');

    if (!common) {
      return '';
    }

    var currentLocation = getDisplayName(common.get('currentLocation'));
    var locationDate = normalizeDate(common.get('locationDate'));

    return [currentLocation, locationDate].filter(function (part) {
      return !!part;
    }).join(' – ');
  };
};