"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 _permissionHelpers = require("../../helpers/permissionHelpers");

var _default = () => ({
  listTypes: {
    authRef: {
      listNodeName: 'ns3:authority-ref-list',
      itemNodeName: 'authority-ref-item',
      // NB: This is a list of terms, not records: a record may appear multiple times in the list,
      // if multiple synonyms are used by the record. The messages reflect this.
      messages: (0, _reactIntl.defineMessages)({
        resultCount: {
          "id": "list.authRef.resultCount",
          "defaultMessage": "{totalItems, plural, =0 {No terms} one {1 term} other {{startNum, number}\u2013{endNum, number} of {totalItems, number} terms}} found"
        },
        searching: {
          "id": "list.authRef.searching",
          "defaultMessage": "Finding terms..."
        }
      }),
      getItemLocationPath: (item, {
        config,
        perms
      }) => {
        const refName = item.get('refName');
        const servicePath = (0, _cspaceRefname.getServicePath)(refName);
        const recordTypeConfig = (0, _configHelpers.getRecordTypeConfigByServicePath)(config, servicePath);

        if (recordTypeConfig) {
          const recordType = recordTypeConfig.name;

          if ((0, _permissionHelpers.canRead)(recordType, perms)) {
            const vocabularyShortID = (0, _cspaceRefname.getVocabularyShortID)(refName);
            const vocabularyConfig = (0, _configHelpers.getVocabularyConfigByShortID)(recordTypeConfig, vocabularyShortID);

            if (vocabularyConfig) {
              const csid = item.get('csid');

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

        return null;
      }
    }
  }
});

exports.default = _default;