"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getIconDetails = getIconDetails;
const core_1 = require("../core");
const icons_1 = require("../icons");
const iconReplacements_1 = require("../icons/iconReplacements");
const PREFIX_MAP = {
    con: 'con',
    bas: 'base',
    bra: 'brand',
};
/** Optimized prefix normalization with constant time lookup */
function normalizeIconPrefix(prefix) {
    return PREFIX_MAP[prefix] || (prefix.startsWith('ui') ? 'ui' : 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
 */
function getIconDetails(iconName) {
    var _a;
    if (!iconName)
        return {};
    const icon = (_a = iconReplacements_1.IconReplacements === null || iconReplacements_1.IconReplacements === void 0 ? void 0 : iconReplacements_1.IconReplacements[iconName]) !== null && _a !== void 0 ? _a : iconName;
    // Compute CDN url if icon is not in library cache
    if (!icons_1.iconsCache.has(icon)) {
        const prefix = icon.slice(0, 3);
        const normalizedPrefix = normalizeIconPrefix(prefix);
        return {
            src: `${core_1.cdnUrl}/common/icons/ui/${normalizedPrefix}/${icon}.svg`,
        };
    }
    // Compute relevant properties based on icon definition from the library
    const { details, name, pathProps = [], svgProps = {} } = icons_1.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: Object.assign({ 'data-name': name, viewBox }, svgProps),
    };
    return {
        customIcon,
    };
}
//# sourceMappingURL=helpers.js.map