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 { css, customElement, html, state } from '../../../../external/lit/index.js';
import { umbFocus } from '../../lit-element/index.js';
import { UmbModalBaseElement } from '../../modal/index.js';
import { UmbTextStyles } from '../../style/index.js';
let UmbAuthTimeoutModalElement = class UmbAuthTimeoutModalElement extends UmbModalBaseElement {
    constructor() {
        super(...arguments);
        this._remainingTimeInSeconds = 60;
    }
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
    #interval;
    connectedCallback() {
        super.connectedCallback();
        this.#startCountdown();
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (this.#interval) {
            clearInterval(this.#interval);
        }
    }
    #startCountdown() {
        this._remainingTimeInSeconds = this.data?.remainingTimeInSeconds ?? 60;
        this.#interval = setInterval(() => {
            if (this._remainingTimeInSeconds > 0) {
                this._remainingTimeInSeconds--;
            }
            else {
                clearInterval(this.#interval);
                // Timer expired — notify the controller so it can call timeOut() and
                // open the re-auth popup. Submit (not reject) so the catch block is
                // not triggered.
                this.data?.onExpired?.();
                this.modalContext?.submit();
            }
        }, 1000);
    }
    #handleLogout() {
        this.data?.onLogout?.();
        this.modalContext?.submit();
    }
    #handleConfirm() {
        this.data?.onContinue?.();
        this.modalContext?.submit();
    }
    render() {
        return html `
			<uui-dialog-layout class="uui-text" .headline=${this.localize.term('timeout_warningHeadline')}>
				<umb-localize key="timeout_warningText" .args=${[this._remainingTimeInSeconds]}>
					Your session is about to expire and you will be logged out in
					<strong>${this._remainingTimeInSeconds} seconds</strong>.
				</umb-localize>

				<uui-button
					slot="actions"
					look="secondary"
					label=${this.localize.term('timeout_warningLogoutAction')}
					@click=${this.#handleLogout}></uui-button>
				<uui-button
					slot="actions"
					id="confirm"
					color="positive"
					look="primary"
					label=${this.localize.term('timeout_warningContinueAction')}
					@click=${this.#handleConfirm}
					${umbFocus()}></uui-button>
			</uui-dialog-layout>
		`;
    }
    static { this.styles = [
        UmbTextStyles,
        css `
			uui-dialog-layout {
				max-inline-size: 60ch;
			}
		`,
    ]; }
};
__decorate([
    state()
], UmbAuthTimeoutModalElement.prototype, "_remainingTimeInSeconds", void 0);
UmbAuthTimeoutModalElement = __decorate([
    customElement('umb-auth-timeout-modal')
], UmbAuthTimeoutModalElement);
export { UmbAuthTimeoutModalElement };
export default UmbAuthTimeoutModalElement;
