import { isLocalhost } from "../../../services/util.js";
export function handleMainUiKeyDown(context, e) {
    const isActive = context.host.getAttribute("active") !== null;
    if (isActive && (e.ctrlKey || e.metaKey) && e.key === "s") {
        e.preventDefault();
        context.saveButton.focus();
        context.save();
    }
    if (context.filemanagerButton && (e.ctrlKey || e.metaKey) && e.key === "o") {
        e.preventDefault();
        context.filemanagerButton.focus();
        context.openFileManager();
    }
    if (e.shiftKey && (e.ctrlKey || e.metaKey) && e.key === "I") {
        e.preventDefault();
        context.infoButton.focus();
        context.info();
    }
    if (context.editNavButton &&
        e.shiftKey &&
        (e.ctrlKey || e.metaKey) &&
        e.key === "E") {
        e.preventDefault();
        context.editNavButton.focus();
        context.editNav();
    }
    if (e.shiftKey && e.key === "Escape") {
        e.preventDefault();
        context.logoutButton.focus();
        context.logout();
    }
    if (!e.shiftKey && (e.ctrlKey || e.metaKey) && e.key === "e") {
        e.preventDefault();
        context.editButton.focus();
        isActive ? context.cancel() : context.edit();
    }
    if ((e.ctrlKey || e.metaKey) && e.key === "p") {
        e.preventDefault();
        context.openPreview();
    }
}
export function handleMainUiBeforeUnload(unsavedChanges, e) {
    if (!unsavedChanges || isLocalhost()) {
        return;
    }
    e.preventDefault();
    e.returnValue = true;
}
