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 { css, html, customElement, state } from '../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../core/lit-element/index.js';
import { consumeContext } from '../../../../../libs/context-api/index.js';
//TODO: add a disabled attribute to the show more button when the total number of items is correctly returned from the endpoint
let UmbLogViewerOverviewViewElement = class UmbLogViewerOverviewViewElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this._canShowLogs = false;
    }
    #logViewerContext;
    set _logViewerContext(value) {
        this.#logViewerContext = value;
        this.#observeErrorCount();
        this.#observeCanShowLogs();
        value?.getLogLevels(0, 100);
    }
    get _logViewerContext() {
        return this.#logViewerContext;
    }
    #observeErrorCount() {
        this.observe(this._logViewerContext?.logCount, (logLevelCount) => {
            this._errorCount = logLevelCount?.Error;
        });
    }
    #observeCanShowLogs() {
        this.observe(this._logViewerContext?.canShowLogs, (canShowLogs) => {
            this._canShowLogs = canShowLogs ?? false;
        });
    }
    render() {
        return html `
			<div id="logviewer-layout">
				<div id="info">
					<uui-box id="time-period" headline=${this.localize.term('logViewer_timePeriod')}>
						<umb-log-viewer-date-range-selector></umb-log-viewer-date-range-selector>
					</uui-box>

					<uui-box id="errors" headline=${this.localize.term('logViewer_numberOfErrors')}>
						<uui-button
							label=${this.localize.term('logViewer_showErrorLogs')}
							href=${`section/settings/workspace/logviewer/view/search/?lq=${encodeURIComponent(`@Level='Fatal' or @Level='Error' or Has(@Exception)`)}`}>
							<h2 id="error-count">
								${this._errorCount === undefined ? html `<uui-loader></uui-loader>` : this._errorCount}
							</h2>
						</uui-button>
					</uui-box>

					<uui-box id="level" headline=${this.localize.term('logViewer_logLevels')}>
						<h2 id="log-level"><umb-log-viewer-log-level-overview></umb-log-viewer-log-level-overview></h2>
					</uui-box>

					<umb-log-viewer-log-types-chart id="types"></umb-log-viewer-log-types-chart>
				</div>

				${this._canShowLogs
            ? html `<div id="saved-searches-container">
								<umb-log-viewer-saved-searches-overview></umb-log-viewer-saved-searches-overview>
							</div>

							<div id="common-messages-container">
								<umb-log-viewer-message-templates-overview></umb-log-viewer-message-templates-overview>
							</div>`
            : html `<umb-log-viewer-to-many-logs-warning id="to-many-logs-warning"></umb-log-viewer-to-many-logs-warning>`}
			</div>
		`;
    }
    static { this.styles = [
        css `
			:host {
				display: block;
				margin: var(--uui-size-layout-1);
			}

			#logviewer-layout {
				padding-bottom: var(--uui-size-layout-1);
				display: grid;
				grid-template-columns: 7fr 2fr;
				grid-template-rows: auto auto;
				gap: 20px 20px;
				grid-auto-flow: row;
				grid-template-areas:
					'saved-searches info'
					'common-messages info';
			}

			#info {
				grid-area: info;
				align-self: start;
				display: grid;
				grid-template-columns: repeat(2, 1fr);
				grid-template-rows: repeat(4, max-content);
				gap: 20px 20px;
			}

			#time-period {
				grid-area: 1 / 1 / 2 / 3;
			}

			#errors {
				grid-area: 2 / 1 / 3 / 2;
				--uui-box-default-padding: 0;
			}

			#errors > uui-button {
				width: 100%;
			}

			#level {
				grid-area: 2 / 2 / 3 / 3;
			}

			#log-level {
				color: var(--uui-color-positive);
				text-align: center;
				margin: 0;
			}

			#types {
				grid-area: 3 / 1 / 5 / 3;
			}

			#saved-searches-container,
			to-many-logs-warning {
				grid-area: saved-searches;
			}

			#common-messages-container {
				grid-area: common-messages;
				--uui-box-default-padding: 0 var(--uui-size-space-5, 18px) var(--uui-size-space-5, 18px)
					var(--uui-size-space-5, 18px);
			}

			#common-messages-container > uui-box {
				height: 100%;
			}

			uui-label:nth-of-type(2) {
				display: block;
				margin-top: var(--uui-size-space-5);
			}

			#error-count {
				font-size: 3rem;
				text-align: center;
				color: var(--uui-color-danger);
				margin: 0;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbLogViewerOverviewViewElement.prototype, "_errorCount", void 0);
__decorate([
    state()
], UmbLogViewerOverviewViewElement.prototype, "_canShowLogs", void 0);
__decorate([
    consumeContext({
        context: UMB_APP_LOG_VIEWER_CONTEXT,
    })
], UmbLogViewerOverviewViewElement.prototype, "_logViewerContext", null);
UmbLogViewerOverviewViewElement = __decorate([
    customElement('umb-log-viewer-overview-view')
], UmbLogViewerOverviewViewElement);
export { UmbLogViewerOverviewViewElement };
