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 '../workspace/logviewer-workspace.context-token.js';
import { UmbTextStyles } from '../../core/style/index.js';
import { css, html, customElement, property, state } from '../../../external/lit/index.js';
import { UmbLitElement } from '../../core/lit-element/index.js';
import { query as getQuery, path, toQueryString } from '../../core/router/index.js';
import { consumeContext } from '../../../libs/context-api/index.js';
let UmbLogViewerDateRangeSelectorElement = class UmbLogViewerDateRangeSelectorElement extends UmbLitElement {
    constructor() {
        super(...arguments);
        this._startDate = '';
        this._endDate = '';
        this.horizontal = false;
    }
    #logViewerContext;
    set _logViewerContext(value) {
        this.#logViewerContext = value;
        this.#observeStuff();
    }
    get _logViewerContext() {
        return this.#logViewerContext;
    }
    #observeStuff() {
        this.observe(this._logViewerContext?.dateRange, (dateRange) => {
            this._startDate = dateRange?.startDate ?? '';
            this._endDate = dateRange?.endDate ?? '';
        }, '_observeDateRange');
    }
    #setStartDate(e) {
        this._startDate = e.target.value;
        this.#updateFiltered();
    }
    #setEndDate(e) {
        this._endDate = e.target.value;
        this.#updateFiltered();
    }
    #updateFiltered() {
        this._logViewerContext?.setDateRange({ startDate: this._startDate, endDate: this._endDate });
        const query = getQuery();
        const qs = toQueryString({
            ...query,
            startDate: this._startDate,
            endDate: this._endDate,
        });
        window.history.pushState({}, '', `${path()}?${qs}`);
    }
    render() {
        return html `
			<div class="input-container">
				<uui-label for="start-date"><umb-localize key="logViewer_from">From</umb-localize>:</uui-label>
				<umb-input-date
					@change=${this.#setStartDate}
					id="start-date"
					type="date"
					label=${this.localize.term('logViewer_from')}
					.max=${this._logViewerContext?.today ?? ''}
					.value=${this._startDate}></umb-input-date>
			</div>
			<div class="input-container">
				<uui-label for="end-date"><umb-localize key="logViewer_to">To</umb-localize>: </uui-label>
				<umb-input-date
					@change=${this.#setEndDate}
					id="end-date"
					type="date"
					label=${this.localize.term('logViewer_to')}
					.min=${this._startDate}
					.max=${this._logViewerContext?.today ?? ''}
					.value=${this._endDate}></umb-input-date>
			</div>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			:host {
				display: flex;
				flex-direction: column;
				gap: var(--uui-size-space-3);
			}
			umb-input-date {
				width: 100%;
			}

			:host([horizontal]) .input-container {
				display: flex;
				align-items: center;
				gap: var(--uui-size-space-3);
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbLogViewerDateRangeSelectorElement.prototype, "_startDate", void 0);
__decorate([
    state()
], UmbLogViewerDateRangeSelectorElement.prototype, "_endDate", void 0);
__decorate([
    property({ type: Boolean, reflect: true })
], UmbLogViewerDateRangeSelectorElement.prototype, "horizontal", void 0);
__decorate([
    consumeContext({ context: UMB_APP_LOG_VIEWER_CONTEXT })
], UmbLogViewerDateRangeSelectorElement.prototype, "_logViewerContext", null);
UmbLogViewerDateRangeSelectorElement = __decorate([
    customElement('umb-log-viewer-date-range-selector')
], UmbLogViewerDateRangeSelectorElement);
export { UmbLogViewerDateRangeSelectorElement };
