"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

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

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

var _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, number}\u2013{endNum, number} of {totalItems, number} uses}} found"
        },
        searching: {
          "id": "list.refDoc.searching",
          "defaultMessage": "Finding uses..."
        }
      }),
      getItemLocationPath: (item, _ref) => {
        let {
          config
        } = _ref;
        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/".concat(recordTypeConfig.name, "/").concat(vocabularyConfig.name, "/").concat(csid);
            }
          } else {
            return "/record/".concat(recordTypeConfig.name, "/").concat(csid);
          }
        }

        return null;
      }
    }
  }
});

exports.default = _default;