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 { UmbTextStyles } from '../../../../../core/style/index.js';
import { html, customElement, state, repeat, css, nothing } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import { umbExtensionsRegistry } from '../../../../../core/extension-registry/index.js';
import './user-group-entity-type-permissions.element.js';
import './user-group-entity-type-granular-permissions.element.js';
let UmbUserGroupEntityTypePermissionGroupsElement = class UmbUserGroupEntityTypePermissionGroupsElement extends UmbLitElement {
    constructor() {
        super();
        this._groups = [];
        this._hasGranularPermissionsWithNoEntityType = false;
        this.observe(umbExtensionsRegistry.byType('entityUserPermission'), (manifests) => {
            const entityTypes = [...new Set(manifests.flatMap((manifest) => manifest.forEntityTypes))];
            this._groups = entityTypes
                .map((entityType) => {
                return {
                    entityType,
                    headline: this.localize.term(`user_permissionsEntityGroup_${entityType}`),
                };
            })
                .sort((a, b) => a.headline.localeCompare(b.headline));
        }, 'umbUserPermissionsObserver');
        this.#observeGranularPermissionsWithNoEntityType();
    }
    #observeGranularPermissionsWithNoEntityType() {
        this.observe(umbExtensionsRegistry.byTypeAndFilter('userGranularPermission', (manifest) => manifest.forEntityTypes === undefined || manifest.forEntityTypes.length === 0), (manifests) => {
            this._hasGranularPermissionsWithNoEntityType = manifests.length > 0;
        });
    }
    render() {
        return html `${repeat(this._groups, (group) => group.entityType, (group) => html `<uui-box>
					<div slot="headline">${group.headline}</div>

					<umb-user-group-entity-type-permissions
						.entityType=${group.entityType}></umb-user-group-entity-type-permissions>

					<umb-user-group-entity-type-granular-permissions
						.entityType=${group.entityType}></umb-user-group-entity-type-granular-permissions>
				</uui-box>`)}
		${this.#renderUngroupedGranularPermissions()}`;
    }
    #renderUngroupedGranularPermissions() {
        if (!this._hasGranularPermissionsWithNoEntityType)
            return nothing;
        return html `<uui-box headline=${this.localize.term('general_rights')}>
			<umb-user-group-entity-type-granular-permissions></umb-user-group-entity-type-granular-permissions
		></uui-box>`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			uui-box {
				margin-top: var(--uui-size-space-6);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbUserGroupEntityTypePermissionGroupsElement.prototype, "_groups", void 0);
__decorate([
    state()
], UmbUserGroupEntityTypePermissionGroupsElement.prototype, "_hasGranularPermissionsWithNoEntityType", void 0);
UmbUserGroupEntityTypePermissionGroupsElement = __decorate([
    customElement('umb-user-group-entity-type-permission-groups')
], UmbUserGroupEntityTypePermissionGroupsElement);
export { UmbUserGroupEntityTypePermissionGroupsElement };
export default UmbUserGroupEntityTypePermissionGroupsElement;
