import { __decorate } from "tslib";
import { property } from "lit/decorators.js";
import { RequestAuthorizationKind } from "@api-client/core/build/browser.js";
import BearerAuthorization from "../../authorization/ui/BearerAuthorization.js";
import * as InputCache from '../../../amf/lib/InputCache.js';
export default class AmfBearer extends BearerAuthorization {
    willUpdate(cp) {
        if (cp.has('security')) {
            this.restoreValues();
        }
        super.willUpdate(cp);
    }
    ensureConfig() {
        if (!this.authorization) {
            this.authorization = {
                enabled: true,
                kind: RequestAuthorizationKind,
                type: 'bearer',
                valid: false,
                config: {
                    token: '',
                },
            };
        }
        return this.authorization;
    }
    restoreValues() {
        const auth = this.ensureConfig();
        const { security } = this;
        if (!security) {
            return;
        }
        const restore = InputCache.get(this, security.id, true);
        if (!restore) {
            return;
        }
        auth.config = restore;
        this.requestUpdate();
    }
    handleToken(e) {
        super.handleToken(e);
        const { security } = this;
        if (!security) {
            return;
        }
        const auth = this.ensureConfig();
        InputCache.set(this, security.id, auth.config, true);
    }
}
__decorate([
    property({ type: Object })
], AmfBearer.prototype, "security", void 0);
//# sourceMappingURL=AmfBearer.js.map