<form id="two-factor-page" #form (ngSubmit)="submit()" [appApiAction]="formPromise">
  <header>
    <div class="left">
      <button type="button" routerLink="/login">{{ "back" | i18n }}</button>
    </div>
    <h1 class="center">
      <span class="title">{{ title }}</span>
    </h1>
    <div class="right">
      <button
        type="submit"
        [disabled]="form.loading"
        *ngIf="
          selectedProviderType != null &&
          selectedProviderType !== providerType.Duo &&
          selectedProviderType !== providerType.OrganizationDuo &&
          (selectedProviderType !== providerType.WebAuthn || form.loading)
        "
      >
        <span [hidden]="form.loading">{{ "continue" | i18n }}</span>
        <i class="bwi bwi-spinner bwi-lg bwi-spin" [hidden]="!form.loading" aria-hidden="true"></i>
      </button>
    </div>
  </header>
  <main tabindex="-1">
    <ng-container
      *ngIf="
        selectedProviderType === providerType.Authenticator ||
        selectedProviderType === providerType.Email
      "
    >
      <div class="content text-center">
        <span *ngIf="selectedProviderType === providerType.Authenticator">
          {{ "enterVerificationCodeApp" | i18n }}
        </span>
        <span *ngIf="selectedProviderType === providerType.Email">
          {{ "enterVerificationCodeEmail" | i18n : twoFactorEmail }}
        </span>
      </div>
      <div class="box first">
        <div class="box-content">
          <div class="box-content-row" appBoxRow>
            <label for="code">{{ "verificationCode" | i18n }}</label>
            <input
              id="code"
              type="text"
              name="Code"
              [(ngModel)]="token"
              required
              appAutofocus
              inputmode="tel"
              appInputVerbatim
            />
          </div>
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="remember">{{ "rememberMe" | i18n }}</label>
            <input id="remember" type="checkbox" name="Remember" [(ngModel)]="remember" />
          </div>
        </div>
      </div>
    </ng-container>
    <ng-container *ngIf="selectedProviderType === providerType.Yubikey">
      <div class="content text-center">
        <p class="text-center">{{ "insertYubiKey" | i18n }}</p>
        <img src="../../popup/images/yubikey.jpg" class="img-rounded img-responsive" alt="" />
      </div>
      <div class="box first">
        <div class="box-content">
          <div class="box-content-row" appBoxRow>
            <label for="code" class="sr-only">{{ "verificationCode" | i18n }}</label>
            <input
              id="code"
              type="password"
              name="Code"
              [(ngModel)]="token"
              required
              appAutofocus
              appInputVerbatim
            />
          </div>
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="remember">{{ "rememberMe" | i18n }}</label>
            <input id="remember" type="checkbox" name="Remember" [(ngModel)]="remember" />
          </div>
        </div>
      </div>
    </ng-container>
    <ng-container *ngIf="selectedProviderType === providerType.WebAuthn && !webAuthnNewTab">
      <div id="web-authn-frame">
        <iframe id="webauthn_iframe"></iframe>
      </div>
      <div class="box">
        <div class="box-content">
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="remember">{{ "rememberMe" | i18n }}</label>
            <input id="remember" type="checkbox" name="Remember" [(ngModel)]="remember" />
          </div>
        </div>
      </div>
    </ng-container>
    <ng-container *ngIf="selectedProviderType === providerType.WebAuthn && webAuthnNewTab">
      <div class="content text-center" *ngIf="webAuthnNewTab">
        <p class="text-center">{{ "webAuthnNewTab" | i18n }}</p>
        <button type="button" class="btn primary block" (click)="authWebAuthn()" appStopClick>
          {{ "webAuthnNewTabOpen" | i18n }}
        </button>
      </div>
    </ng-container>
    <ng-container
      *ngIf="
        selectedProviderType === providerType.Duo ||
        selectedProviderType === providerType.OrganizationDuo
      "
    >
      <div id="duo-frame"><iframe id="duo_iframe"></iframe></div>
      <div class="box">
        <div class="box-content">
          <div class="box-content-row box-content-row-checkbox" appBoxRow>
            <label for="remember">{{ "rememberMe" | i18n }}</label>
            <input id="remember" type="checkbox" name="Remember" [(ngModel)]="remember" />
          </div>
        </div>
      </div>
    </ng-container>
    <div class="box-content-row" [hidden]="!showCaptcha()">
      <iframe id="hcaptcha_iframe" height="80"></iframe>
    </div>
    <div class="content" *ngIf="selectedProviderType == null">
      <p class="text-center">{{ "noTwoStepProviders" | i18n }}</p>
      <p class="text-center">{{ "noTwoStepProviders2" | i18n }}</p>
    </div>
    <div class="content no-vpad" *ngIf="selectedProviderType != null">
      <p class="text-center">
        <button type="button" appStopClick (click)="anotherMethod()">
          {{ "useAnotherTwoStepMethod" | i18n }}
        </button>
      </p>
      <p *ngIf="selectedProviderType === providerType.Email" class="text-center">
        <button type="button" appStopClick (click)="sendEmail(true)" [appApiAction]="emailPromise">
          {{ "sendVerificationCodeEmailAgain" | i18n }}
        </button>
      </p>
    </div>
  </main>
</form>
