/**
 * Page object for the `nimble-rich-text-viewer` component.
 */
export class RichTextViewerPageObject {
    constructor(richTextViewerElement) {
        this.richTextViewerElement = richTextViewerElement;
    }
    getRenderedMarkdownLastChildContents() {
        return this.getLastChildMarkdownRenderedElement()?.textContent || '';
    }
    getRenderedMarkdownLastChildAttribute(attribute) {
        return (this.getLastChildMarkdownRenderedElement()?.getAttribute(attribute) || '');
    }
    /**
     * Retrieves tag names for the rendered markdown content in document order
     * @returns An array of tag names in document order
     */
    getRenderedMarkdownTagNames() {
        return Array.from(this.getMarkdownRenderedElement().querySelectorAll('*')).map(el => el.tagName);
    }
    /**
     * @returns An array of tag names with the closing tags (eg: '/P') in a document order
     */
    getRenderedMarkdownTagNamesWithClosingTags() {
        const tagNames = [];
        const renderedElement = this.getMarkdownRenderedElement();
        const processNode = (node) => {
            if (node.nodeType === Node.ELEMENT_NODE) {
                const el = node;
                tagNames.push(el.tagName);
                el.childNodes.forEach(processNode);
                tagNames.push(`/${el.tagName}`);
            }
        };
        if (renderedElement) {
            processNode(renderedElement);
        }
        return tagNames.slice(1, -1);
    }
    /**
     * Retrieves text contents for the rendered markdown content in document order
     * @returns An array of text contents of last elements in a tree
     */
    getRenderedMarkdownLeafContents() {
        return Array.from(this.getMarkdownRenderedElement().querySelectorAll('*'))
            .filter((el, _) => el.children.length === 0)
            .map(el => el.textContent || '');
    }
    getRenderedMarkdownAttributeValues(attribute) {
        return Array.from(this.getMarkdownRenderedElement().querySelectorAll('*'))
            .filter((el, _) => el.children.length === 0)
            .map(el => el.getAttribute(attribute) || '');
    }
    getMarkdownRenderedElement() {
        return this.richTextViewerElement.shadowRoot?.querySelector('.viewer');
    }
    getLastChildMarkdownRenderedElement() {
        let lastElement = this.getMarkdownRenderedElement()?.lastElementChild;
        while (lastElement?.lastElementChild) {
            lastElement = lastElement?.lastElementChild;
        }
        return lastElement;
    }
}
//# sourceMappingURL=rich-text-viewer.pageobject.js.map