/* eslint-disable no-continue */
import { ContextualMenu } from '../../contextual-menu/ContextualMenu.js';
import commands from './HttpClientCommands.js';
export class HttpClientContextMenu extends ContextualMenu {
    constructor() {
        super(document.body, {
            cancelNativeWhenHandled: false,
        });
        this.registerCommands(commands);
    }
    elementToTarget(element) {
        const name = element.localName;
        if (element.dataset.kind) {
            return `${name}[data-kind="${element.dataset.kind}"]`;
        }
        return super.elementToTarget(element);
    }
    /**
     * Finds the click target which can be one of the model objects
     * or SVG elements.
     */
    findTarget(e) {
        const element = e.target;
        if (element.localName === 'project-navigation') {
            return this.readNavigationElement(e, element);
        }
        if (element.localName === 'split-view') {
            return this.readLayoutElement(e, element);
        }
        return element;
    }
    readNavigationElement(e, element) {
        if (element === this.workspace) {
            return element;
        }
        const path = e.composedPath();
        while (path.length) {
            const target = path.shift();
            if (target.nodeType !== Node.ELEMENT_NODE) {
                continue;
            }
            const elm = target;
            if (elm.matches('li[data-key][data-kind]')) {
                return elm;
            }
            // top most for the navigation
            if (elm.localName === 'project-navigation') {
                return elm;
            }
        }
        return undefined;
    }
    readLayoutElement(e, element) {
        if (element === this.workspace) {
            return element;
        }
        const path = e.composedPath();
        while (path.length) {
            const target = path.shift();
            if (target.nodeType !== Node.ELEMENT_NODE) {
                continue;
            }
            const elm = target;
            if (elm.matches('.layout-tab')) {
                return elm;
            }
        }
        return undefined;
    }
}
//# sourceMappingURL=HttpClientContextMenu.js.map