import { __decorate } from "tslib";
/* eslint-disable class-methods-use-this */
import { OidcAuthorization, EventTypes as CoreEventTypes } from '@api-client/core/build/browser.js';
import { property } from 'lit/decorators.js';
import ApiElement from '../ApiElement.js';
export const authorizeHandler = Symbol('authorizeHandler');
export default class OidcAuthorize extends ApiElement {
    constructor() {
        super();
        this[authorizeHandler] = this[authorizeHandler].bind(this);
    }
    connectedCallback() {
        super.connectedCallback();
        this.eventsTarget.addEventListener(CoreEventTypes.Authorization.Oidc.authorize, this[authorizeHandler]);
        this.setAttribute('aria-hidden', 'true');
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.eventsTarget.removeEventListener(CoreEventTypes.Authorization.Oidc.authorize, this[authorizeHandler]);
    }
    [authorizeHandler](event) {
        const e = event;
        const config = { ...e.detail };
        e.detail.result = this.authorize(config);
    }
    /**
     * Authorize the user using provided settings.
     * This is left for compatibility. Use the `OAuth2Authorization` instead.
     *
     * @param settings The authorization configuration.
     */
    async authorize(settings) {
        const { tokenProxy, tokenProxyEncode } = this;
        const options = {};
        if (tokenProxy && typeof tokenProxy === 'string') {
            options.tokenProxy = tokenProxy;
        }
        if (tokenProxy && tokenProxyEncode && typeof tokenProxyEncode === 'boolean') {
            options.tokenProxyEncode = tokenProxyEncode;
        }
        const auth = new OidcAuthorization(settings, options);
        auth.checkConfig();
        // FIXME: Fix the typings in the `OidcAuthorization` class.
        return auth.authorize();
    }
}
__decorate([
    property({ type: String })
], OidcAuthorize.prototype, "tokenProxy", void 0);
__decorate([
    property({ type: String })
], OidcAuthorize.prototype, "tokenProxyEncode", void 0);
//# sourceMappingURL=OidcAuthorize.js.map