"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.parseCredDefFromId = parseCredDefFromId;
exports.parsedCredDefName = parsedCredDefName;
exports.parsedCredDefNameFromCredential = parsedCredDefNameFromCredential;
var _anoncreds = require("@credo-ts/anoncreds");
var _schema = require("./schema");
function parseCredDefFromId(credDefId, schemaId) {
  let name = 'Credential';
  if (credDefId) {
    const credDefRegex = /[^:]+/g;
    const credDefIdParts = credDefId.match(credDefRegex);
    if ((credDefIdParts === null || credDefIdParts === void 0 ? void 0 : credDefIdParts.length) === 5) {
      name = `${credDefIdParts === null || credDefIdParts === void 0 ? void 0 : credDefIdParts[4].replace(/_|-/g, ' ')}`.split(' ').map(credIdPart => credIdPart.charAt(0).toUpperCase() + credIdPart.substring(1)).join(' ');
    }
  }
  if (name.toLocaleLowerCase() === 'default' || name.toLowerCase() === 'credential') {
    name = (0, _schema.parseSchemaFromId)(schemaId).name;
  }
  return name;
}
function credentialDefinition(credential) {
  var _credential$metadata$;
  return (_credential$metadata$ = credential.metadata.get(_anoncreds.AnonCredsCredentialMetadataKey)) === null || _credential$metadata$ === void 0 ? void 0 : _credential$metadata$.credentialDefinitionId;
}
function parsedCredDefNameFromCredential(credential) {
  return parseCredDefFromId(credentialDefinition(credential), (0, _schema.credentialSchema)(credential));
}
function parsedCredDefName(credentialDefinitionId, schemaId) {
  return parseCredDefFromId(credentialDefinitionId, schemaId);
}
//# sourceMappingURL=cred-def.js.map