const toCatalogNumericPart = (catalogIndex) => `${catalogIndex}`.padStart(3, "0");
/**
 * Format a catalog index as an ID like `R001`.
 */
export const toRuleCatalogId = (catalogIndex) => `R${toCatalogNumericPart(catalogIndex)}`;
/**
 * Convert a rule name to its documentation page id.
 */
export const toRuleDocId = (ruleName) => ruleName.replaceAll("/", "-");
/**
 * Sort rules so core rules come first, then TypeScript-scoped rules.
 */
export const compareRuleNamesForCatalog = (leftRuleName, rightRuleName) => {
    const leftIsTypeScriptRule = leftRuleName.startsWith("typescript/");
    const rightIsTypeScriptRule = rightRuleName.startsWith("typescript/");
    if (leftIsTypeScriptRule !== rightIsTypeScriptRule) {
        return leftIsTypeScriptRule ? 1 : -1;
    }
    return leftRuleName.localeCompare(rightRuleName);
};
/**
 * Build a globally ordered rule catalog map keyed by both rule name and doc id.
 */
export const buildRuleCatalog = (ruleNames) => {
    const sortedRuleNames = ruleNames.toSorted(compareRuleNamesForCatalog);
    let ordered = [];
    let byRuleName = {};
    let byDocId = {};
    for (const [zeroBasedIndex, ruleName] of sortedRuleNames.entries()) {
        const catalogIndex = zeroBasedIndex + 1;
        const docId = toRuleDocId(ruleName);
        const entry = {
            catalogId: toRuleCatalogId(catalogIndex),
            catalogIndex,
            docId,
            isTypeScriptRule: ruleName.startsWith("typescript/"),
            ruleName,
        };
        ordered = [...ordered, entry];
        byRuleName = { ...byRuleName, [ruleName]: entry };
        byDocId = { ...byDocId, [docId]: entry };
    }
    return {
        byDocId,
        byRuleName,
        ordered,
    };
};
//# sourceMappingURL=rule-catalog.js.map