"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ucfirst = ucfirst;
exports.pluralize = pluralize;
exports.pluralizeWithCount = pluralizeWithCount;
exports.hostStatusToString = hostStatusToString;
exports.statusEnumToString = statusEnumToString;
exports.usageEnvironmentToString = usageEnvironmentToString;
exports.userAccessPermissionToString = userAccessPermissionToString;
exports.actionAvailabilityToString = actionAvailabilityToString;
exports.actionAccessLevelToString = actionAccessLevelToString;
exports.slugToName = slugToName;
exports.featureFlagToString = featureFlagToString;
exports.commaSeparatedList = commaSeparatedList;
exports.numberWithCommas = numberWithCommas;
function ucfirst(s) {
    return s.charAt(0).toUpperCase() + s.substring(1);
}
function pluralize(num, singular, plural) {
    if (!plural) {
        plural = `${singular}s`;
    }
    return num === 1 ? singular : plural;
}
function pluralizeWithCount(num, singular, plural, options) {
    const x = options?.commas ? numberWithCommas(num) : num;
    return `${x} ${pluralize(num, singular, plural)}`;
}
function enumToString(val) {
    const str = val.toLowerCase().replace(/[^a-z0-9]/g, ' ');
    return str[0].toUpperCase() + str.slice(1);
}
function hostStatusToString(status) {
    return enumToString(status);
}
function statusEnumToString(status) {
    switch (status) {
        case 'HOST_CONNECTION_DROPPED':
            return 'Connection lost';
        case 'CLIENT_CONNECTION_DROPPED':
            return 'Closed';
        case 'FAILURE':
            return 'Error';
        case 'SUCCESS':
            return 'Completed';
        default:
            return enumToString(status);
    }
}
function usageEnvironmentToString(env) {
    return env.charAt(0) + env.substring(1).toLowerCase();
}
function userAccessPermissionToString(perm) {
    switch (perm) {
        case 'ACTION_RUNNER':
            return 'Member';
        case 'READONLY_VIEWER':
            return 'Auditor';
        default:
            return enumToString(perm).replace('api', 'API');
    }
}
function actionAvailabilityToString(availability) {
    switch (availability) {
        case 'GROUPS':
            return 'Teams';
        default:
            return enumToString(availability);
    }
}
function actionAccessLevelToString(level) {
    return enumToString(level);
}
function slugToName(slug) {
    if (slug.includes('/')) {
        slug = slug.substring(slug.lastIndexOf('/') + 1);
    }
    if (slug === slug.toUpperCase()) {
        slug = slug.toLowerCase();
    }
    // Don't split on multiple caps in a row like URL
    const matches = slug.match(/[A-Z][A-Z]+/g);
    if (matches && matches.length) {
        for (const match of matches) {
            const toReplace = match.substring(0, match.length - 1);
            slug = slug.replace(toReplace, ` ${toReplace.toLowerCase()} `);
        }
    }
    return ucfirst(slug
        .replace(/[-_.]+/g, ' ')
        // Split on camelCase and whitespace
        .split(/((?!^)(?=[A-Z]))|\s+/g)
        .filter(Boolean)
        .map(s => s.trim())
        .filter(s => s.length)
        .map(s => s.toLowerCase())
        .join(' '));
}
function featureFlagToString(flag) {
    return enumToString(flag);
}
function commaSeparatedList(items, conjunction = 'or') {
    if (!items.length)
        return '';
    if (items.length === 1) {
        return items[0];
    }
    if (items.length === 2) {
        return `${items[0]} ${conjunction} ${items[1]}`;
    }
    return `${items.slice(0, -1).join(', ')}, ${conjunction} ${items[items.length - 1]}`;
}
function numberWithCommas(num) {
    return num.toLocaleString('en-US');
}
