import { html, nothing } from 'lit';
import { live } from 'lit/directives/live.js';
import { Authorization } from './Authorization.js';
import '../../../md/text-field/ui-filled-text-field.js';
export default class BearerAuthorization extends Authorization {
    get config() {
        const { authorization } = this;
        if (!authorization) {
            return { token: '' };
        }
        if (!authorization.config) {
            authorization.config = {};
        }
        return authorization.config;
    }
    checkValidity() {
        const { authorization } = this;
        if (!authorization) {
            return true;
        }
        const config = authorization.config;
        return !!config && !!config.token;
    }
    handleToken(e) {
        const { authorization } = this;
        if (!authorization) {
            return;
        }
        const input = e.target;
        const { value } = input;
        if (!authorization.config) {
            authorization.config = {};
        }
        ;
        authorization.config.token = value;
        this.notifyChange();
    }
    render() {
        return html ` ${this.renderHeader()} ${this.renderEditor()} `;
    }
    renderEditor() {
        const { authorization } = this;
        if (!authorization) {
            return nothing;
        }
        const config = authorization.config || {};
        return html `
      <form autocomplete="on" class="auth-form basic-auth">${this.renderToken(config)}</form>
      ${this.renderAuthInfo()}
    `;
    }
    renderToken(config) {
        return html `
      <div class="full-input">
        <ui-filled-text-field
          label="Token value"
          name="token"
          type="password"
          .value="${live(config.token || '')}"
          required
          invalidText="Token is required"
          ?disabled="${this.disabled}"
          ?readOnly="${this.readOnly}"
          @change="${this.handleToken}"
        ></ui-filled-text-field>
      </div>
    `;
    }
}
//# sourceMappingURL=BearerAuthorization.js.map