'use strict';

var index = require('./bundle-Dn0hi6OJ.js');

var EmojiManager = /** @class */ (function () {
    function EmojiManager(props) {
        var _this = this;
        var _a;
        var sdk = props.sdk, logger = props.logger;
        (_a = sdk === null || sdk === void 0 ? void 0 : sdk.getAllEmoji) === null || _a === void 0 ? void 0 : _a.call(sdk).then(function (emojiContainer) {
            _this._emojiContainer = emojiContainer;
            logger === null || logger === void 0 ? void 0 : logger.info('EmojiManager | Succeeded getting all emojis. ', emojiContainer);
        }).catch(function () {
            logger === null || logger === void 0 ? void 0 : logger.warning('EmojiManager | Failed getting all emojis.');
        });
    }
    Object.defineProperty(EmojiManager.prototype, "AllEmojisAsArray", {
        get: function () {
            return this._emojiContainer.emojiCategories.flatMap(function (category) { return category.emojis; });
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(EmojiManager.prototype, "AllEmojisAsMap", {
        get: function () {
            return this._emojiContainer.emojiCategories
                .flatMap(function (category) { return category.emojis; })
                .reduce(function (map, emoji) {
                map.set(emoji.key, emoji.url);
                return map;
            }, new Map());
        },
        enumerable: false,
        configurable: true
    });
    EmojiManager.prototype.getAllEmojis = function (type) {
        var _this = this;
        return index.K(type)
            .when(function (type) { return ['array', 'arr'].includes(type); }, function () { return _this.AllEmojisAsArray; })
            .when(function (type) { return ['map'].includes(type); }, function () { return _this.AllEmojisAsMap; })
            .otherwise(function () { return _this.AllEmojisAsArray; });
    };
    EmojiManager.prototype.getEmojiUrl = function (reactionKey) {
        var _a, _b;
        return (_b = (_a = this.AllEmojisAsArray.find(function (emoji) { return emoji.key === reactionKey; })) === null || _a === void 0 ? void 0 : _a.url) !== null && _b !== void 0 ? _b : '';
    };
    Object.defineProperty(EmojiManager.prototype, "emojiContainer", {
        get: function () {
            return this._emojiContainer;
        },
        enumerable: false,
        configurable: true
    });
    return EmojiManager;
}());

/**
 * Mapping object to convert numeric keys to descriptive text
 * [(legacy) numeric key]: [(new) descriptive text]
 */
var colorMapping = {
    // Primary / Secondary / Error / Information
    100: 'extra-light',
    200: 'light',
    300: 'main',
    400: 'dark',
    500: 'extra-dark',
    // Overlay
    'overlay-01': 'overlay-dark',
    'overlay-02': 'overlay-light',
    // OnLight
    'onlight-01': 'onlight-text-high-emphasis',
    'onlight-02': 'onlight-text-mid-emphasis',
    'onlight-03': 'onlight-text-low-emphasis',
    'onlight-04': 'onlight-text-disabled',
    // OnDark
    'ondark-01': 'ondark-text-high-emphasis',
    'ondark-02': 'ondark-text-mid-emphasis',
    'ondark-03': 'ondark-text-low-emphasis',
    'ondark-04': 'ondark-text-disabled',
};
/**
 * Order of mappings to ensure longer keys are matched first
 * e.g. In --sendbird-dark-background-extra-dark, 'extra-dark' should be matched instead of 'dark'
 */
var colorMappingOrder = Object
    .values(colorMapping)
    .sort(function (a, b) { return b.length - a.length; });
/**
 * Convert colorMapping to a Map for quick lookup in mapColorKeys
 */
var colorMappingMap = new Map(Object.entries(colorMapping).map(function (_a) {
    var key = _a[0], value = _a[1];
    return [value, key];
}));
/**
 * Converts descriptive color keys to their numeric equivalents.
 *
 * This function takes a set of CSS variable keys and transforms
 * descriptive color keys (e.g. 'extra-light', 'main') into their
 * numeric equivalents(e.g. 100, 200, ..., 500) as defined in the colorMapping object.
 *
 * e.g.
 * Input:
 * {
 *   '--sendbird-light-primary-extra-dark': '#00487c',
 *   '--sendbird-light-primary-dark': '#4bb3fd',
 *   '--sendbird-light-primary-main': '#3e6680',
 *   '--sendbird-light-primary-light': '#0496ff',
 *   '--sendbird-light-primary-extra-light': '#027bce',
 * }
 *
 * Output:
 * {
 *   '--sendbird-light-primary-500': '#00487c',
 *   '--sendbird-light-primary-400': '#4bb3fd',
 *   '--sendbird-light-primary-300': '#3e6680',
 *   '--sendbird-light-primary-200': '#0496ff',
 *   '--sendbird-light-primary-100': '#027bce',
 * }
 *
 * @param {ColorSet} colorSet - The input object containing CSS variables with descriptive keys.
 * @returns {ColorSet} The transformed object with numeric keys.
 */
var mapColorKeys = function (colorSet) {
    var mappedColors = {};
    Object.entries(colorSet).forEach(function (_a) {
        var key = _a[0], value = _a[1];
        var descriptiveKey = key;
        for (var _i = 0, colorMappingOrder_1 = colorMappingOrder; _i < colorMappingOrder_1.length; _i++) {
            var mappingValue = colorMappingOrder_1[_i];
            // Prepare a regex to match the mapping value at the end of the key
            // e.g., '-extra-dark$'
            var regex = new RegExp("-".concat(mappingValue, "$"));
            if (regex.test(key)) {
                // Find the corresponding numeric key for the mapping value using Map
                var numericKey = colorMappingMap.get(mappingValue);
                if (numericKey) {
                    // Replace the descriptive text with the numeric key
                    descriptiveKey = key.replace(regex, "-".concat(numericKey));
                    break;
                }
            }
        }
        mappedColors[descriptiveKey] = value;
    });
    return mappedColors;
};

exports.EmojiManager = EmojiManager;
exports.mapColorKeys = mapColorKeys;
//# sourceMappingURL=bundle-CMpha6Ac.js.map
