export function registerUITagHandlers(editor) {
    editor.queryEngine.registerTagHandler('output', () => {
        return {
            getId: () => 'output',
            getHTMLElement: () => {
                return editor.output.dom.root;
            },
        };
    });
    editor.queryEngine.registerTagHandler('button', (selector) => {
        const target = selector.id || selector.class;
        if (!target) {
            throw new Error('Could not query button: Either and id or a class must be defined');
        }
        const getToolbar = () => {
            return editor.domNode.workspaceToolbar;
        };
        const getToolbarEntry = (id) => {
            const toolbar = getToolbar();
            if (!toolbar) {
                throw new Error('Could not find toolbar entry: Toolbar is not accessible');
            }
            const entry = toolbar.entries.find((e) => e.id === id);
            if (!entry) {
                throw new Error(`Could not find toolbar entry with id '${id}'`);
            }
            const element = toolbar.getDomForEntry(entry);
            if (!element) {
                throw new Error(`Could not find toolbar entry with id '${id}'`);
            }
            return element;
        };
        const toolbarEntry = (id) => {
            return {
                getId: () => target,
                getHTMLElement: () => {
                    return getToolbarEntry(id);
                },
            };
        };
        switch (target) {
            case 'restart': {
                return toolbarEntry('restart');
            }
            case 'fullscreen': {
                return toolbarEntry('fullscreen');
            }
            case 'play': {
                return {
                    getId: () => target,
                    getHTMLElement: () => {
                        const toolbar = getToolbar();
                        if (!toolbar || !toolbar.shadowRoot) {
                            throw new Error('Could not find play button: Toolbar is not accessible');
                        }
                        const element = toolbar.shadowRoot.querySelector('#entry-play');
                        if (!element) {
                            throw new Error('Could not find play button');
                        }
                        return element;
                    }
                };
            }
            default: {
                throw new Error(`Could not query button: id '${target}' is unknown`);
            }
        }
    });
    editor.queryEngine.registerTagHandler('tab', (selector) => {
        const target = selector.id || selector.class;
        if (!target) {
            throw new Error('Could not query button: Either and id or a class must be defined');
        }
        const targetMap = {
            artboard: 'workspace',
            code: 'code-display',
        };
        const tabId = targetMap[target];
        return {
            getId: () => target,
            getHTMLElement: () => {
                const element = editor.domNode.getTabDom(tabId);
                if (!element) {
                    throw new Error(`Could not query editor tab: tab '${target}' is unknown`);
                }
                return element;
            },
        };
    });
}
//# sourceMappingURL=ui.js.map