import { __decorate } from "tslib";
import { RequestAuthorizationKind } from "@api-client/core/build/browser.js";
import { property } from "lit/decorators.js";
import OidcAuthorization from "../../authorization/ui/OidcAuthorization.js";
export default class AmfOidc extends OidcAuthorization {
    willUpdate(cp) {
        if (cp.has('security')) {
            this.restoreValues();
        }
        super.willUpdate(cp);
    }
    ensureConfig() {
        if (!this.authorization) {
            this.authorization = {
                enabled: true,
                kind: RequestAuthorizationKind,
                type: 'oauth 2',
                valid: false,
                config: {},
            };
        }
        return this.authorization;
    }
    restoreValues() {
        const { security } = this;
        this.authorization = undefined;
        const auth = this.ensureConfig();
        if (!security) {
            return;
        }
        const { scheme } = security;
        if (!scheme) {
            return;
        }
        const settings = scheme.settings;
        if (!settings) {
            return;
        }
        const { url } = settings;
        const cnf = auth.config;
        cnf.issuerUri = url;
        if (url) {
            this.discover();
        }
        auth.config = this.serialize();
        this.notifyChange();
    }
}
__decorate([
    property({ type: Object })
], AmfOidc.prototype, "security", void 0);
//# sourceMappingURL=AmfOidc.js.map