"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.iconManager = exports.defaultIconMap = exports.defaultIconfont = void 0;
const tslib_1 = require("tslib");
const warning_1 = tslib_1.__importDefault(require("../../utils/warning"));
const iconMap_1 = require("./iconMap");
Object.defineProperty(exports, "defaultIconfont", { enumerable: true, get: function () { return iconMap_1.defaultIconfont; } });
/**
 * 以下为 typo 的字体，做一定兼容
 * key 为 iconName enum, value 为 icon className
 */
const typoIconMap = {
    'search-close': 'close-square',
    'fold': 'collapse-all',
    'setting-general': 'setting',
    'setting-file': 'file-text',
    'setting-extension': 'extension',
    'run-debug': 'start',
    'toggle-breakpoints': 'deactivate-breakpoints',
    // new typos issue
    'withdraw': 'fallback',
    'terminate1': 'stop',
    'stop1': 'stop',
    'add': 'plus',
    // removed duplicated icons
    'rundebug': 'start',
    'terminate': 'stop',
};
const _defaultIconAndTypoIconMap = Object.assign({}, iconMap_1.defaultIconfont, typoIconMap);
exports.defaultIconMap = new Proxy(_defaultIconAndTypoIconMap, {
    get(obj, prop) {
        const typoValue = typoIconMap[prop];
        (0, warning_1.default)(!typoValue, `Icon '${prop}' was a typo, please use '${typoValue}' instead`);
        return obj[prop];
    },
});
class IconManager {
    constructor() {
        this._ktIconPrefixes = [];
        this._iconMap = {};
    }
    update(prefix, customIconMap) {
        this._iconMap[prefix] = customIconMap;
        this._ktIconPrefixes.push(prefix);
    }
    getIconClx(iconKey) {
        if (!iconKey) {
            (0, warning_1.default)(false, 'not a valid icon key:' + iconKey);
            return [];
        }
        let lastIndex = this._ktIconPrefixes.length;
        while (!this._iconMap[this._ktIconPrefixes[--lastIndex]][iconKey]) {
            if (lastIndex === 0) {
                break;
            }
        }
        const iconValue = this._iconMap[this._ktIconPrefixes[lastIndex]][iconKey];
        if (!iconValue) {
            (0, warning_1.default)(false, '图标库缺失图标:' + iconKey);
            return [];
        }
        return [`${this._ktIconPrefixes[lastIndex]}${iconValue}`];
    }
}
exports.iconManager = new IconManager();
const defaultKtIconPrefix = 'kaitian-icon kticon-';
// 将 default 的部分先配置进去
exports.iconManager.update(defaultKtIconPrefix, exports.defaultIconMap);
//# sourceMappingURL=iconManager.js.map