import { __esDecorate, __runInitializers } from "tslib";
import { property } from 'lit/decorators.js';
import { Kind as RequestAuthorizationKind, } from '@api-client/core/models/RequestAuthorization.js';
import BearerAuthorization from '../../authorization/ui/BearerAuthorization.js';
import * as InputCache from '../../../amf/lib/InputCache.js';
let AmfBearer = (() => {
    let _classSuper = BearerAuthorization;
    let _security_decorators;
    let _security_initializers = [];
    let _security_extraInitializers = [];
    return class AmfBearer extends _classSuper {
        static {
            const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
            _security_decorators = [property({ type: Object })];
            __esDecorate(this, null, _security_decorators, { kind: "accessor", name: "security", static: false, private: false, access: { has: obj => "security" in obj, get: obj => obj.security, set: (obj, value) => { obj.security = value; } }, metadata: _metadata }, _security_initializers, _security_extraInitializers);
            if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
        }
        #security_accessor_storage = __runInitializers(this, _security_initializers, void 0);
        /**
         * The in-memory key where the values are stored.
         */
        get security() { return this.#security_accessor_storage; }
        set security(value) { this.#security_accessor_storage = value; }
        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);
        }
        constructor() {
            super(...arguments);
            __runInitializers(this, _security_extraInitializers);
        }
    };
})();
export default AmfBearer;
//# sourceMappingURL=AmfBearer.js.map