var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { css, customElement, html, map, nothing, state } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
let UmbTiptapStatusbarElementPathElement = class UmbTiptapStatusbarElementPathElement extends UmbLitElement {
    connectedCallback() {
        super.connectedCallback();
        if (this.editor) {
            this.editor.on('selectionUpdate', this.#onEditorSelectionUpdate);
            this.#onEditorSelectionUpdate();
        }
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (this.editor) {
            this.editor.off('selectionUpdate', this.#onEditorSelectionUpdate);
        }
    }
    #onEditorSelectionUpdate = () => {
        let dom = this.editor?.view.domAtPos(this.editor.state.selection.from).node;
        this._path = [];
        while (dom) {
            if (!this.editor?.view.dom.contains(dom))
                break;
            if (dom.nodeType === dom.ELEMENT_NODE && dom instanceof HTMLElement) {
                let tagName = dom.nodeName.toLocaleLowerCase();
                if (dom.id) {
                    tagName += `#${dom.id}`;
                }
                if (dom.classList.length) {
                    tagName += `${['', ...dom.classList].join('.')}`;
                }
                this._path.push(tagName);
            }
            if (!dom.parentElement)
                break;
            dom = dom.parentElement;
        }
        this._path.reverse().shift();
    };
    render() {
        if (!this._path)
            return nothing;
        return map(this._path, (item) => html `<code>${item}</code>`);
    }
    static { this.styles = [
        css `
			:host {
				display: flex;
				gap: 0.5rem;

				font-size: var(--uui-type-small-size);
				color: var(--uui-color-text-alt);
			}

			code:not(:last-of-type)::after {
				content: '>';
				margin-left: 0.5rem;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbTiptapStatusbarElementPathElement.prototype, "_path", void 0);
UmbTiptapStatusbarElementPathElement = __decorate([
    customElement('umb-tiptap-statusbar-element-path')
], UmbTiptapStatusbarElementPathElement);
export { UmbTiptapStatusbarElementPathElement };
export { UmbTiptapStatusbarElementPathElement as element };
