#include utility.js

Umi.UI.LoadingOverlay = function(icon, header, message) {
    const icons = {
        'spinner': 'fas fa-3x fa-fw fa-spinner fa-pulse',
        'checkmark': 'fas fa-3x fa-fw fa-check-circle',
        'cross': 'fas fa-3x fa-fw fa-times-circle',
        'hammer': 'fas fa-3x fa-fw fa-gavel',
        'bomb': 'fas fa-3x fa-fw fa-bomb',
        'unlink': 'fas fa-3x fa-fw fa-unlink',
        'reload': 'fas fa-3x fa-fw fa-sync fa-spin',
        'warning': 'fas fa-exclamation-triangle fa-3x',
        'question': 'fas fa-3x fa-question-circle',
        'poop': 'fas fa-3x fa-poop',
    };

    let iconElem, headerElem, messageElem;
    const html = <div class="overlay">
        <div class="overlay__inner">
            {iconElem = <div class="fas fa-3x fa-question-circle" />}
            {headerElem = <div class="overlay__message" />}
            {messageElem = <div class="overlay__status" />}
        </div>
    </div>;

    const setIcon = name => {
        name = (name || '').toString();
        if(!(name in icons))
            name = 'question';
        iconElem.className = icons[name];
    };

    const setHeader = text => headerElem.textContent = (text || '').toString();
    const setMessage = text => messageElem.innerHTML = (text || '').toString();

    setIcon(icon);
    setHeader(header);
    setMessage(message);

    return {
        setIcon: setIcon,
        setHeader: setHeader,
        setMessage: setMessage,
        getElement: function() {
            return html;
        },
        getViewTransition: mode => {
            if(mode === 'pop')
                return ctx => MamiAnimate({
                    async: true,
                    duration: 200,
                    easing: 'inOutSine',
                    start: () => {
                        ctx.fromElem.style.pointerEvents = 'none';
                    },
                    update: t => {
                        ctx.fromElem.style.transform = `scale(${1 + (.25 * t)})`;
                        ctx.fromElem.style.opacity = 1 - (1 * t).toString();
                    },
                });
        },
    };
};
