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 '../../../style/index.js';
import { css, html, nothing, customElement, state } from '../../../../../external/lit/index.js';
import { HealthStatusModel, IndexerService, SearcherService } from '../../../backend-api/index.js';
import { UmbLitElement } from '../../../lit-element/index.js';
import { tryExecute } from '../../../resources/index.js';
let UmbDashboardExamineOverviewElement = class UmbDashboardExamineOverviewElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this._loadingIndexers = false;
        this._loadingSearchers = false;
    }
    connectedCallback() {
        super.connectedCallback();
        this._getIndexers();
        this._getSearchers();
    }
    async _getIndexers() {
        this._loadingIndexers = true;
        const { data } = await tryExecute(this, IndexerService.getIndexer({ query: { take: 9999, skip: 0 } }));
        this._indexers = data?.items ?? [];
        this._loadingIndexers = false;
    }
    async _getSearchers() {
        this._loadingSearchers = true;
        const { data } = await tryExecute(this, SearcherService.getSearcher({ query: { take: 9999, skip: 0 } }));
        this._searchers = data?.items ?? [];
        this._loadingSearchers = false;
    }
    #renderStatus(status) {
        switch (status) {
            case HealthStatusModel.HEALTHY:
                return html `<umb-icon name="icon-check color-green"></umb-icon>`;
            case HealthStatusModel.CORRUPT:
            case HealthStatusModel.UNHEALTHY:
                return html `<umb-icon name="icon-alert color-red"></umb-icon>`;
            case HealthStatusModel.REBUILDING:
                return html `<umb-icon name="icon-time color-yellow"></umb-icon>`;
            default:
                return;
        }
    }
    render() {
        return html `
			<uui-box headline=${this.localize.term('examineManagement_indexers')} class="overview">
				<p>
					<strong><umb-localize key="examineManagement_manageIndexes">Manage Examine indexes</umb-localize></strong
					><br />
					<umb-localize key="examineManagement_manageIndexesDescription"
						>Allows you to view the details of each index and provides some tools for managing the indexes</umb-localize
					>
				</p>
				${this.#renderIndexersList()}
			</uui-box>
			<uui-box headline=${this.localize.term('examineManagement_searchers')}>
				<p>
					<strong><umb-localize key="examineManagement_configuredSearchers">Configured Searchers</umb-localize></strong
					><br />
					<umb-localize key="examineManagement_configuredSearchersDescription"
						>Shows properties and tools for any configured Searcher (e.g. such as a multi-index searcher)</umb-localize
					>
				</p>
				${this.#renderSearchersList()}
			</uui-box>
		`;
    }
    #renderIndexersList() {
        if (this._loadingIndexers)
            return html `<uui-loader></uui-loader>`;
        if (!this._indexers)
            return nothing;
        return html ` <uui-table class="overview">
			${this._indexers.map((index) => {
            return html `
					<uui-table-row>
						<uui-table-cell style="width:0px"> ${this.#renderStatus(index.healthStatus.status)} </uui-table-cell>
						<uui-table-cell>
							<a href="${window.location.href.replace(/\/+$/, '')}/index/${index.name}">${index.name}</a>
						</uui-table-cell>
					</uui-table-row>
				`;
        })}
		</uui-table>`;
    }
    #renderSearchersList() {
        if (this._loadingSearchers)
            return html `<uui-loader></uui-loader>`;
        if (!this._searchers)
            return nothing;
        return html `
			<uui-table class="overview2">
				${this._searchers.map((searcher) => {
            return html `<uui-table-row>
							<uui-table-cell style="width:0px">
								<uui-icon-essentials>
									<uui-icon
										style="vertical-align: top"
										name="info"></uui-icon>
									</uui-icon>
								</uui-icon-essentials>
							</uui-table-cell>
						<uui-table-cell><a href="${window.location.href.replace(/\/+$/, '')}/searcher/${searcher.name}">${searcher.name}</a>
					</uui-table-cell>
					</uui-table-row>`;
        })}
			</uui-table>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: block;
			}

			uui-box + uui-box {
				margin-top: var(--uui-size-space-5);
			}

			uui-box p {
				margin-top: 0;
			}

			a {
				color: var(--uui-color-text);
				background: transparent;
				border: none;
				text-decoration: underline;
				cursor: pointer;
			}

			uui-table-cell {
				line-height: 0;
				vertical-align: middle;
			}

			uui-table-row:last-child uui-table-cell {
				padding-bottom: 0;
			}

			.positive {
				color: var(--uui-color-positive);
			}

			.danger {
				color: var(--uui-color-danger);
			}

			.not-found-message {
				font-style: italic;
				color: var(--uui-color-text-alt);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbDashboardExamineOverviewElement.prototype, "_indexers", void 0);
__decorate([
    state()
], UmbDashboardExamineOverviewElement.prototype, "_searchers", void 0);
__decorate([
    state()
], UmbDashboardExamineOverviewElement.prototype, "_loadingIndexers", void 0);
__decorate([
    state()
], UmbDashboardExamineOverviewElement.prototype, "_loadingSearchers", void 0);
UmbDashboardExamineOverviewElement = __decorate([
    customElement('umb-dashboard-examine-overview')
], UmbDashboardExamineOverviewElement);
export { UmbDashboardExamineOverviewElement };
export default UmbDashboardExamineOverviewElement;
