import { cdnUrl } from '../core';
import { iconsCache } from '../icons';
import { IconReplacements } from '../icons/iconReplacements';
const PREFIX_MAP = {
    con: 'con',
    bra: 'brand',
};
/** Optimized prefix normalization with constant time lookup */
function normalizeIconPrefix(prefix) {
    return PREFIX_MAP[prefix] || (prefix.startsWith('ui') ? 'fa' : prefix);
}
/**
 * Returns an object with either 'src' or 'customIcon', depending on whether the provided icon is:
 * - not in library:    'src' as CDN url
 * - in library:            'customIcon' as icon definition object
 */
export function getIconDetails(iconName) {
    if (!iconName)
        return {};
    const icon = IconReplacements?.[iconName] ?? iconName;
    // Compute CDN url if icon is not in library cache
    if (!iconsCache.has(icon)) {
        const prefix = icon.slice(0, 3);
        const normalizedPrefix = normalizeIconPrefix(prefix);
        return {
            src: `${cdnUrl}/common/icons/ui/${normalizedPrefix}/${icon}.svg`,
        };
    }
    // Compute relevant properties based on icon definition from the library
    const { details, name, pathProps = [], svgProps = {} } = iconsCache.get(icon);
    const [width, height, , , d] = details;
    const viewBox = `0 0 ${width} ${height}`;
    const customIcon = {
        d: Array.isArray(d) ? d : [d],
        pathProps: Array.isArray(pathProps) ? pathProps : [pathProps],
        svgProps: { 'data-name': name, viewBox, ...svgProps },
    };
    return {
        customIcon,
    };
}
//# sourceMappingURL=helpers.js.map