'use strict';

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

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

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

var refNameToUrl = function refNameToUrl(config, refName) {
  if (!refName) return null;

  var servicePath = (0, _cspaceRefname.getServicePath)(refName);
  var recordTypeConfig = (0, _configHelpers.getRecordTypeConfigByServicePath)(config, servicePath);
  var recordType = recordTypeConfig.name;

  var vocabularyShortID = (0, _cspaceRefname.getVocabularyShortID)(refName);
  var vocabularyConfig = (0, _configHelpers.getVocabularyConfigByShortID)(recordTypeConfig, vocabularyShortID);
  var vocabulary = vocabularyConfig.name;

  var itemShortID = (0, _cspaceRefname.getItemShortID)(refName);
  var csid = 'urn:cspace:name(' + itemShortID + ')';

  return '/record/' + recordType + '/' + vocabulary + '/' + csid;
};

exports.default = refNameToUrl;