import { Component } from '@angular/core' ; import { BehaviorSubject , Observable } from 'rxjs' ; import { map } from 'rxjs/operators' ; import { FormToastService } from '../../../../../../common/services/form-toast.service' ; import { SettingsTwoFactorV2Service , TwoFactorSetupPanel , } from '../../two-factor-v2.service' ; /**
 * Disable confirmation button for 2fa.
 **/ @ Component ( { selector : 'm-twoFactor__confirmDisable--totp' , template : `
    <span class="m-twoFactorDisable__text" i18n="@@2FA_PASSWORD__ARE_YOU_SURE"
      >Are you sure you want to disable two-factor authentication?</span
    >
    <input
      class="m-twoFactor__confirmDisableInput"
      type="text"
      [ngModel]="code$ | async"
      (ngModelChange)="codeValueChanged($event)"
      placeholder="Enter code"
    />
    <m-button
      [color]="'red'"
      (onAction)="disable()"
      [saving]="inProgress$ | async"
      [disabled]="disabled$ | async"
    >
      <ng-container i18n="disable 2fa|@@2FA_PASSWORD__DISABLE_APP_INTEGRATION">
        Disable app integration
      </ng-container>
    </m-button>
  ` , styleUrls : [ '../confirm-disable.component.ng.scss' ] , } ) export class SettingsTwoFactorDisableTOTPComponent { /**
     * Code for disable confirmation.
     */ public readonly code$ : BehaviorSubject < string > = new BehaviorSubject < string > ( '' ) ; returns { Observable < boolean > } get disabled$ ( ) : Observable < boolean > { return this . code$ . pipe ( map ( ( code ) => { return code . length !== 6 ; } ) ) ; } returns { BehaviorSubject < boolean > } get inProgress$ ( ) : BehaviorSubject < boolean > { return this . service . inProgress$ ; } returns { BehaviorSubject < TwoFactorSetupPanel > } get activePanel$ ( ) : BehaviorSubject < TwoFactorSetupPanel > { return this . service . activePanel$ ; } constructor ( private service , private toast ) { } returns { void } public disable ( ) { try { this . service . removeTotp ( this . code$ . getValue ( ) ) ; } catch ( e ) { this . toast . error ( 'Sorry, an unknown error has occurred disabling 2FA.' ) ; } } param { string } $event returns { void } public codeValueChanged ( $event ) { this . code$ . next ( $event ) ; } }