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 { UmbModalBaseElement } from '../../modal/index.js';
import { UMB_AUTH_CONTEXT } from '../auth.context.token.js';
import { customElement, html } from '../../../../external/lit/index.js';
import '../components/umb-auth-view.element.js';
let UmbAppAuthModalElement = class UmbAppAuthModalElement extends UmbModalBaseElement {
    #onSuccess = () => {
        this.value = { success: true };
        this._submitModal();
    };
    connectedCallback() {
        super.connectedCallback();
        // Close this modal when another tab restores the session via BroadcastChannel.
        this.consumeContext(UMB_AUTH_CONTEXT, (ctx) => {
            this.observe(ctx?.isAuthorized, (isAuthorized) => {
                if (isAuthorized)
                    this.#onSuccess();
            });
        });
    }
    render() {
        return html `<umb-auth-view
			.userLoginState=${this.data?.userLoginState ?? 'loggingIn'}
			.onSuccess=${this.#onSuccess}></umb-auth-view>`;
    }
};
UmbAppAuthModalElement = __decorate([
    customElement('umb-app-auth-modal')
], UmbAppAuthModalElement);
export { UmbAppAuthModalElement };
export default UmbAppAuthModalElement;
