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