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 { createExtensionApiByAlias } from '../../../../core/extension-registry/index.js';
import { html, customElement, property, repeat, state } from '../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../core/lit-element/index.js';
let UmbUserDocumentStartNodeElement = class UmbUserDocumentStartNodeElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this.#uniques = [];
        this.readonly = false;
        this._displayValue = [];
    }
    #uniques;
    get uniques() {
        return this.#uniques;
    }
    set uniques(value) {
        this.#uniques = value;
        if (this.#uniques.length > 0) {
            this.#observeItems();
        }
    }
    async #observeItems() {
        // TODO: get back to this when documents have been decoupled from users.
        // The repository alias is hardcoded on purpose to avoid a document import in the user module.
        const itemRepository = await createExtensionApiByAlias(this, 'Umb.Repository.DocumentItem');
        const { asObservable } = await itemRepository.requestItems(this.#uniques);
        this.observe(asObservable?.(), (data) => {
            this._displayValue = data || [];
        });
    }
    render() {
        if (this.uniques.length < 1) {
            return html `
				<uui-ref-node
					name="Content Root"
					?disabled=${this.readonly}
					style="--uui-color-disabled-contrast: var(--uui-color-text)">
					<uui-icon slot="icon" name="folder"></uui-icon>
				</uui-ref-node>
			`;
        }
        return repeat(this._displayValue, (item) => item.unique, (item) => {
            return html `
					<!-- TODO: get correct variant name -->
					<uui-ref-node
						name=${item.variants[0]?.name}
						?disabled=${this.readonly}
						style="--uui-color-disabled-contrast: var(--uui-color-text)">
						<uui-icon slot="icon" name="folder"></uui-icon>
					</uui-ref-node>
				`;
        });
    }
};
__decorate([
    property({ type: Array, attribute: false })
], UmbUserDocumentStartNodeElement.prototype, "uniques", null);
__decorate([
    property({ type: Boolean })
], UmbUserDocumentStartNodeElement.prototype, "readonly", void 0);
__decorate([
    state()
], UmbUserDocumentStartNodeElement.prototype, "_displayValue", void 0);
UmbUserDocumentStartNodeElement = __decorate([
    customElement('umb-user-document-start-node')
], UmbUserDocumentStartNodeElement);
export { UmbUserDocumentStartNodeElement };
export default UmbUserDocumentStartNodeElement;
