import { Component } from '@angular/core';
import { UserService } from '@c8y/client';
import { Status } from '../common/status.model';
import { gettext } from '../i18n/gettext';
import { ModalService } from '../modal/modal.service';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { LoginService } from '../login/login.service';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/client";
import * as i2 from "../modal/modal.service";
import * as i3 from "ngx-bootstrap/modal";
import * as i4 from "../login/login.service";
import * as i5 from "../modal/modal.component";
import * as i6 from "../authentication/totp-challenge.component";
import * as i7 from "../authentication/totp-setup.component";
import * as i8 from "../i18n/c8y-translate.pipe";
export class UserTotpSetupComponent {
    constructor(user, modalService, modal, loginService) {
        this.user = user;
        this.modalService = modalService;
        this.modal = modal;
        this.loginService = loginService;
    }
    async totpSetupVerified() {
        await this.user.activateTotp();
        this.modal.hide();
        try {
            await this.modalService.acknowledge(gettext('Logout required'), gettext('You must log out in order to apply your changes'), Status.WARNING, gettext('Log out'));
            await this.loginService.logout();
        }
        catch (ex) {
            // intended empty
        }
    }
    close() {
        this.modal.hide();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UserTotpSetupComponent, deps: [{ token: i1.UserService }, { token: i2.ModalService }, { token: i3.BsModalRef }, { token: i4.LoginService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: UserTotpSetupComponent, selector: "c8y-user-totp-setup", ngImport: i0, template: "<c8y-modal\n  [title]=\"'Set up two-factor authentication' | translate\"\n  [headerClasses]=\"'dialog-header'\"\n  [customFooter]=\"true\"\n>\n  <ng-container c8y-modal-title>\n    <span class=\"dlt-c8y-icon-phonelink-lock\"></span>\n  </ng-container>\n\n  <c8y-totp-setup></c8y-totp-setup>\n  <c8y-totp-challenge [isModal]=\"true\" (onSuccess)=\"totpSetupVerified()\" (totpUnconfirmedEmitter)=\"close()\"></c8y-totp-challenge>\n</c8y-modal>\n", dependencies: [{ kind: "component", type: i5.ModalComponent, selector: "c8y-modal", inputs: ["disabled", "close", "dismiss", "title", "body", "customFooter", "headerClasses", "labels"], outputs: ["onDismiss", "onClose"] }, { kind: "component", type: i6.TotpChallengeComponent, selector: "c8y-totp-challenge", inputs: ["verify", "loading", "hasError", "isModal"], outputs: ["onSuccess", "totpUnconfirmedEmitter"] }, { kind: "component", type: i7.TotpSetupComponent, selector: "c8y-totp-setup" }, { kind: "pipe", type: i8.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UserTotpSetupComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-user-totp-setup', template: "<c8y-modal\n  [title]=\"'Set up two-factor authentication' | translate\"\n  [headerClasses]=\"'dialog-header'\"\n  [customFooter]=\"true\"\n>\n  <ng-container c8y-modal-title>\n    <span class=\"dlt-c8y-icon-phonelink-lock\"></span>\n  </ng-container>\n\n  <c8y-totp-setup></c8y-totp-setup>\n  <c8y-totp-challenge [isModal]=\"true\" (onSuccess)=\"totpSetupVerified()\" (totpUnconfirmedEmitter)=\"close()\"></c8y-totp-challenge>\n</c8y-modal>\n" }]
        }], ctorParameters: () => [{ type: i1.UserService }, { type: i2.ModalService }, { type: i3.BsModalRef }, { type: i4.LoginService }] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXNlci10b3RwLXNldHVwLmNvbXBvbmVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL2NvcmUvdXNlci91c2VyLXRvdHAtc2V0dXAuY29tcG9uZW50LnRzIiwiLi4vLi4vLi4vLi4vY29yZS91c2VyL3VzZXItdG90cC1zZXR1cC5jb21wb25lbnQuaHRtbCJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sZUFBZS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