import { Component, EventEmitter, Output } from '@angular/core';
import { MatomoService, RegisterStepsCompletedType } from '@aztrix/helpers';
import { SessionsService } from '@aztrix/sdk';
import { BehaviorSubject, first, map } from 'rxjs';
import { ModeService } from '../services/mode.service';
import * as i0 from "@angular/core";
import * as i1 from "../services/mode.service";
import * as i2 from "@aztrix/helpers";
import * as i3 from "@aztrix/sdk";
import * as i4 from "@angular/common";
import * as i5 from "../auth-form-header/auth-form-header.component";
import * as i6 from "./verification-step/verification-step.component";
import * as i7 from "./verification-success-step/verification-success-step.component";
export class VerificationFormComponent {
    constructor(_mode, _matomo, _sessions) {
        this._mode = _mode;
        this._matomo = _matomo;
        this._sessions = _sessions;
        this.loginComplete = new EventEmitter();
        this.registerComplete = new EventEmitter();
        this.step = 0;
        this.loading$ = new BehaviorSubject(false);
    }
    ngOnInit() {
        this._matomo.trackEvent('register', RegisterStepsCompletedType.VERIFICATION);
    }
    verificationCompleted(verificationValue) {
        this.verificationValue = verificationValue;
        this._mode.setMode('verification', {
            username: verificationValue,
        });
        this.step = 1;
        this._matomo.trackEvent('register', RegisterStepsCompletedType.SUCCESS);
        this.registerComplete.emit();
    }
    continue() {
        this.loading$.next(true);
        if (this._mode.password) {
            this._sessions
                .login({ login: this.verificationValue, password: this._mode.password }, 'response')
                .pipe(first(), map((resp) => resp.headers.get('AuthToken')))
                .subscribe({
                next: (authToken) => {
                    this._mode.mode$.next('login');
                    this.loginComplete.emit(authToken);
                },
                error: () => {
                    this._mode.setMode('login', { verificationValue: this.verificationValue });
                },
            });
        }
        else {
            this._mode.setMode('login', { verificationValue: this.verificationValue });
        }
    }
}
VerificationFormComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: VerificationFormComponent, deps: [{ token: i1.ModeService }, { token: i2.MatomoService }, { token: i3.SessionsService }], target: i0.ɵɵFactoryTarget.Component });
VerificationFormComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.1.5", type: VerificationFormComponent, selector: "ax-verification-form", outputs: { loginComplete: "loginComplete", registerComplete: "registerComplete" }, ngImport: i0, template: "<ax-auth-form-header\n  title=\"label.verification\"\n  [subTexts]=\"['register.individual.pending.title' | translate]\"\n></ax-auth-form-header>\n\n<div class=\"register-form form\" [ngSwitch]=\"step\">\n  <ax-verification-step\n    *ngSwitchCase=\"0\"\n    [form]=\"form\"\n    (completed)=\"verificationCompleted($event)\"\n  ></ax-verification-step>\n  <ax-verification-success-step\n    *ngSwitchCase=\"1\"\n    [form]=\"form\"\n    [loading$]=\"loading$\"\n    (continue)=\"continue()\"\n  ></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: i4.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i4.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "component", type: i5.AuthFormHeaderComponent, selector: "ax-auth-form-header", inputs: ["title", "subTexts"] }, { kind: "component", type: i6.VerificationStepComponent, selector: "ax-verification-step", outputs: ["completed"] }, { kind: "component", type: i7.VerificationSuccessStepComponent, selector: "ax-verification-success-step", inputs: ["loading$"], outputs: ["continue"] }, { kind: "pipe", type: i2.TranslatePipe, name: "translate" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.1.5", ngImport: i0, type: VerificationFormComponent, decorators: [{
            type: Component,
            args: [{ selector: 'ax-verification-form', template: "<ax-auth-form-header\n  title=\"label.verification\"\n  [subTexts]=\"['register.individual.pending.title' | translate]\"\n></ax-auth-form-header>\n\n<div class=\"register-form form\" [ngSwitch]=\"step\">\n  <ax-verification-step\n    *ngSwitchCase=\"0\"\n    [form]=\"form\"\n    (completed)=\"verificationCompleted($event)\"\n  ></ax-verification-step>\n  <ax-verification-success-step\n    *ngSwitchCase=\"1\"\n    [form]=\"form\"\n    [loading$]=\"loading$\"\n    (continue)=\"continue()\"\n  ></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.ModeService }, { type: i2.MatomoService }, { type: i3.SessionsService }]; }, propDecorators: { loginComplete: [{
                type: Output
            }], registerComplete: [{
                type: Output
            }] } });
//# sourceMappingURL=data:application/json;base64, 