import { Component, Input } from '@angular/core';
import { AppStateService, C8yTranslatePipe, CommonModule, TenantUiService, Permissions } from '@c8y/ngx-components';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components";
import * as i2 from "@angular/common";
export class SupportUserAccessComponent {
    constructor(tenantUiService, appState, permissions) {
        this.tenantUiService = tenantUiService;
        this.appState = appState;
        this.permissions = permissions;
    }
    async ngOnInit() {
        this.isTopTenant = await this.tenantUiService.isManagementTenant();
        this.setSupportUserLogin();
    }
    async setSupportUserLogin() {
        const currentUser = (await this.appState.currentUser).value;
        if (this.permissions.hasAnyRole([Permissions.ROLE_SUPPORT_ADMIN, Permissions.ROLE_SUPPORT_READ])) {
            this.supportUserLogin = encodeURIComponent(`${currentUser.id}$`);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SupportUserAccessComponent, deps: [{ token: i1.TenantUiService }, { token: i1.AppStateService }, { token: i1.Permissions }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: SupportUserAccessComponent, isStandalone: true, selector: "c8y-support-user-access", inputs: { tenant: "tenant" }, ngImport: i0, template: "<div class=\"card-header separator sticky-top large-padding\">\n  <div class=\"card-title fit-w\">\n    <i\n      class=\"c8y-icon c8y-icon-c8y-support\"\n      [ngClass]=\"{ 'c8y-icon-duocolor': tenant.supportUser?.enabled }\"\n    ></i>\n    {{ 'Support user access' | translate }}\n  </div>\n  <ng-container *ngIf=\"tenant.supportUser?.enabled && supportUserLogin && isTopTenant\">\n    <a\n      class=\"btn btn-default btn-xs\"\n      title=\"{{ 'Log in' | translate }}\"\n      href=\"//{{ tenant.domain }}/apps/administration/?user={{ supportUserLogin }}\"\n      target=\"_blank\"\n      rel=\"noopener noreferrer\"\n    >\n      <i c8yIcon=\"external-link\"></i>\n      {{ 'Log in' | translate }}\n    </a>\n  </ng-container>\n</div>\n<div class=\"card-block large-padding\">\n  <div class=\"form-group\">\n    <label>{{ 'Status' | translate }}</label>\n    <div>\n      <p class=\"form-control-static\">\n        <span\n          title=\"{{ 'Disabled' | translate }}\"\n          *ngIf=\"!tenant.supportUser?.enabled\"\n        >\n          <i\n            class=\"text-danger\"\n            c8yIcon=\"ban\"\n          ></i>\n          {{ 'Disabled' | translate }}\n        </span>\n        <span\n          title=\"{{ 'Enabled' | translate }}\"\n          *ngIf=\"tenant.supportUser?.enabled\"\n        >\n          <i\n            class=\"text-success\"\n            c8yIcon=\"check-circle\"\n          ></i>\n          {{ 'Enabled' | translate }}\n        </span>\n      </p>\n    </div>\n  </div>\n  <div class=\"form-group\" data-cy=\"c8y-support-user-access--activeRequestCount\">\n    <label>{{ 'Active requests count' | translate }}</label>\n\n    <p class=\"form-control-static\">\n      <span *ngIf=\"tenant.supportUser?.activeRequestCount\">\n        <span class=\"badge badge-danger\">\n          {{ tenant.supportUser?.activeRequestCount }}\n        </span>\n      </span>\n      <span *ngIf=\"!tenant.supportUser?.enabled && tenant.supportUser?.activeRequestCount === 0\">\n        {{ 'No active requests' | translate }}\n      </span>\n      <span *ngIf=\"tenant.supportUser?.enabled && tenant.supportUser?.activeRequestCount === 0\">\n        {{ 'Not applicable' | translate }}\n      </span>\n    </p>\n  </div>\n  <div\n    class=\"form-group\"\n    *ngIf=\"tenant.supportUser?.enabled\"\n  >\n    <label>{{ 'Expiry date' | translate }}</label>\n    <div>\n      <p class=\"form-control-static\">\n        <span *ngIf=\"tenant.supportUser?.expiryDate\">\n          {{ tenant.supportUser?.expiryDate | c8yDate: 'medium' }}\n        </span>\n        <span *ngIf=\"!tenant.supportUser?.expiryDate\">{{ 'No limit' | translate }}</span>\n      </p>\n    </div>\n  </div>\n</div>\n", dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: i1.C8yTranslatePipe, name: "translate" }, { kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "pipe", type: i1.DatePipe, name: "c8yDate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: SupportUserAccessComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-support-user-access', standalone: true, imports: [CommonModule, C8yTranslatePipe], template: "<div class=\"card-header separator sticky-top large-padding\">\n  <div class=\"card-title fit-w\">\n    <i\n      class=\"c8y-icon c8y-icon-c8y-support\"\n      [ngClass]=\"{ 'c8y-icon-duocolor': tenant.supportUser?.enabled }\"\n    ></i>\n    {{ 'Support user access' | translate }}\n  </div>\n  <ng-container *ngIf=\"tenant.supportUser?.enabled && supportUserLogin && isTopTenant\">\n    <a\n      class=\"btn btn-default btn-xs\"\n      title=\"{{ 'Log in' | translate }}\"\n      href=\"//{{ tenant.domain }}/apps/administration/?user={{ supportUserLogin }}\"\n      target=\"_blank\"\n      rel=\"noopener noreferrer\"\n    >\n      <i c8yIcon=\"external-link\"></i>\n      {{ 'Log in' | translate }}\n    </a>\n  </ng-container>\n</div>\n<div class=\"card-block large-padding\">\n  <div class=\"form-group\">\n    <label>{{ 'Status' | translate }}</label>\n    <div>\n      <p class=\"form-control-static\">\n        <span\n          title=\"{{ 'Disabled' | translate }}\"\n          *ngIf=\"!tenant.supportUser?.enabled\"\n        >\n          <i\n            class=\"text-danger\"\n            c8yIcon=\"ban\"\n          ></i>\n          {{ 'Disabled' | translate }}\n        </span>\n        <span\n          title=\"{{ 'Enabled' | translate }}\"\n          *ngIf=\"tenant.supportUser?.enabled\"\n        >\n          <i\n            class=\"text-success\"\n            c8yIcon=\"check-circle\"\n          ></i>\n          {{ 'Enabled' | translate }}\n        </span>\n      </p>\n    </div>\n  </div>\n  <div class=\"form-group\" data-cy=\"c8y-support-user-access--activeRequestCount\">\n    <label>{{ 'Active requests count' | translate }}</label>\n\n    <p class=\"form-control-static\">\n      <span *ngIf=\"tenant.supportUser?.activeRequestCount\">\n        <span class=\"badge badge-danger\">\n          {{ tenant.supportUser?.activeRequestCount }}\n        </span>\n      </span>\n      <span *ngIf=\"!tenant.supportUser?.enabled && tenant.supportUser?.activeRequestCount === 0\">\n        {{ 'No active requests' | translate }}\n      </span>\n      <span *ngIf=\"tenant.supportUser?.enabled && tenant.supportUser?.activeRequestCount === 0\">\n        {{ 'Not applicable' | translate }}\n      </span>\n    </p>\n  </div>\n  <div\n    class=\"form-group\"\n    *ngIf=\"tenant.supportUser?.enabled\"\n  >\n    <label>{{ 'Expiry date' | translate }}</label>\n    <div>\n      <p class=\"form-control-static\">\n        <span *ngIf=\"tenant.supportUser?.expiryDate\">\n          {{ tenant.supportUser?.expiryDate | c8yDate: 'medium' }}\n        </span>\n        <span *ngIf=\"!tenant.supportUser?.expiryDate\">{{ 'No limit' | translate }}</span>\n      </p>\n    </div>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.TenantUiService }, { type: i1.AppStateService }, { type: i1.Permissions }], propDecorators: { tenant: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 