import { __esDecorate, __runInitializers } from "tslib";
import { Kind as RequestAuthorizationKind, } from '@api-client/core/models/RequestAuthorization.js';
import { property } from 'lit/decorators.js';
import OidcAuthorization from '../../authorization/ui/OidcAuthorization.js';
let AmfOidc = (() => {
    let _classSuper = OidcAuthorization;
    let _security_decorators;
    let _security_initializers = [];
    let _security_extraInitializers = [];
    return class AmfOidc 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: '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();
        }
        constructor() {
            super(...arguments);
            __runInitializers(this, _security_extraInitializers);
        }
    };
})();
export default AmfOidc;
//# sourceMappingURL=AmfOidc.js.map