
/**
 * @const
**/
var EmojiProvider = {
    "noemoji": {
        js: "noemoji.js",
        css: null,
        name: "None"
    },
    "emojione_v2_3": {
        js: "emojione_v2.3.sprites.js",
        css: "emojione_v2.3.sprites.css",
        name: "Emojione v2.3"
    },
    "emojione_v3": {
        js: "emojione_v3.sprites.js",
        css: "emojione_v3.sprites.css",
        name: "Emojione v3"
    }
};

var
    /** @type {{js: string, css: string, name: string}} */
    DEFAULT_EMOJI_PROVIDER = EmojiProvider["emojione_v2_3"],
    /** @type {{js: string, css: string, name: string}} */
    CURRENT_EMOJI_PROVIDER;

/**
 * @param {{js: string, css: string, name: string}} provider
**/
function setEmojiProvider(provider) {
    if (CURRENT_EMOJI_PROVIDER !== provider) {
        console.log("Loading emoji pack " +provider.name);
        HttpRequestWrapper(provider.js)
            .callbackSuccess(function(code, head, resp) {
                var script = document.createElement("script");
                script.innerHTML = resp;
                script.language = "text/javascript";
                document.body.appendChild(script);

                if (provider.css) {
                    var link = document.createElement("link");
                    link.href = provider.css;
                    link.rel = "stylesheet";
                    document.head.appendChild(link);
                }

                onEmojiReady();
            })
            .setTimeout(1000 * 60 * 1)
            .send();
        CURRENT_EMOJI_PROVIDER = provider;
        return true;
    }
    return false;
}

/** @param {string|undefined} providerId */
function loadEmojiProvider(providerId) {
    return setEmojiProvider(providerId && EmojiProvider[providerId] ? EmojiProvider[providerId] : DEFAULT_EMOJI_PROVIDER);
}

function isValidEmojiProvider(providerId) {
    return !!EmojiProvider[providerId];
}

