/*---------------------------------------------------------------------------------------------
 * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
 * See LICENSE.md in the project root for license terms and full copyright notice.
 *--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Tools
 */
import { Key } from "ts-key-enum";
import { ToolAdmin } from "@itwin/core-frontend";
import { UiFramework } from "../UiFramework.js";
/** Subclass of `ToolAdmin` in `@itwin/core-frontend` to be used to initialize `IModelApp`.
 *
 * Enable processing of shortcut keys registered to
 * [[UiFramework.keyboardShortcuts]] when focus is set to Home.
 *
 * ```ts
 * await IModelApp.startup({
 *   toolAdmin: new FrameworkToolAdmin()
 * });
 * ```
 * @public
 */
export class FrameworkToolAdmin extends ToolAdmin {
    async processShortcutKey(e, wentDown) {
        if (!wentDown)
            return false;
        if (UiFramework.isContextMenuOpen)
            return false;
        if (e.key === Key.Escape.valueOf())
            return false;
        if (isElement(e.target) && isEditable(e.target))
            return false;
        UiFramework.keyboardShortcuts.processKey(e.key, e.altKey, e.ctrlKey, e.shiftKey);
        return true;
    }
}
function isElement(target) {
    return target instanceof Element;
}
const editableTags = ["input", "textarea", "select"];
function isEditable(element) {
    const tagName = element.tagName.toLowerCase();
    if (editableTags.includes(tagName))
        return true;
    if (element instanceof HTMLElement && element.isContentEditable)
        return true;
    return false;
}
//# sourceMappingURL=FrameworkToolAdmin.js.map