'use strict';

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

var _reactIntl = require('react-intl');

var _cspaceRefname = require('cspace-refname');

var _configHelpers = require('../../helpers/configHelpers');

exports.default = () => ({
  listTypes: {
    refDoc: {
      listNodeName: 'ns3:authority-ref-doc-list',
      itemNodeName: 'authority-ref-doc-item',
      // NB: This is a list of uses, not records: a record may appear multiple times in the list,
      // if it uses the authority item multiple times in different fields (or different instances
      // of a repeating field). The messages reflect this.
      messages: (0, _reactIntl.defineMessages)({
        resultCount: {
          'id': 'list.refDoc.resultCount',
          'defaultMessage': '{totalItems, plural, =0 {No uses} one {1 use} other {{startNum}\u2013{endNum} of {totalItems} uses}} found'
        },
        searching: {
          'id': 'list.refDoc.searching',
          'defaultMessage': 'Finding uses...'
        }
      }),
      getItemLocationPath: (item, { config }) => {
        const refName = item.get('refName');
        const csid = item.get('docId');
        const servicePath = (0, _cspaceRefname.getServicePath)(refName);
        const recordTypeConfig = (0, _configHelpers.getRecordTypeConfigByServicePath)(config, servicePath);

        if (recordTypeConfig) {
          if (recordTypeConfig.serviceConfig.serviceType === 'authority') {
            const vocabularyShortID = (0, _cspaceRefname.getVocabularyShortID)(refName);

            const vocabularyConfig = (0, _configHelpers.getVocabularyConfigByShortID)(recordTypeConfig, vocabularyShortID);

            if (vocabularyConfig) {
              return `/record/${recordTypeConfig.name}/${vocabularyConfig.name}/${csid}`;
            }
          } else {
            return `/record/${recordTypeConfig.name}/${csid}`;
          }
        }

        return null;
      }
    }
  }
});