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_EDIT_DICTIONARY_WORKSPACE_PATH_PATTERN } from '../../../workspace/paths.js';
import { UMB_COLLECTION_CONTEXT } from '../../../../core/collection/index.js';
import { css, html, customElement, state } from '../../../../../external/lit/index.js';
import { UmbTextStyles } from '../../../../core/style/index.js';
import { UmbLitElement } from '../../../../core/lit-element/index.js';
import { UmbLanguageCollectionRepository } from '../../../../language/index.js';
let UmbDictionaryTableCollectionViewElement = class UmbDictionaryTableCollectionViewElement extends UmbLitElement {
    #collectionContext;
    #languageCollectionRepository;
    constructor() {
        super();
        this._tableConfig = {
            allowSelection: false,
        };
        this._tableColumns = [
            {
                name: 'Name',
                alias: 'name',
            },
        ];
        this._tableItems = [];
        this.#languageCollectionRepository = new UmbLanguageCollectionRepository(this);
        this.consumeContext(UMB_COLLECTION_CONTEXT, (instance) => {
            this.#collectionContext = instance;
            this.#observeCollectionItems();
        });
    }
    async #observeCollectionItems() {
        if (!this.#collectionContext)
            return;
        const { data: languageData } = await this.#languageCollectionRepository.requestCollection({});
        if (!languageData)
            return;
        this.observe(this.#collectionContext.items, (collectionItems) => {
            this.#createTableColumns(languageData.items);
            this.#createTableItems(collectionItems, languageData.items);
        }, 'umbCollectionItemsObserver');
    }
    #createTableColumns(languages) {
        const columns = [
            {
                name: this.localize.term('general_name'),
                alias: 'name',
            },
        ];
        const languageColumns = languages.map((language) => {
            return {
                name: language.name,
                alias: language.unique,
            };
        });
        this._tableColumns = [...columns, ...languageColumns];
    }
    #createTableItems(dictionaries, languages) {
        this._tableItems = dictionaries.map((dictionary) => {
            const editPath = UMB_EDIT_DICTIONARY_WORKSPACE_PATH_PATTERN.generateAbsolute({
                unique: dictionary.unique,
            });
            return {
                id: dictionary.unique,
                icon: 'icon-book-alt-2',
                data: [
                    {
                        columnAlias: 'name',
                        value: html `<a style="font-weight:bold" href=${editPath}> ${dictionary.name}</a> `,
                    },
                    ...languages.map((language) => {
                        return {
                            columnAlias: language.unique,
                            value: dictionary.translatedIsoCodes?.includes(language.unique)
                                ? this.#renderCheckIcon(language.name)
                                : this.#renderAlertIcon(language.name),
                        };
                    }),
                ],
            };
        });
    }
    #renderCheckIcon(name) {
        return html `<uui-icon
			name="check"
			title="${this.localize.term('visuallyHiddenTexts_hasTranslation')} (${name})"
			style="color:var(--uui-color-positive-standalone);display:inline-block"></uui-icon>`;
    }
    #renderAlertIcon(name) {
        return html `<uui-icon
			name="alert"
			title="${this.localize.term('visuallyHiddenTexts_noTranslation')} (${name})"
			style="color:var(--uui-color-danger-standalone);display:inline-block"></uui-icon>`;
    }
    render() {
        return html `
			<umb-table .config=${this._tableConfig} .columns=${this._tableColumns} .items=${this._tableItems}></umb-table>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: flex;
				flex-direction: column;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbDictionaryTableCollectionViewElement.prototype, "_tableConfig", void 0);
__decorate([
    state()
], UmbDictionaryTableCollectionViewElement.prototype, "_tableColumns", void 0);
__decorate([
    state()
], UmbDictionaryTableCollectionViewElement.prototype, "_tableItems", void 0);
UmbDictionaryTableCollectionViewElement = __decorate([
    customElement('umb-dictionary-table-collection-view')
], UmbDictionaryTableCollectionViewElement);
export { UmbDictionaryTableCollectionViewElement };
export default UmbDictionaryTableCollectionViewElement;
