import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import slugify from 'slugify';
const SITE_DEFAULTS = {
    description: 'PatternFly Elements: A set of community-created web components based on PatternFly design.',
    favicon: '/brand/logo/svg/pfe-icon-blue.svg',
    logoUrl: '/brand/logo/svg/pfe-icon-white-shaded.svg',
    stylesheets: [],
    title: 'PatternFly Elements',
};
const DEFAULT_CONFIG = {
    demoURLPrefix: 'https://patternflyelements.org/',
    sourceControlURLPrefix: 'https://github.com/patternfly/patternfly-elements/tree/main/',
    tagPrefix: 'pfe',
    aliases: {},
};
function tryJson(path) {
    try {
        return JSON.parse(readFileSync(path, 'utf8'));
    }
    catch {
        return {};
    }
}
export function getPfeConfig(rootDir = process.cwd()) {
    const jsonConfig = tryJson(join(rootDir, '.pfe.config.json'));
    return {
        ...DEFAULT_CONFIG,
        rootDir,
        ...jsonConfig,
        site: {
            ...SITE_DEFAULTS,
            ...jsonConfig.site ?? {}
        }
    };
}
const slugsConfigMap = new Map();
const reverseSlugifyObject = ([k, v]) => [slugify(v).toLowerCase(), k];
function getSlugsMap(rootDir) {
    if (!slugsConfigMap.get(rootDir)) {
        const config = getPfeConfig(rootDir);
        const slugs = new Map(Object.entries(config.aliases).map(reverseSlugifyObject));
        slugsConfigMap.set(rootDir, { slugs, config });
    }
    return slugsConfigMap.get(rootDir);
}
export function deslugify(slug, rootDir = process.cwd()) {
    const { slugs, config } = getSlugsMap(rootDir);
    return slugs.get(slug) ?? `${config.tagPrefix}-${slug}`;
}
//# sourceMappingURL=config.js.map