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_CREATE_MEMBER_WORKSPACE_PATH_PATTERN } from '../../paths.js';
import { html, customElement, state, repeat, css } from '../../../../../external/lit/index.js';
import { UmbTextStyles } from '../../../../core/style/index.js';
import { UmbModalBaseElement } from '../../../../core/modal/index.js';
import { UmbMemberTypeTreeRepository } from '../../../member-type/index.js';
let UmbMemberCreateOptionsModalElement = class UmbMemberCreateOptionsModalElement extends UmbModalBaseElement {
    constructor() {
        super(...arguments);
        this._options = [];
        this.#memberTypeTreeRepository = new UmbMemberTypeTreeRepository(this);
    }
    #memberTypeTreeRepository;
    firstUpdated() {
        this.#getOptions();
    }
    async #getOptions() {
        //TODO: Should we use the tree repository or make a collection repository?
        //TODO: And how would we get all the member types?
        //TODO: This only works because member types can't have folders.
        const { data } = await this.#memberTypeTreeRepository.requestTreeRootItems({});
        if (!data)
            return;
        this._options = data.items.map((item) => {
            return {
                label: item.name,
                unique: item.unique,
                icon: item.icon || '',
            };
        });
    }
    // close the modal when navigating
    #onOpen(event, unique) {
        event?.stopPropagation();
        // TODO: the href does not emit an event, so we need to use the click event
        const path = UMB_CREATE_MEMBER_WORKSPACE_PATH_PATTERN.generateAbsolute({
            memberTypeUnique: unique,
        });
        history.pushState(null, '', path);
        this._submitModal();
    }
    render() {
        return html `
			<uui-dialog-layout headline=${this.localize.term('actions_create')}>
				${this.#renderOptions()}
				<uui-button
					slot="actions"
					id="cancel"
					label=${this.localize.term('general_cancel')}
					@click="${this._rejectModal}"></uui-button>
			</uui-dialog-layout>
		`;
    }
    #renderOptions() {
        return repeat(this._options, (option) => option.unique, (option) => html `
				<uui-ref-node
					.name=${this.localize.string(option.label)}
					@open=${(event) => this.#onOpen(event, option.unique)}>
					<umb-icon slot="icon" name=${option.icon || 'icon-circle-dotted'}></umb-icon>
				</uui-ref-node>
			`);
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			#blank {
				border-bottom: 1px solid var(--uui-color-border);
			}

			#edit-permissions {
				margin-top: var(--uui-size-6);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbMemberCreateOptionsModalElement.prototype, "_options", void 0);
UmbMemberCreateOptionsModalElement = __decorate([
    customElement('umb-member-create-options-modal')
], UmbMemberCreateOptionsModalElement);
export { UmbMemberCreateOptionsModalElement };
export { UmbMemberCreateOptionsModalElement as element };
