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 { UMB_UFM_CONTEXT } from '../../contexts/ufm.context.js';
import { UmbUfmRenderContext } from './ufm-render.context.js';
import { css, customElement, nothing, property, unsafeHTML, until } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import { UmbTextStyles } from '../../../core/style/index.js';
let UmbUfmRenderElement = class UmbUfmRenderElement extends UmbLitElement {
    #context;
    // No reactive property declaration because it's causing a re-render that is not needed.
    // This just works as a shortcut to set the values on the context. [NL]
    set value(value) {
        this.#context.setValue(value);
    }
    get value() {
        return this.#context.getValue();
    }
    #ufmContext;
    constructor() {
        super();
        this.#context = new UmbUfmRenderContext(this);
        this.inline = false;
        this.consumeContext(UMB_UFM_CONTEXT, (ufmContext) => {
            this.#ufmContext = ufmContext;
        });
    }
    toString() {
        return this.shadowRoot?.textContent ?? '';
    }
    render() {
        return until(this.#renderMarkdown());
    }
    async #renderMarkdown() {
        if (!this.#ufmContext || !this.markdown)
            return null;
        const markup = await this.#ufmContext.parse(this.markdown, this.inline);
        return markup ? unsafeHTML(markup) : nothing;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				position: relative;
			}

			* {
				max-width: 100%;
				word-wrap: break-word;
			}

			pre {
				overflow: auto;
			}

			code {
				font-family: var(--uui-font-monospace, monospace);
				white-space: pre-wrap;
				background-color: var(--uui-color-background);
				border-radius: var(--uui-border-radius);
				padding: 0.2em 0.4em;
			}

			:host > :first-child {
				margin-block-start: 0;
			}

			:host > :last-child {
				margin-block-end: 0;
			}
		`,
    ]; }
};
__decorate([
    property({ type: Boolean })
], UmbUfmRenderElement.prototype, "inline", void 0);
__decorate([
    property()
], UmbUfmRenderElement.prototype, "markdown", void 0);
UmbUfmRenderElement = __decorate([
    customElement('umb-ufm-render')
], UmbUfmRenderElement);
export { UmbUfmRenderElement };
export { UmbUfmRenderElement as element };
