#include utility.js

Umi.UI.Toggles = (function() {
    const ids = [];

    return {
        Add: function(baseId, eventHandlers, title) {
            if(ids.includes(baseId))
                return;

            ids.push(baseId);

            const toggle = $e({
                attrs: {
                    id: 'umi-toggles-' + baseId,
                    classList: ['sidebar__selector-mode', 'sidebar__selector-mode--' + baseId],
                    title: title,
                },
            });

            if(typeof eventHandlers === 'object' && eventHandlers !== null)
                for(const i in eventHandlers)
                    toggle.addEventListener(i, eventHandlers[i]);

            const toggles = $i('umi-toggles');
            toggles.insertBefore(toggle, toggles.firstChild);

            // hack cuz i'm lazy
            if(baseId === 'ping')
                return toggle;
        },
        Get: function(baseId, icon) {
            const id = 'umi-toggles-' + baseId;
            if(ids.indexOf(baseId) >= 0)
                return $i(id);
            return null;
        },
        Remove: function(baseId) {
            $ri('umi-toggles-' + baseId);
        },
    };
})();
