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 { css, customElement, html, state } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import { UMB_COLLECTION_CONTEXT } from '../../../../../core/collection/index.js';
import './column-layouts/name/webhook-table-name-column-layout.element.js';
import './column-layouts/content-type/webhook-table-name-column-layout.element.js';
import { UMB_EDIT_WEBHOOK_WORKSPACE_PATH_PATTERN } from '../../../paths.js';
let UmbWebhookTableCollectionViewElement = class UmbWebhookTableCollectionViewElement extends UmbLitElement {
    #collectionContext;
    #enabledLabel;
    #disabledLabel;
    #unnamedWebhookLabel;
    constructor() {
        super();
        this._tableConfig = {
            allowSelection: false,
        };
        this._tableColumns = [
            {
                name: this.localize.term('general_name'),
                alias: 'name',
            },
            {
                name: this.localize.term('webhooks_url'),
                alias: 'url',
            },
            {
                name: this.localize.term('webhooks_events'),
                alias: 'events',
            },
            {
                name: this.localize.term('webhooks_types'),
                alias: 'contentTypes',
                elementName: 'umb-webhook-table-content-type-column-layout',
            },
            {
                name: this.localize.term('general_status'),
                alias: 'status',
            },
            {
                name: '',
                alias: 'entityActions',
                align: 'right',
            },
        ];
        this._tableItems = [];
        this.#enabledLabel = this.localize.term('webhooks_enabled');
        this.#disabledLabel = this.localize.term('webhooks_disabled');
        this.#unnamedWebhookLabel = this.localize.term('webhooks_unnamedWebhook');
        this.consumeContext(UMB_COLLECTION_CONTEXT, (instance) => {
            this.#collectionContext = instance;
            this.#observeCollectionItems();
        });
    }
    #observeCollectionItems() {
        if (!this.#collectionContext)
            return;
        this.observe(this.#collectionContext.items, (items) => this.#createTableItems(items), 'umbCollectionItemsObserver');
    }
    #createTableItems(webhooks) {
        this._tableItems = webhooks.map((webhook) => {
            const name = webhook.name || `(${this.#unnamedWebhookLabel})`;
            const path = UMB_EDIT_WEBHOOK_WORKSPACE_PATH_PATTERN.generateAbsolute({ unique: webhook.unique });
            return {
                id: webhook.unique,
                icon: 'icon-webhook',
                data: [
                    {
                        columnAlias: 'name',
                        value: html `<a href=${path}>${name}</a>`,
                    },
                    {
                        columnAlias: 'url',
                        value: webhook.url,
                    },
                    {
                        columnAlias: 'events',
                        value: webhook.events.map((event) => event.eventName).join(', ') || 'None',
                    },
                    {
                        columnAlias: 'contentTypes',
                        value: { contentTypeName: webhook.events[0].eventType, contentTypes: webhook.contentTypes },
                    },
                    {
                        columnAlias: 'status',
                        value: html `<uui-tag color=${webhook.enabled ? 'positive' : 'danger'}
							>${webhook.enabled ? this.#enabledLabel : this.#disabledLabel}</uui-tag
						>`,
                    },
                    {
                        columnAlias: 'entityActions',
                        value: html `<umb-entity-actions-table-column-view
							.value=${{
                            entityType: webhook.entityType,
                            unique: webhook.unique,
                            name: webhook.name,
                        }}></umb-entity-actions-table-column-view>`,
                    },
                ],
            };
        });
    }
    render() {
        return html `
			<umb-table .config=${this._tableConfig} .columns=${this._tableColumns} .items=${this._tableItems}></umb-table>
		`;
    }
    static { this.styles = [
        css `
			:host {
				display: flex;
				flex-direction: column;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbWebhookTableCollectionViewElement.prototype, "_tableConfig", void 0);
__decorate([
    state()
], UmbWebhookTableCollectionViewElement.prototype, "_tableColumns", void 0);
__decorate([
    state()
], UmbWebhookTableCollectionViewElement.prototype, "_tableItems", void 0);
UmbWebhookTableCollectionViewElement = __decorate([
    customElement('umb-webhook-table-collection-view')
], UmbWebhookTableCollectionViewElement);
export { UmbWebhookTableCollectionViewElement };
export default UmbWebhookTableCollectionViewElement;
