import { Component } from '@angular/core';
import { UserFormComponent } from './user-form.component';
import { UserTypeEnum } from './user-type.enum';
import * as i0 from "@angular/core";
import * as i1 from "./user.service";
import * as i2 from "@angular/router";
import * as i3 from "../core";
import * as i4 from "@angular/material/dialog";
import * as i5 from "./current-user.service";
import * as i6 from "@angular/common";
import * as i7 from "@angular/material/button";
import * as i8 from "@angular/material/icon";
import * as i9 from "../login-history-for-user/login-history-for-user.component";
import * as i10 from "../audit-log/audit-log-list/audit-log-list.component";
import * as i11 from "@angular/material/tabs";
import * as i12 from "../user-clients-list/user-clients-list.component";
import * as i13 from "./user-sessions/user-sessions/user-sessions.component";
/**
 * Controller used to view a single user
 *
 * @author Floyd Kissoon
 * @since 20210701
 */
export class UserViewComponent {
    constructor(userService, route, config, http, dialog, currentUserService) {
        this.userService = userService;
        this.route = route;
        this.config = config;
        this.http = http;
        this.dialog = dialog;
        this.currentUserService = currentUserService;
        this.UserTypeEnum = UserTypeEnum;
        this.currentUser = this.currentUserService.getUser();
    }
    ngOnInit() {
        this.route.params.subscribe(params => {
            if (params.id !== undefined) {
                this.loadUser(params.id);
            }
        });
    }
    loadUser(userId) {
        this.userService.getUser(userId).then((result) => {
            this.user = result.item;
        });
    }
    enableOrDisableUser(action) {
        this.http.patch('api/users/' + this.user.id + '/' + action, this.user).toPromise().then((res) => {
            this.user.user_client = res.item.user_client;
        });
    }
    editUser(user) {
        const dialogRef = this.dialog.open(UserFormComponent, {
            width: '700px',
            data: user,
            autoFocus: false,
            restoreFocus: false
        });
        dialogRef.afterClosed().subscribe(async (result) => {
            if (result) {
                this.loadUser(this.user.id);
            }
        });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UserViewComponent, deps: [{ token: i1.UserService }, { token: i2.ActivatedRoute }, { token: i3.ConfigService }, { token: i3.HttpService }, { token: i4.MatDialog }, { token: i5.CurrentUserService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: UserViewComponent, selector: "user-view", ngImport: i0, template: "<div class=\"mat-typography m-4\" *ngIf=\"user\">\n  <h1 class=\"text-center\">{{user.name}}</h1>\n\n  <div class=\"border\">\n    <mat-tab-group>\n      <mat-tab label=\"Basic Information\">\n        <ng-template matTabContent>\n          <div class=\"row m-4\">\n            <div class=\"col-4\">\n              <div class=\"bordered-section\">\n                <div class=\"row\" *ngIf=\"currentUser?.user_type_id != 3\">\n                  <button type=\"button\" mat-icon-button (click)=\"editUser(user)\">\n                    <mat-icon>edit</mat-icon>\n                  </button>\n                  <button mat-stroked-button color=\"warn\" *ngIf=\"!user.user_client?.is_enabled\"\n                    (click)=\"enableOrDisableUser('enable')\">\n                    Enable\n                  </button>\n                  <button mat-stroked-button color=\"primary\" *ngIf=\"user.user_client?.is_enabled\"\n                    (click)=\"enableOrDisableUser('disable')\">Disable</button>\n                </div>\n\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Name:</label>\n                  <div class=\"col-sm-8\">{{user?.name}}</div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Email:</label>\n                  <div class=\"col-sm-8\">{{user?.email}}</div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Type:</label>\n                  <div class=\"col-sm-8\">{{user?.type?.title}}</div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Status:</label>\n                  <div class=\"col-sm-8\">{{user?.user_client?.is_enabled ? 'Enabled' : 'Disabled' }}\n                  </div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Role:</label>\n                  <div class=\"col-sm-8\">\n                    <span *ngFor=\"let role of user?.roles\">\n                      <button class=\"btn btn-outline-dark btn-xs mb-2\">{{role?.label}}</button>\n                      &nbsp;\n                    </span>\n                  </div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Signature:</label>\n                  <div class=\"col-sm-8\">\n                    <span *ngIf=\"user?.signature\">\n                      <img src=\"{{user?.signature_url}}\" alt=\"\" width=\"250px\" />\n                    </span>\n                    <span *ngIf=\"!user?.signature\">\n                      No Signature Added\n                    </span>\n\n                  </div>\n                </div>\n              </div>\n            </div>\n          </div>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Login History\">\n        <ng-template matTabContent>\n          <app-login-history-for-user [userId]=\"user?.id\"></app-login-history-for-user>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Activity Logs\">\n        <ng-template matTabContent>\n          <app-audit-log-list objectType=\"User\" [objectId]=\"user?.id\" [showExportButtons]=\"false\">\n          </app-audit-log-list>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Tenants\" *ngIf=\"currentUser?.user_type_id === UserTypeEnum.ADMIN\">\n        <ng-template matTabContent>\n          <app-user-clients-list [user]=\"user\"></app-user-clients-list>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Sessions\">\n        <ng-template matTabContent>\n          <app-user-sessions [user]=\"user\"></app-user-sessions>\n        </ng-template>\n      </mat-tab>\n    </mat-tab-group>\n  </div>\n\n</div>\n", styles: [".user-node .page-title{margin:20px 0 0}.user-node #information-tabs-wrapper .nav-pills .nav-link{border-radius:0;border:1px solid #007bff;border-right:none;width:190px}.user-node #information-tabs-wrapper .tab-content{padding:20px;border:1px solid #007bff;width:calc(100vw - 200px)}\n"], dependencies: [{ kind: "directive", type: i6.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i7.MatButton, selector: "    button[mat-button], button[mat-raised-button], button[mat-flat-button],    button[mat-stroked-button]  ", exportAs: ["matButton"] }, { kind: "component", type: i7.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "component", type: i8.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i9.LoginHistoryForUserComponent, selector: "app-login-history-for-user", inputs: ["userId"] }, { kind: "component", type: i10.AuditLogListComponent, selector: "app-audit-log-list", inputs: ["objectId", "objectType", "showFilter", "showExportButtons", "userId", "disableFilterPatchingFromUrl", "scrollContainer"] }, { kind: "directive", type: i11.MatTabContent, selector: "[matTabContent]" }, { kind: "component", type: i11.MatTab, selector: "mat-tab", inputs: ["disabled", "label", "aria-label", "aria-labelledby", "labelClass", "bodyClass"], exportAs: ["matTab"] }, { kind: "component", type: i11.MatTabGroup, selector: "mat-tab-group", inputs: ["color", "fitInkBarToContent", "mat-stretch-tabs", "dynamicHeight", "selectedIndex", "headerPosition", "animationDuration", "contentTabIndex", "disablePagination", "disableRipple", "preserveContent", "backgroundColor", "aria-label", "aria-labelledby"], outputs: ["selectedIndexChange", "focusChange", "animationDone", "selectedTabChange"], exportAs: ["matTabGroup"] }, { kind: "component", type: i12.UserClientsListComponent, selector: "app-user-clients-list", inputs: ["user"] }, { kind: "component", type: i13.UserSessionsComponent, selector: "app-user-sessions", inputs: ["user"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: UserViewComponent, decorators: [{
            type: Component,
            args: [{ selector: 'user-view', template: "<div class=\"mat-typography m-4\" *ngIf=\"user\">\n  <h1 class=\"text-center\">{{user.name}}</h1>\n\n  <div class=\"border\">\n    <mat-tab-group>\n      <mat-tab label=\"Basic Information\">\n        <ng-template matTabContent>\n          <div class=\"row m-4\">\n            <div class=\"col-4\">\n              <div class=\"bordered-section\">\n                <div class=\"row\" *ngIf=\"currentUser?.user_type_id != 3\">\n                  <button type=\"button\" mat-icon-button (click)=\"editUser(user)\">\n                    <mat-icon>edit</mat-icon>\n                  </button>\n                  <button mat-stroked-button color=\"warn\" *ngIf=\"!user.user_client?.is_enabled\"\n                    (click)=\"enableOrDisableUser('enable')\">\n                    Enable\n                  </button>\n                  <button mat-stroked-button color=\"primary\" *ngIf=\"user.user_client?.is_enabled\"\n                    (click)=\"enableOrDisableUser('disable')\">Disable</button>\n                </div>\n\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Name:</label>\n                  <div class=\"col-sm-8\">{{user?.name}}</div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Email:</label>\n                  <div class=\"col-sm-8\">{{user?.email}}</div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Type:</label>\n                  <div class=\"col-sm-8\">{{user?.type?.title}}</div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Status:</label>\n                  <div class=\"col-sm-8\">{{user?.user_client?.is_enabled ? 'Enabled' : 'Disabled' }}\n                  </div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Role:</label>\n                  <div class=\"col-sm-8\">\n                    <span *ngFor=\"let role of user?.roles\">\n                      <button class=\"btn btn-outline-dark btn-xs mb-2\">{{role?.label}}</button>\n                      &nbsp;\n                    </span>\n                  </div>\n                </div>\n                <div class=\"row\">\n                  <label class=\"col-sm-4 control-label\">Signature:</label>\n                  <div class=\"col-sm-8\">\n                    <span *ngIf=\"user?.signature\">\n                      <img src=\"{{user?.signature_url}}\" alt=\"\" width=\"250px\" />\n                    </span>\n                    <span *ngIf=\"!user?.signature\">\n                      No Signature Added\n                    </span>\n\n                  </div>\n                </div>\n              </div>\n            </div>\n          </div>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Login History\">\n        <ng-template matTabContent>\n          <app-login-history-for-user [userId]=\"user?.id\"></app-login-history-for-user>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Activity Logs\">\n        <ng-template matTabContent>\n          <app-audit-log-list objectType=\"User\" [objectId]=\"user?.id\" [showExportButtons]=\"false\">\n          </app-audit-log-list>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Tenants\" *ngIf=\"currentUser?.user_type_id === UserTypeEnum.ADMIN\">\n        <ng-template matTabContent>\n          <app-user-clients-list [user]=\"user\"></app-user-clients-list>\n        </ng-template>\n      </mat-tab>\n      <mat-tab label=\"Sessions\">\n        <ng-template matTabContent>\n          <app-user-sessions [user]=\"user\"></app-user-sessions>\n        </ng-template>\n      </mat-tab>\n    </mat-tab-group>\n  </div>\n\n</div>\n", styles: [".user-node .page-title{margin:20px 0 0}.user-node #information-tabs-wrapper .nav-pills .nav-link{border-radius:0;border:1px solid #007bff;border-right:none;width:190px}.user-node #information-tabs-wrapper .tab-content{padding:20px;border:1px solid #007bff;width:calc(100vw - 200px)}\n"] }]
        }], ctorParameters: () => [{ type: i1.UserService }, { type: i2.ActivatedRoute }, { type: i3.ConfigService }, { type: i3.HttpService }, { type: i4.MatDialog }, { type: i5.CurrentUserService }] });
//# sourceMappingURL=data:application/json;base64, 