function toggleMainUiClickListener(button, handler, operation) {
    if (!button) {
        return;
    }
    button[operation]("click", handler);
}
function toggleConditionalMainUiClickListener(condition, button, handler, operation) {
    if (!condition) {
        return;
    }
    toggleMainUiClickListener(button, handler, operation);
}
export function bindMainUiElements(ui) {
    ui.editButton = ui.shadowRoot.querySelector(".button--edit");
    ui.infoButton = ui.shadowRoot.querySelector(".button--info");
    ui.saveButton = ui.shadowRoot.querySelector(".button--save");
    ui.cancelButton = ui.shadowRoot.querySelector(".button--cancel");
    ui.logoutButton = ui.shadowRoot.querySelector(".button--logout");
    ui.editNavButton = ui.shadowRoot.querySelector(".button--edit-structure");
    ui.filemanagerButton = ui.shadowRoot.querySelector(".button--file-manager");
    ui.refreshButton = ui.shadowRoot.querySelector(".button--refresh");
    ui.duplicateButton = ui.shadowRoot.querySelector(".button--duplicate");
    ui.previewButton = ui.shadowRoot.querySelector(".button--preview");
    ui.playersContainer = ui.shadowRoot.querySelector(".players");
}
export function connectMainUiListeners(ui, handlers, isAdmin) {
    toggleMainUiClickListener(ui.filemanagerButton, handlers.openFileManager, "addEventListener");
    toggleConditionalMainUiClickListener(isAdmin, ui.editNavButton, handlers.editNav, "addEventListener");
    toggleMainUiClickListener(ui.refreshButton, handlers.refreshSite, "addEventListener");
    toggleMainUiClickListener(ui.duplicateButton, handlers.showDuplicationModal, "addEventListener");
    toggleMainUiClickListener(ui.previewButton, handlers.openPreview, "addEventListener");
    toggleMainUiClickListener(ui.infoButton, handlers.info, "addEventListener");
    toggleMainUiClickListener(ui.editButton, handlers.edit, "addEventListener");
    toggleMainUiClickListener(ui.saveButton, handlers.save, "addEventListener");
    toggleMainUiClickListener(ui.cancelButton, handlers.cancel, "addEventListener");
    toggleMainUiClickListener(ui.logoutButton, handlers.logout, "addEventListener");
    document.addEventListener("keydown", handlers.keyDown);
    window.addEventListener("beforeunload", handlers.beforeUnload);
}
export function disconnectMainUiListeners(ui, handlers, isAdmin) {
    window.removeEventListener("beforeunload", handlers.beforeUnload);
    document.removeEventListener("keydown", handlers.keyDown);
    toggleMainUiClickListener(ui.logoutButton, handlers.logout, "removeEventListener");
    toggleMainUiClickListener(ui.cancelButton, handlers.cancel, "removeEventListener");
    toggleMainUiClickListener(ui.saveButton, handlers.save, "removeEventListener");
    toggleMainUiClickListener(ui.editButton, handlers.edit, "removeEventListener");
    toggleMainUiClickListener(ui.infoButton, handlers.info, "removeEventListener");
    toggleMainUiClickListener(ui.previewButton, handlers.openPreview, "removeEventListener");
    toggleMainUiClickListener(ui.duplicateButton, handlers.showDuplicationModal, "removeEventListener");
    toggleMainUiClickListener(ui.refreshButton, handlers.refreshSite, "removeEventListener");
    toggleConditionalMainUiClickListener(isAdmin, ui.editNavButton, handlers.editNav, "removeEventListener");
    toggleMainUiClickListener(ui.filemanagerButton, handlers.openFileManager, "removeEventListener");
}
