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, query, state } from '../../../../../../external/lit/index.js';
import { UmbLitElement } from '../../../../../core/lit-element/index.js';
import { consumeContext } from '../../../../../../libs/context-api/index.js';
let UmbLogViewerPollingButtonElement = class UmbLogViewerPollingButtonElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this._poolingConfig = { enabled: false, interval: 0 };
        this.#pollingIntervals = [2000, 5000, 10000, 20000, 30000];
        this.#setPolingInterval = (interval) => {
            this._logViewerContext?.setPollingInterval(interval);
            this.#closePoolingPopover();
        };
    }
    #pollingIntervals;
    #logViewerContext;
    set _logViewerContext(value) {
        this.#logViewerContext = value;
        this.#observePoolingConfig();
    }
    get _logViewerContext() {
        return this.#logViewerContext;
    }
    #observePoolingConfig() {
        this.observe(this._logViewerContext?.polling, (poolingConfig) => {
            this._poolingConfig = poolingConfig ? { ...poolingConfig } : { enabled: false, interval: 0 };
        });
    }
    #togglePolling() {
        this._logViewerContext?.togglePolling();
    }
    #setPolingInterval;
    #closePoolingPopover() {
        if (this._dropdownElement) {
            this._dropdownElement.open = false;
        }
    }
    #getPollingLabel() {
        const seconds = this._poolingConfig.interval / 1000;
        return this.localize.term('logViewer_pollingActive', seconds);
    }
    #getIntervalLabel(interval) {
        const seconds = interval / 1000;
        return this.localize.term('logViewer_pollingInterval', seconds);
    }
    render() {
        return html `
			<uui-button-group>
				<uui-button label=${this.localize.term('logViewer_startPolling')} @click=${this.#togglePolling}>
					${this._poolingConfig.enabled
            ? html `<uui-icon name="icon-axis-rotation" id="polling-enabled-icon"></uui-icon>${this.#getPollingLabel()}`
            : html `<umb-localize key="logViewer_polling">Polling</umb-localize>`}
				</uui-button>

				<umb-dropdown id="polling-rate-dropdown" compact label=${this.localize.term('logViewer_choosePollingInterval')}>
					${this.#pollingIntervals.map((interval) => html `<uui-menu-item
								label=${this.#getIntervalLabel(interval)}
								@click-label=${() => this.#setPolingInterval(interval)}></uui-menu-item>`)}
				</umb-dropdown>
			</uui-button-group>
		`;
    }
    static { this.styles = [
        css `
			#polling-enabled-icon {
				margin-right: var(--uui-size-space-3);
				margin-bottom: 1px;
				-webkit-animation: rotate-center 0.8s ease-in-out infinite both;
				animation: rotate-center 0.8s ease-in-out infinite both;
			}

			@-webkit-keyframes rotate-center {
				0% {
					-webkit-transform: rotate(0);
					transform: rotate(0);
				}
				100% {
					-webkit-transform: rotate(360deg);
					transform: rotate(360deg);
				}
			}
			@keyframes rotate-center {
				0% {
					-webkit-transform: rotate(0);
					transform: rotate(0);
				}
				100% {
					-webkit-transform: rotate(360deg);
					transform: rotate(360deg);
				}
			}
		`,
    ]; }
};
__decorate([
    query('#polling-rate-dropdown')
], UmbLogViewerPollingButtonElement.prototype, "_dropdownElement", void 0);
__decorate([
    state()
], UmbLogViewerPollingButtonElement.prototype, "_poolingConfig", void 0);
__decorate([
    consumeContext({ context: UMB_APP_LOG_VIEWER_CONTEXT })
], UmbLogViewerPollingButtonElement.prototype, "_logViewerContext", null);
UmbLogViewerPollingButtonElement = __decorate([
    customElement('umb-log-viewer-polling-button')
], UmbLogViewerPollingButtonElement);
export { UmbLogViewerPollingButtonElement };
