
$(() => {
    let closePopinsRequestedHandlers = [];
    window.lastKeyboardEvent = null;

    document.addEventListener("keyup", evt => {
        window.lastKeyboardEvent = evt;
    });

    function triggerClosePopinsRequestHandlers() {
        for (let i of closePopinsRequestedHandlers)
            i();
    }

    document.addEventListener("keydown", evt => {
        window.lastKeyboardEvent = evt;
        if (evt.keyCode === 27)
            triggerClosePopinsRequestHandlers();
    });

    document.getElementById("pch-navbar-reload").addEventListener("click", e => { e.preventDefault(); reloadServerDb(); });
    document.getElementById("pch-navbar-share").addEventListener("click", e => { e.preventDefault(); showShareUi(); });
    document.getElementById("pch-navbar-autotags").addEventListener("click", e => { e.preventDefault(); showAutoTagsUi(); });
    document.getElementById("fullScreenOverlay").addEventListener("click", e => { e.preventDefault(); triggerClosePopinsRequestHandlers(); });
    document.onClosePopinRequested = (hndl) => closePopinsRequestedHandlers.push(hndl);
});

