import { html, TemplateResult } from 'lit'
import { type IRequestAuthorization, RequestAuthorization } from '@api-client/core/models/RequestAuthorization.js'
import { reactive } from '../../../src/decorators/index.js'
import { DemoPage } from '../../../src/demo/DemoPage.js'
import BearerAuthorization from '../../../src/elements/authorization/ui/BearerAuthorization.js'
import '../../../src/define/authorization/bearer-authorization.js'

class ComponentDemoPage extends DemoPage {
  override accessor componentName = 'HTTP Bearer authorization'

  @reactive() accessor authorization: IRequestAuthorization

  constructor() {
    super()
    const auth = RequestAuthorization.fromTypedConfig('bearer', {}, false)
    this.authorization = auth.toJSON()
  }

  handleChange(e: Event): void {
    const input = e.target as BearerAuthorization
    console.log('Value changed', input.authorization)
  }

  handleDelete(): void {
    console.log('Requested to delete.')
  }

  contentTemplate(): TemplateResult {
    return html`
      <a href="./">Back</a>
      <section class="demo-section">
        <bearer-authorization
          .authorization="${this.authorization}"
          @change="${this.handleChange}"
          @delete="${this.handleDelete}"
        ></bearer-authorization>
      </section>
    `
  }
}

const instance = new ComponentDemoPage()
instance.render()
