// TODO: export this from @aries-framework/anoncreds
import { AnonCredsCredentialMetadataKey } from '@aries-framework/anoncreds/build/utils/metadata';
import { parseSchemaFromId, credentialSchema } from './schema';
export 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 = parseSchemaFromId(schemaId).name;
  }
  return name;
}
function credentialDefinition(credential) {
  var _credential$metadata$;
  return (_credential$metadata$ = credential.metadata.get(AnonCredsCredentialMetadataKey)) === null || _credential$metadata$ === void 0 ? void 0 : _credential$metadata$.credentialDefinitionId;
}
export function parsedCredDefNameFromCredential(credential) {
  return parseCredDefFromId(credentialDefinition(credential), credentialSchema(credential));
}
export function parsedCredDefName(credentialDefinitionId, schemaId) {
  return parseCredDefFromId(credentialDefinitionId, schemaId);
}
//# sourceMappingURL=cred-def.js.map