import { DiagnosticsService } from './diagnostics.service';
import { ActivatedRoute } from '@angular/router';
import { Component } from '@angular/core';
import { BehaviorSubject, pipe } from 'rxjs';
import { map } from 'rxjs/operators';
import { operationStatusClasses, operationStatusIcons, OperationRealtimeService } from '@c8y/ngx-components';
import * as i0 from "@angular/core";
import * as i1 from "@angular/router";
import * as i2 from "./diagnostics.service";
import * as i3 from "@c8y/ngx-components";
import * as i4 from "@angular/common";
import * as i5 from "@c8y/ngx-components/repository/shared";
import * as i6 from "ngx-bootstrap/tooltip";
export class DiagnosticsComponent {
    constructor(route, diagnosticService, operationRealtime) {
        this.route = route;
        this.diagnosticService = diagnosticService;
        this.operationRealtime = operationRealtime;
        this.statusIcons = operationStatusIcons;
        this.statusClasses = operationStatusClasses;
        this.deviceId = this.route.snapshot.parent.data.contextData.id;
        this.device$ = new BehaviorSubject(this.route.snapshot.parent.data.contextData);
        this.operations$ = this.diagnosticService.getOperations$(this.device$);
        this.operationsPipe = pipe(map(ops => ops.filter(op => op[this.diagnosticService.fragment])));
        this.realtimeOptions = {
            entityOrId: this.deviceId,
            removeOnUpdate: true,
            insertOnUpdate: true
        };
    }
    onDiagnosticRequest() {
        this.diagnosticService.createOperation(this.deviceId);
    }
    onDelete(operation) {
        this.diagnosticService.deleteOperation(operation);
    }
    onCancel(operation) {
        this.diagnosticService.cancelOperation(operation);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DiagnosticsComponent, deps: [{ token: i1.ActivatedRoute }, { token: i2.DiagnosticsService }, { token: i3.OperationRealtimeService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: DiagnosticsComponent, selector: "c8y-diagnostics", ngImport: i0, template: "<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    type=\"button\"\n    title=\"{{ 'Request diagnostic file' | translate }}\"\n    (click)=\"onDiagnosticRequest()\"\n  >\n    <i c8yIcon=\"stethoscope\"></i>\n    <span translate>Request diagnostic file</span>\n  </button>\n</c8y-action-bar-item>\n\n<div\n  class=\"page-sticky-header hidden-xs c8y-list__item c8y-list--timeline\"\n  *ngIf=\"operationCount > 0\"\n>\n  <div class=\"d-flex\">\n    <div class=\"c8y-list--timeline__item__date a-s-center\">\n      <label>{{ 'Date' | translate }}</label>\n    </div>\n    <div class=\"c8y-list__item__block flex-grow\">\n      <div class=\"c8y-list__item__icon\">\n        <i class=\"p-l-24\"></i>\n      </div>\n      <div class=\"c8y-list__item__body\">\n        <div class=\"content-flex-40\">\n          <div class=\"col-4\">{{ 'Event' | translate }}</div>\n          <div class=\"col-5 m-l-8\">{{ 'File' | translate }}</div>\n        </div>\n      </div>\n    </div>\n  </div>\n</div>\n\n<c8y-list-group>\n  <ng-template\n    c8yFor\n    let-operation\n    [c8yForOf]=\"operations$\"\n    [c8yForPipe]=\"operationsPipe\"\n    [c8yForRealtime]=\"operationRealtime\"\n    [c8yForRealtimeOptions]=\"realtimeOptions\"\n    (c8yForCount)=\"operationCount = $event\"\n  >\n    <c8y-li-timeline>\n      {{ operation.creationTime | c8yDate }}\n      <c8y-li>\n        <c8y-li-icon>\n          <i\n            [c8yIcon]=\"statusIcons[operation.status]\"\n            [ngClass]=\"statusClasses[operation.status]\"\n            [tooltip]=\"operation.status?.toString() | translate\"\n          ></i>\n        </c8y-li-icon>\n        <c8y-li-body class=\"content-flex-40\">\n          <div class=\"col-4\">\n            <p class=\"text-truncate-wrap\" title=\"{{ operation.description | translate }}\">\n              {{ operation.description | translate }}\n            </p>\n          </div>\n          <div class=\"col-5\" *ngIf=\"operation.c8y_DiagnosticReport?.file\">\n            <div class=\"text-truncate-wrap m-t-xs-8\">\n              <span class=\"text-label-small visible-xs\" translate>File</span>\n              <span title=\"{{ operation.c8y_DiagnosticReport.file }}\">\n                <c8y-file-download\n                  url=\"{{ operation.c8y_DiagnosticReport.file }}\"\n                ></c8y-file-download>\n              </span>\n            </div>\n          </div>\n        </c8y-li-body>\n        <c8y-li-action\n          (click)=\"onCancel(operation)\"\n          *ngIf=\"operation.status === 'PENDING'\"\n          icon=\"times\"\n          label=\"{{ 'Cancel' | translate }}\"\n        ></c8y-li-action>\n        <c8y-li-action\n          (click)=\"onDelete(operation)\"\n          *ngIf=\"operation.status === 'SUCCESSFUL'\"\n          icon=\"delete\"\n          label=\"{{ 'Delete' | translate }}\"\n        ></c8y-li-action>\n      </c8y-li>\n    </c8y-li-timeline>\n  </ng-template>\n</c8y-list-group>\n\n<!-- EMPTY STATE -->\n\n<c8y-ui-empty-state\n  *ngIf=\"operationCount === 0\"\n  [icon]=\"'stethoscope'\"\n  [title]=\"'No diagnostic files available.' | translate\"\n></c8y-ui-empty-state>\n", dependencies: [{ kind: "component", type: i3.ActionBarItemComponent, selector: "c8y-action-bar-item", inputs: ["placement", "priority", "itemClass", "injector", "groupId", "inGroupPriority"] }, { kind: "component", type: i3.EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: i3.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i3.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i4.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i3.ForOfDirective, selector: "[c8yFor]", inputs: ["c8yForOf", "c8yForLoadMore", "c8yForPipe", "c8yForNotFound", "c8yForMaxIterations", "c8yForLoadingTemplate", "c8yForLoadNextLabel", "c8yForLoadingLabel", "c8yForRealtime", "c8yForRealtimeOptions", "c8yForComparator", "c8yForEnableVirtualScroll", "c8yForVirtualScrollElementSize", "c8yForVirtualScrollStrategy", "c8yForVirtualScrollContainerHeight"], outputs: ["c8yForCount", "c8yForChange", "c8yForLoadMoreComponent"] }, { kind: "component", type: i3.ListGroupComponent, selector: "c8y-list-group" }, { kind: "component", type: i3.ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: i3.ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "component", type: i3.ListItemBodyComponent, selector: "c8y-list-item-body, c8y-li-body", inputs: ["body"] }, { kind: "component", type: i3.ListItemActionComponent, selector: "c8y-list-item-action, c8y-li-action", inputs: ["label", "icon", "disabled"], outputs: ["click"] }, { kind: "component", type: i3.ListItemTimelineComponent, selector: "c8y-list-item-timeline, c8y-li-timeline" }, { kind: "component", type: i5.FileDownloadComponent, selector: "c8y-file-download", inputs: ["url"] }, { kind: "directive", type: i6.TooltipDirective, selector: "[tooltip], [tooltipHtml]", inputs: ["adaptivePosition", "tooltip", "placement", "triggers", "container", "containerClass", "boundariesElement", "isOpen", "isDisabled", "delay", "tooltipHtml", "tooltipPlacement", "tooltipIsOpen", "tooltipEnable", "tooltipAppendToBody", "tooltipAnimation", "tooltipClass", "tooltipContext", "tooltipPopupDelay", "tooltipFadeDuration", "tooltipTrigger"], outputs: ["tooltipChange", "onShown", "onHidden", "tooltipStateChanged"], exportAs: ["bs-tooltip"] }, { kind: "pipe", type: i3.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i3.DatePipe, name: "c8yDate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: DiagnosticsComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-diagnostics', template: "<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    type=\"button\"\n    title=\"{{ 'Request diagnostic file' | translate }}\"\n    (click)=\"onDiagnosticRequest()\"\n  >\n    <i c8yIcon=\"stethoscope\"></i>\n    <span translate>Request diagnostic file</span>\n  </button>\n</c8y-action-bar-item>\n\n<div\n  class=\"page-sticky-header hidden-xs c8y-list__item c8y-list--timeline\"\n  *ngIf=\"operationCount > 0\"\n>\n  <div class=\"d-flex\">\n    <div class=\"c8y-list--timeline__item__date a-s-center\">\n      <label>{{ 'Date' | translate }}</label>\n    </div>\n    <div class=\"c8y-list__item__block flex-grow\">\n      <div class=\"c8y-list__item__icon\">\n        <i class=\"p-l-24\"></i>\n      </div>\n      <div class=\"c8y-list__item__body\">\n        <div class=\"content-flex-40\">\n          <div class=\"col-4\">{{ 'Event' | translate }}</div>\n          <div class=\"col-5 m-l-8\">{{ 'File' | translate }}</div>\n        </div>\n      </div>\n    </div>\n  </div>\n</div>\n\n<c8y-list-group>\n  <ng-template\n    c8yFor\n    let-operation\n    [c8yForOf]=\"operations$\"\n    [c8yForPipe]=\"operationsPipe\"\n    [c8yForRealtime]=\"operationRealtime\"\n    [c8yForRealtimeOptions]=\"realtimeOptions\"\n    (c8yForCount)=\"operationCount = $event\"\n  >\n    <c8y-li-timeline>\n      {{ operation.creationTime | c8yDate }}\n      <c8y-li>\n        <c8y-li-icon>\n          <i\n            [c8yIcon]=\"statusIcons[operation.status]\"\n            [ngClass]=\"statusClasses[operation.status]\"\n            [tooltip]=\"operation.status?.toString() | translate\"\n          ></i>\n        </c8y-li-icon>\n        <c8y-li-body class=\"content-flex-40\">\n          <div class=\"col-4\">\n            <p class=\"text-truncate-wrap\" title=\"{{ operation.description | translate }}\">\n              {{ operation.description | translate }}\n            </p>\n          </div>\n          <div class=\"col-5\" *ngIf=\"operation.c8y_DiagnosticReport?.file\">\n            <div class=\"text-truncate-wrap m-t-xs-8\">\n              <span class=\"text-label-small visible-xs\" translate>File</span>\n              <span title=\"{{ operation.c8y_DiagnosticReport.file }}\">\n                <c8y-file-download\n                  url=\"{{ operation.c8y_DiagnosticReport.file }}\"\n                ></c8y-file-download>\n              </span>\n            </div>\n          </div>\n        </c8y-li-body>\n        <c8y-li-action\n          (click)=\"onCancel(operation)\"\n          *ngIf=\"operation.status === 'PENDING'\"\n          icon=\"times\"\n          label=\"{{ 'Cancel' | translate }}\"\n        ></c8y-li-action>\n        <c8y-li-action\n          (click)=\"onDelete(operation)\"\n          *ngIf=\"operation.status === 'SUCCESSFUL'\"\n          icon=\"delete\"\n          label=\"{{ 'Delete' | translate }}\"\n        ></c8y-li-action>\n      </c8y-li>\n    </c8y-li-timeline>\n  </ng-template>\n</c8y-list-group>\n\n<!-- EMPTY STATE -->\n\n<c8y-ui-empty-state\n  *ngIf=\"operationCount === 0\"\n  [icon]=\"'stethoscope'\"\n  [title]=\"'No diagnostic files available.' | translate\"\n></c8y-ui-empty-state>\n" }]
        }], ctorParameters: () => [{ type: i1.ActivatedRoute }, { type: i2.DiagnosticsService }, { type: i3.OperationRealtimeService }] });
//# sourceMappingURL=data:application/json;base64, 