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 { UmbMemberTypeTreeRepository } from '../../member-type/tree/member-type-tree.repository.js';
import { UMB_MEMBER_COLLECTION_CONTEXT } from './member-collection.context-token.js';
import { css, customElement, html, ifDefined, repeat, state } from '../../../../external/lit/index.js';
import { UmbLitElement } from '../../../core/lit-element/index.js';
let UmbMemberCollectionHeaderElement = class UmbMemberCollectionHeaderElement extends UmbLitElement {
    #collectionContext;
    // TODO: Should we make a collection repository for member types?
    #contentTypeRepository;
    constructor() {
        super();
        // TODO: Should we make a collection repository for member types?
        this.#contentTypeRepository = new UmbMemberTypeTreeRepository(this);
        this._contentTypes = [];
        this.consumeContext(UMB_MEMBER_COLLECTION_CONTEXT, (instance) => {
            this.#collectionContext = instance;
        });
        this.#requestContentTypes();
    }
    async #requestContentTypes() {
        const { data } = await this.#contentTypeRepository.requestTreeRootItems({});
        if (data) {
            this._contentTypes = data.items.map((item) => ({
                unique: item.unique,
                name: item.name,
                icon: item.icon || '',
                entityType: item.entityType,
            }));
        }
    }
    get #getContentTypeFilterLabel() {
        if (!this._selectedContentTypeUnique)
            return this.localize.term('general_all') + ' Member types';
        return (this._contentTypes.find((type) => type.unique === this._selectedContentTypeUnique)?.name ||
            this.localize.term('general_all'));
    }
    #onContentTypeFilterChange(contentTypeUnique) {
        this._selectedContentTypeUnique = contentTypeUnique;
        this.#collectionContext?.setMemberTypeFilter(contentTypeUnique);
    }
    render() {
        return html `
			<umb-collection-action-bundle></umb-collection-action-bundle>
			<umb-collection-filter-field></umb-collection-filter-field>
			${this.#renderContentTypeFilter()}
		`;
    }
    #renderContentTypeFilter() {
        return html `
			<umb-dropdown data-mark="dropdown:filter">
				<span slot="label">${this.#getContentTypeFilterLabel}</span>
				<div id="dropdown-layout">
					<uui-button
						label=${this.localize.term('general_all')}
						look=${!this._selectedContentTypeUnique ? 'secondary' : 'default'}
						data-mark="action:select-all"
						compact
						@click=${() => this.#onContentTypeFilterChange('')}></uui-button>
					${repeat(this._contentTypes, (memberType) => memberType.unique, (memberType) => html `
							<uui-button
								label=${ifDefined(memberType.name)}
								look=${memberType.unique === this._selectedContentTypeUnique ? 'secondary' : 'default'}
								data-mark="action:select-${memberType.unique}"
								compact
								@click=${() => this.#onContentTypeFilterChange(memberType.unique)}></uui-button>
						`)}
				</div>
			</umb-dropdown>
		`;
    }
    static { this.styles = [
        css `
			:host {
				height: 100%;
				width: 100%;
				display: flex;
				justify-content: space-between;
				white-space: nowrap;
				gap: var(--uui-size-space-5);
				align-items: center;
			}

			#dropdown-layout {
				display: flex;
				flex-direction: column;
				--uui-button-content-align: left;
			}

			umb-collection-filter-field {
				width: 100%;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbMemberCollectionHeaderElement.prototype, "_contentTypes", void 0);
__decorate([
    state()
], UmbMemberCollectionHeaderElement.prototype, "_selectedContentTypeUnique", void 0);
UmbMemberCollectionHeaderElement = __decorate([
    customElement('umb-member-collection-header')
], UmbMemberCollectionHeaderElement);
export { UmbMemberCollectionHeaderElement };
export default UmbMemberCollectionHeaderElement;
