import { Component, EventEmitter, Input, Output } from '@angular/core';
import { FormControl } from '@angular/forms';
import { SessionsService } from '@aztrix/sdk';
import { first, map, tap } from 'rxjs';
import * as i0 from "@angular/core";
import * as i1 from "@aztrix/sdk";
import * as i2 from "@angular/common";
import * as i3 from "../auth-form-header/auth-form-header.component";
import * as i4 from "../verification-form/verification-success-step/verification-success-step.component";
import * as i5 from "./otp-login-email-step/otp-login-email-step.component";
import * as i6 from "./otp-login-verification-step/otp-login-verification-step.component";
import * as i7 from "@aztrix/helpers";
export class OtpLoginFormComponent {
    constructor(_sessions) {
        this._sessions = _sessions;
        this.loginComplete = new EventEmitter();
        this.step = 0;
        this.verification = (code, verificationValue) => {
            return this._sessions.loginWithOtp({ login: verificationValue, otp: code }, 'response').pipe(first(), map((resp) => resp.headers.get('AuthToken')), tap({
                next: (authToken) => {
                    this.loginComplete.next(authToken);
                },
            }));
        };
        this.retryVerification = (verificationValue) => {
            return this._sessions.requestOtpLogin({ loginValue: verificationValue });
        };
    }
    continue() {
        this.step++;
    }
}
OtpLoginFormComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: OtpLoginFormComponent, deps: [{ token: i1.SessionsService }], target: i0.ɵɵFactoryTarget.Component });
OtpLoginFormComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: OtpLoginFormComponent, selector: "ax-otp-login-form", inputs: { form: "form" }, outputs: { loginComplete: "loginComplete" }, ngImport: i0, template: "<ax-auth-form-header\n  title=\"label.login\"\n  [subTexts]=\"['login.otp.explanation' | translate]\"\n></ax-auth-form-header>\n\n<div class=\"form\">\n  <ax-otp-login-email-step\n    *ngIf=\"step === 0\"\n    [form]=\"form\"\n    (continue)=\"continue()\"\n  ></ax-otp-login-email-step>\n  <ax-otp-login-verification-step\n    *ngIf=\"step === 1\"\n    [form]=\"form\"\n    [verification]=\"verification\"\n    [retryVerification]=\"retryVerification\"\n  ></ax-otp-login-verification-step>\n  <ax-verification-success-step *ngIf=\"step === 2\"></ax-verification-success-step>\n</div>\n", styles: ["", ":host{display:flex;flex-direction:column;gap:.5rem}.form{margin-bottom:20px;background-color:#fff;border-radius:15px;padding:1.5rem 1.5rem 0}.value{display:flex;flex-direction:column;align-items:flex-end;margin-bottom:.5rem}.input{width:100%}.action{margin:1rem 1rem -20px}.action ::ng-deep .ax-button{font-size:1.2rem;text-transform:none;height:2.5rem}.back{margin:1rem auto -.5rem;width:auto}.back ::ng-deep .ax-button{font-size:small;height:2rem;width:auto;margin:0 auto}.back ::ng-deep .ax-button .icon{width:1rem;height:1rem}.verification ::ng-deep .verify{width:100%;display:block;position:relative;bottom:-20px}.verification ::ng-deep .verify .ax-button{font-size:1.2rem;text-transform:none;height:2.5rem;width:100%}.verification ::ng-deep .resend{height:0;position:relative;bottom:-30px}.verification ::ng-deep .error-message{height:0;position:relative;bottom:-30px;display:flex;text-align:center;flex-direction:column;gap:1rem}\n"], dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.AuthFormHeaderComponent, selector: "ax-auth-form-header", inputs: ["title", "subTexts"] }, { kind: "component", type: i4.VerificationSuccessStepComponent, selector: "ax-verification-success-step", inputs: ["loading$"], outputs: ["continue"] }, { kind: "component", type: i5.OtpLoginEmailStepComponent, selector: "ax-otp-login-email-step" }, { kind: "component", type: i6.OtpLoginVerificationStepComponent, selector: "ax-otp-login-verification-step", inputs: ["verification", "retryVerification"] }, { kind: "pipe", type: i7.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: OtpLoginFormComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-otp-login-form', template: "<ax-auth-form-header\n  title=\"label.login\"\n  [subTexts]=\"['login.otp.explanation' | translate]\"\n></ax-auth-form-header>\n\n<div class=\"form\">\n  <ax-otp-login-email-step\n    *ngIf=\"step === 0\"\n    [form]=\"form\"\n    (continue)=\"continue()\"\n  ></ax-otp-login-email-step>\n  <ax-otp-login-verification-step\n    *ngIf=\"step === 1\"\n    [form]=\"form\"\n    [verification]=\"verification\"\n    [retryVerification]=\"retryVerification\"\n  ></ax-otp-login-verification-step>\n  <ax-verification-success-step *ngIf=\"step === 2\"></ax-verification-success-step>\n</div>\n", styles: [":host{display:flex;flex-direction:column;gap:.5rem}.form{margin-bottom:20px;background-color:#fff;border-radius:15px;padding:1.5rem 1.5rem 0}.value{display:flex;flex-direction:column;align-items:flex-end;margin-bottom:.5rem}.input{width:100%}.action{margin:1rem 1rem -20px}.action ::ng-deep .ax-button{font-size:1.2rem;text-transform:none;height:2.5rem}.back{margin:1rem auto -.5rem;width:auto}.back ::ng-deep .ax-button{font-size:small;height:2rem;width:auto;margin:0 auto}.back ::ng-deep .ax-button .icon{width:1rem;height:1rem}.verification ::ng-deep .verify{width:100%;display:block;position:relative;bottom:-20px}.verification ::ng-deep .verify .ax-button{font-size:1.2rem;text-transform:none;height:2.5rem;width:100%}.verification ::ng-deep .resend{height:0;position:relative;bottom:-30px}.verification ::ng-deep .error-message{height:0;position:relative;bottom:-30px;display:flex;text-align:center;flex-direction:column;gap:1rem}\n"] }]
        }], ctorParameters: function () { return [{ type: i1.SessionsService }]; }, propDecorators: { form: [{
                type: Input
            }], loginComplete: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 