import { Component, Input, Output, EventEmitter } from '@angular/core';
import { UserService } from '@c8y/client';
import { AlertService } from '../alert/alert.service';
import { gettext } from '../i18n/gettext';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/client";
import * as i2 from "../alert/alert.service";
import * as i3 from "../common/icon.directive";
import * as i4 from "../i18n/c8y-translate.directive";
import * as i5 from "ngx-bootstrap/popover";
import * as i6 from "../i18n/c8y-translate.pipe";
export class UserTotpRevokeComponent {
    constructor(users, alert) {
        this.users = users;
        this.alert = alert;
        this.revokeEmitter = new EventEmitter();
    }
    async revoke() {
        try {
            await this.users.totpRevokeSecret(this.user);
            this.alert.success(gettext('User TOTP secret revoked.'));
            this.revokeEmitter.next();
        }
        catch (e) {
            this.alert.addServerFailure(e);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: UserTotpRevokeComponent, deps: [{ token: i1.UserService }, { token: i2.AlertService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: UserTotpRevokeComponent, selector: "c8y-user-totp-revoke", inputs: { user: "user" }, outputs: { revokeEmitter: "revoke" }, ngImport: i0, template: "<button\n  class=\"btn btn-default\"\n  type=\"button\"\n  [popoverTitle]=\"'Revoke TOTP secret' | translate\"\n  [popover]=\"confirm\"\n  #popover=\"bs-popover\"\n  placement=\"bottom\"\n>\n  <i c8yIcon=\"key\"></i>\n  {{ 'Revoke TOTP secret' | translate }}\n</button>\n\n<ng-template #confirm>\n  <p class=\"m-b-16\" translate>\n    This action will revoke the user's stored TOTP secret which will require a new setup.\n  </p>\n  <button\n    class=\"btn btn-default\"\n    type=\"button\"\n    title=\"{{ 'Cancel' | translate }}\"\n    (click)=\"popover.hide()\"\n    translate\n  >\n    Cancel\n  </button>\n  <button\n    class=\"btn btn-danger\"\n    type=\"button\"\n    title=\"{{ 'Revoke' | translate }}\"\n    (click)=\"revoke(); popover.hide()\"\n    translate\n  >\n    Revoke\n  </button>\n</ng-template>\n", dependencies: [{ kind: "directive", type: i3.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i4.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i5.PopoverDirective, selector: "[popover]", inputs: ["adaptivePosition", "boundariesElement", "popover", "popoverContext", "popoverTitle", "placement", "outsideClick", "triggers", "container", "containerClass", "isOpen", "delay"], outputs: ["onShown", "onHidden"], exportAs: ["bs-popover"] }, { kind: "pipe", type: i6.C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: UserTotpRevokeComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-user-totp-revoke', template: "<button\n  class=\"btn btn-default\"\n  type=\"button\"\n  [popoverTitle]=\"'Revoke TOTP secret' | translate\"\n  [popover]=\"confirm\"\n  #popover=\"bs-popover\"\n  placement=\"bottom\"\n>\n  <i c8yIcon=\"key\"></i>\n  {{ 'Revoke TOTP secret' | translate }}\n</button>\n\n<ng-template #confirm>\n  <p class=\"m-b-16\" translate>\n    This action will revoke the user's stored TOTP secret which will require a new setup.\n  </p>\n  <button\n    class=\"btn btn-default\"\n    type=\"button\"\n    title=\"{{ 'Cancel' | translate }}\"\n    (click)=\"popover.hide()\"\n    translate\n  >\n    Cancel\n  </button>\n  <button\n    class=\"btn btn-danger\"\n    type=\"button\"\n    title=\"{{ 'Revoke' | translate }}\"\n    (click)=\"revoke(); popover.hide()\"\n    translate\n  >\n    Revoke\n  </button>\n</ng-template>\n" }]
        }], ctorParameters: () => [{ type: i1.UserService }, { type: i2.AlertService }], propDecorators: { user: [{
                type: Input
            }], revokeEmitter: [{
                type: Output,
                args: ['revoke']
            }] } });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidXNlci10b3RwLXJldm9rZS5jb21wb25lbnQ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