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_APP_LOG_VIEWER_CONTEXT } from '../../../logviewer-workspace.context-token.js';
import { UmbTextStyles } from '../../../../../core/style/index.js';
import { css, html, customElement, state, nothing } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import { consumeContext } from '../../../../../../libs/context-api/index.js';
let UmbLogViewerMessageTemplatesOverviewElement = class UmbLogViewerMessageTemplatesOverviewElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this.#itemsPerPage = 10;
        this.#currentPage = 1;
        this._total = 0;
        this._messageTemplates = [];
    }
    #itemsPerPage;
    #currentPage;
    #logViewerContext;
    set _logViewerContext(value) {
        this.#logViewerContext = value;
        this.#getMessageTemplates();
        this.#observeStuff();
    }
    get _logViewerContext() {
        return this.#logViewerContext;
    }
    #observeStuff() {
        this.observe(this._logViewerContext?.messageTemplates, (templates) => {
            this._messageTemplates = templates?.items ?? [];
            this._total = templates?.total ?? 0;
        });
    }
    #getMessageTemplates() {
        const skip = this.#currentPage * this.#itemsPerPage - this.#itemsPerPage;
        this._logViewerContext?.getMessageTemplates(skip, this.#itemsPerPage);
    }
    #onChangePage(event) {
        this.#currentPage = event.target.current;
        this.#getMessageTemplates();
    }
    render() {
        return html `
			<uui-box headline=${this.localize.term('logViewer_commonLogMessages')} id="saved-searches">
				<p style="font-style: italic;">${this.localize.term('logViewer_totalUniqueMessageTypes', this._total)}</p>

				<uui-table>
					${this._messageTemplates
            ? this._messageTemplates.map((template) => html `<uui-table-row>
										<uui-table-cell>
											<a
												href=${`section/settings/workspace/logviewer/view/search/?lq=${encodeURIComponent(`@MessageTemplate='${template.messageTemplate}'`)}`}>
												<span>${template.messageTemplate}</span> <span>${template.count}</span>
											</a>
										</uui-table-cell>
									</uui-table-row>`)
            : ''}
				</uui-table>
				${this._total > this.#itemsPerPage
            ? html `<uui-pagination
							.current=${this.#currentPage}
							.total=${Math.ceil(this._total / this.#itemsPerPage)}
							firstlabel=${this.localize.term('general_first')}
							previouslabel=${this.localize.term('general_previous')}
							nextlabel=${this.localize.term('general_next')}
							lastlabel=${this.localize.term('general_last')}
							@change=${this.#onChangePage}></uui-pagination>`
            : nothing}
			</uui-box>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			uui-pagination {
				margin-top: var(--uui-size-layout-1);
			}

			#show-more-templates-btn {
				margin-top: var(--uui-size-space-5);
			}

			a {
				display: flex;
				align-items: center;
				justify-content: space-between;
				text-decoration: none;
				color: inherit;
			}

			uui-table-cell {
				padding: 10px 20px;
				height: unset;
			}

			uui-table-row {
				cursor: pointer;
			}

			uui-table-row:hover > uui-table-cell {
				background-color: var(--uui-color-surface-alt);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbLogViewerMessageTemplatesOverviewElement.prototype, "_total", void 0);
__decorate([
    state()
], UmbLogViewerMessageTemplatesOverviewElement.prototype, "_messageTemplates", void 0);
__decorate([
    consumeContext({ context: UMB_APP_LOG_VIEWER_CONTEXT })
], UmbLogViewerMessageTemplatesOverviewElement.prototype, "_logViewerContext", null);
UmbLogViewerMessageTemplatesOverviewElement = __decorate([
    customElement('umb-log-viewer-message-templates-overview')
], UmbLogViewerMessageTemplatesOverviewElement);
export { UmbLogViewerMessageTemplatesOverviewElement };
