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 { html, customElement, state } from '../../../../external/lit/index.js';
import { UmbSelectionManager } from '../../utils/index.js';
import { umbExtensionsRegistry } from '../../extension-registry/index.js';
import { UmbModalBaseElement } from '../../modal/index.js';
let UmbSectionPickerModalElement = class UmbSectionPickerModalElement extends UmbModalBaseElement {
    #selectionManager;
    constructor() {
        super();
        this._sections = [];
        this._selectable = false;
        this.#selectionManager = new UmbSelectionManager(this);
        this.#selectionManager.setSelectable(true);
        this.observe(this.#selectionManager.selectable, (selectable) => (this._selectable = selectable), null);
        this.observe(umbExtensionsRegistry.byType('section'), (sections) => (this._sections = sections), null);
    }
    connectedCallback() {
        super.connectedCallback();
        this.#selectionManager.setMultiple(this.data?.multiple ?? false);
        this.#selectionManager.setSelection(this.value?.selection ?? []);
    }
    #submit() {
        this.value = { selection: this.#selectionManager.getSelection() };
        this._submitModal();
    }
    render() {
        return html `
			<umb-body-layout headline="Select sections">
				<uui-box>
					${this._sections.map((item) => html `
							<uui-menu-item
								label=${this.localize.string(item.meta.label)}
								?selectable=${this._selectable}
								?selected=${this.#selectionManager.isSelected(item.alias)}
								@selected=${() => this.#selectionManager.select(item.alias)}
								@deselected=${() => this.#selectionManager.deselect(item.alias)}></uui-menu-item>
						`)}
				</uui-box>
				<div slot="actions">
					<uui-button label="Close" @click=${this._rejectModal}></uui-button>
					<uui-button label="Submit" look="primary" color="positive" @click=${this.#submit}></uui-button>
				</div>
			</umb-body-layout>
		`;
    }
};
__decorate([
    state()
], UmbSectionPickerModalElement.prototype, "_sections", void 0);
__decorate([
    state()
], UmbSectionPickerModalElement.prototype, "_selectable", void 0);
UmbSectionPickerModalElement = __decorate([
    customElement('umb-section-picker-modal')
], UmbSectionPickerModalElement);
export { UmbSectionPickerModalElement };
export default UmbSectionPickerModalElement;
