import { UmbContextBase } from '../../../libs/class-api/index.js';
import { UmbContextToken } from '../../../libs/context-api/index.js';
import { UmbBooleanState } from '../../../libs/observable-api/index.js';
import { Subject } from '../../../external/rxjs/index.js';
export const UMB_AUTH_SIGNALER_CONTEXT = new UmbContextToken('UmbAuthSignalerContext');
/**
 * A lightweight bridge context owned by {@link UmbApiInterceptorController} (resources package)
 * and consumed by the auth package. Allows resource-layer concerns (e.g. HTTP interceptors) to
 * signal authentication state without creating a circular dependency on the auth package.
 */
export class UmbAuthSignalerContext extends UmbContextBase {
    #isAuthorized;
    #timeoutRequest;
    constructor(host) {
        super(host, UMB_AUTH_SIGNALER_CONTEXT);
        this.#isAuthorized = new UmbBooleanState(false);
        this.isAuthorized = this.#isAuthorized.asObservable();
        this.#timeoutRequest = new Subject();
        /** Emits when an HTTP interceptor detects a 401 and needs the auth layer to show the login UI. */
        this.timeoutRequest = this.#timeoutRequest.asObservable();
    }
    /** Called by the auth context to keep authorization state in sync. */
    setAuthorized(value) {
        this.#isAuthorized.setValue(value);
    }
    /** Called by HTTP interceptors when a 401 response is received. */
    requestTimeout() {
        this.#timeoutRequest.next();
    }
}
