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 { UmbLanguageCollectionRepository } from '../../collection/index.js';
import { html, customElement, state, repeat } from '../../../../external/lit/index.js';
import { UmbSelectionManager } from '../../../core/utils/index.js';
import { UmbModalBaseElement } from '../../../core/modal/index.js';
let UmbLanguagePickerModalElement = class UmbLanguagePickerModalElement extends UmbModalBaseElement {
    constructor() {
        super(...arguments);
        this._languages = [];
        this.#collectionRepository = new UmbLanguageCollectionRepository(this);
        this.#selectionManager = new UmbSelectionManager(this);
    }
    #collectionRepository;
    #selectionManager;
    connectedCallback() {
        super.connectedCallback();
        this.#selectionManager.setSelectable(true);
        this.#selectionManager.setMultiple(this.data?.multiple ?? false);
        this.#selectionManager.setSelection(this.value?.selection ?? []);
        this.observe(this.#selectionManager.selection, (selection) => {
            this.value = { selection };
        });
    }
    async firstUpdated() {
        const { data } = await this.#collectionRepository.requestCollection({});
        this._languages = data?.items ?? [];
    }
    get #filteredLanguages() {
        if (this.data?.filter) {
            return this._languages.filter(this.data.filter);
        }
        else {
            return this._languages;
        }
    }
    #submit() {
        this.modalContext?.submit();
    }
    #close() {
        this.modalContext?.reject();
    }
    render() {
        return html `<umb-body-layout headline=${this.localize.term('defaultdialogs_selectLanguages')}>
			<uui-box>
				${this.#filteredLanguages.length > 0
            ? repeat(this.#filteredLanguages, (item) => item.unique, (item) => html `
								<uui-menu-item
									label=${item.name ?? ''}
									selectable
									@selected=${() => this.#selectionManager.select(item.unique)}
									@deselected=${() => this.#selectionManager.deselect(item.unique)}
									?selected=${this.value.selection.includes(item.unique)}>
									<uui-icon slot="icon" name="icon-globe"></uui-icon>
								</uui-menu-item>
							`)
            : html `<umb-localize key="language_noFallbackLanguages">
							There are no other languages to choose from
						</umb-localize>`}
			</uui-box>
			<div slot="actions">
				<uui-button label=${this.localize.term('general_close')} @click=${this.#close}></uui-button>
				<uui-button label=${this.localize.term('general_submit')} look="primary" color="positive" @click=${this.#submit}></uui-button>
			</div>
		</umb-body-layout> `;
    }
};
__decorate([
    state()
], UmbLanguagePickerModalElement.prototype, "_languages", void 0);
UmbLanguagePickerModalElement = __decorate([
    customElement('umb-language-picker-modal')
], UmbLanguagePickerModalElement);
export { UmbLanguagePickerModalElement };
export default UmbLanguagePickerModalElement;
