#include utility.js

const MszChristmas2019EventInfo = function() {
    return {
        isActive: () => {
            const d = new Date;
            return d.getMonth() === 11 && d.getDate() > 5 && d.getDate() < 27;
        },
        dispatch: () => {
            const impl = new MszChristmas2019Event;
            impl.dispatch();
            return impl;
        },
    };
};

const MszChristmas2019Event = function() {
    const propName = 'msz-christmas-' + (new Date).getFullYear().toString();
    const headerBg = $q('.header__background');
    const menuBgs = Array.from($qa('.header__desktop__submenu__background'));

    if(!localStorage.getItem(propName))
        localStorage.setItem(propName, '0');

    const changeColour = () => {
        let count = parseInt(localStorage.getItem(propName));
        document.body.style.setProperty('--header-accent-colour', (count++ % 2) ? 'green' : 'red');
        localStorage.setItem(propName, count.toString());
    };

    return {
        changeColour: changeColour,
        dispatch: () => {
            if(headerBg)
                headerBg.style.transition = 'background-color .4s';

            setTimeout(() => {
                if(headerBg)
                    headerBg.style.transition = 'background-color 1s';

                for(const menuBg of menuBgs)
                    menuBg.style.transition = 'background-color 1s';
            }, 1000);

            changeColour();
            setInterval(changeColour, 10000);
        },
    };
};
