// retoor <retoor@molodetz.nl>

import { Component } from "./Component.js";
import { contentRenderer } from "../ContentRenderer.js";

export class AppTitle extends Component {
    connectedCallback() {
        if (this._rendered) {
            return;
        }
        if (typeof DOMPurify === "undefined" || typeof marked === "undefined") {
            window.addEventListener("load", () => this.connectedCallback(), { once: true });
            return;
        }
        if (!contentRenderer.emojiLoaded) {
            contentRenderer.ready.then(() => this.connectedCallback());
            return;
        }
        this._rendered = true;
        this.classList.add("rendered-title");
        const source = (this.textContent || "").trim();
        const authorAdmin = this.hasAttribute("data-author-admin");
        this.innerHTML = contentRenderer.renderInline(source, authorAdmin);
    }
}

customElements.define("dp-title", AppTitle);
