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 { classMap, css, customElement, html, nothing, property, state, when, } from '../../../../external/lit/index.js';
import { DocumentVariantStateModel } from '../../../core/backend-api/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
import { UMB_APP_LANGUAGE_CONTEXT } from '../../../language/index.js';
let UmbDocumentSearchResultItemElement = class UmbDocumentSearchResultItemElement extends UmbLitElement {
    constructor() {
        super();
        this.consumeContext(UMB_APP_LANGUAGE_CONTEXT, (instance) => {
            this.#observeAppCulture(instance);
            this.#observeDefaultCulture(instance);
        });
    }
    #observeAppCulture(context) {
        this.observe(context?.appLanguageCulture, (value) => {
            this._currentCulture = value;
            this._variant = this.#getVariant(value);
        });
    }
    #observeDefaultCulture(context) {
        this.observe(context?.appDefaultLanguage, (value) => {
            this._defaultCulture = value?.unique;
        });
    }
    #getVariant(culture) {
        return this.item?.variants.find((x) => x.culture === culture);
    }
    #getLabel() {
        if (this.item?.variants[0]?.culture === null) {
            return this.item?.name ?? 'Unknown';
        }
        const fallbackName = this.#getVariant(this._defaultCulture)?.name ?? this.item?.name ?? 'Unknown';
        return this._variant?.name ?? `(${fallbackName})`;
    }
    #getDraftState() {
        if (this.item?.isTrashed)
            return false;
        return (this._variant?.state === DocumentVariantStateModel.DRAFT ||
            this.item?.variants[0]?.state === DocumentVariantStateModel.DRAFT);
    }
    render() {
        if (!this.item)
            return nothing;
        const label = this.#getLabel();
        const isDraft = this.#getDraftState();
        const classes = {
            trashed: this.item.isTrashed,
            hasState: this.item.isTrashed || isDraft,
        };
        return html `
			${when(this.item.documentType.icon ?? this.item.icon, (icon) => html `<umb-icon name=${icon}></umb-icon>`, () => html `<uui-icon name="icon-document"></uui-icon>`)}
			<span class=${classMap(classes)}>${label}</span>
			<div class="extra">
				${when(this.item.isTrashed, () => html `
						<uui-tag look="secondary">
							<umb-localize key="mediaPicker_trashed">Trashed</umb-localize>
						</uui-tag>
					`)}
				${when(!this.item.isTrashed && isDraft, () => html `<uui-tag look="secondary">Draft</uui-tag>`)}
			</div>
		`;
    }
    static { this.styles = [
        css `
			:host {
				border-radius: var(--uui-border-radius);
				outline-offset: -3px;
				padding: var(--uui-size-space-3) var(--uui-size-space-5);

				display: flex;
				gap: var(--uui-size-space-3);
				align-items: center;

				width: 100%;

				> span {
					flex: 1;

					&.hasState {
						opacity: 0.6;
					}

					&.trashed {
						text-decoration: line-through;
					}
				}
			}
		`,
    ]; }
};
__decorate([
    property({ type: Object })
], UmbDocumentSearchResultItemElement.prototype, "item", void 0);
__decorate([
    state()
], UmbDocumentSearchResultItemElement.prototype, "_currentCulture", void 0);
__decorate([
    state()
], UmbDocumentSearchResultItemElement.prototype, "_defaultCulture", void 0);
__decorate([
    state()
], UmbDocumentSearchResultItemElement.prototype, "_variant", void 0);
UmbDocumentSearchResultItemElement = __decorate([
    customElement('umb-document-search-result-item')
], UmbDocumentSearchResultItemElement);
export { UmbDocumentSearchResultItemElement };
export { UmbDocumentSearchResultItemElement as element };
