import { Component, forwardRef, Input, ViewChild } from '@angular/core';
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
import { OperationStatus } from '@c8y/client';
import { CoreModule, gettext, ListItemComponent, PRODUCT_EXPERIENCE_EVENT_SOURCE } from '@c8y/ngx-components';
import { BulkOperationListItemService } from '@c8y/ngx-components/operations/bulk-operation-list-item';
import { OperationsListItemDetailsModule } from '@c8y/ngx-components/operations/operations-list-item-details';
import { OPERATION_STATUS_OPTIONS_MAP, OperationsService } from '@c8y/ngx-components/operations/shared';
import { TooltipModule } from 'ngx-bootstrap/tooltip';
import { OperationsListService } from './operations-list.service';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components/operations/bulk-operation-list-item";
import * as i2 from "@c8y/ngx-components/operations/shared";
import * as i3 from "./operations-list.service";
import * as i4 from "@angular/router";
import * as i5 from "@c8y/ngx-components";
import * as i6 from "@angular/common";
import * as i7 from "ngx-bootstrap/tooltip";
import * as i8 from "@c8y/ngx-components/operations/operations-list-item-details";
export class OperationsListItemComponent {
    constructor(bulkOperationListItemService, sharedService, operationsListService, route, router) {
        this.bulkOperationListItemService = bulkOperationListItemService;
        this.sharedService = sharedService;
        this.operationsListService = operationsListService;
        this.route = route;
        this.router = router;
        this.collapsed = true;
        this.readOnly = false;
        this.noExpandToggle = false;
        this.refreshLoading = false;
        this.OPERATION_STATUS = OperationStatus;
        this.OPERATION_STATUS_OPTIONS_MAP = OPERATION_STATUS_OPTIONS_MAP;
        this.deviceId = this.route.snapshot.parent?.data.contextData?.id ||
            this.route.snapshot.firstChild?.data.contextData?.id;
    }
    ngOnInit() {
        this.updateOperationTitle();
        const smartRulesCreatePermissions = this.operationsListService.getSmartRulesCreatePermissions();
        if (smartRulesCreatePermissions) {
            this.inventoryPermissions = smartRulesCreatePermissions[0].anyRole;
            this.smartRuleAdminPermissions = smartRulesCreatePermissions[1].anyRole;
        }
    }
    ngOnChanges(changes) {
        if (changes.operation && changes.operation.currentValue) {
            this.updateOperationTitle();
        }
    }
    createCustomizedBulkOperation($event) {
        if ($event) {
            $event.stopPropagation();
        }
        this.router.navigateByUrl(`/devicecontrol/single/create-bulk/${this.operation.id}`);
    }
    updateOperationTitle() {
        this.operationTitle =
            this.operation?.c8y_Command?.text ||
                this.operation?.description ||
                gettext('No command text or description available');
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OperationsListItemComponent, deps: [{ token: i1.BulkOperationListItemService }, { token: i2.OperationsService }, { token: i3.OperationsListService }, { token: i4.ActivatedRoute }, { token: i4.Router }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: OperationsListItemComponent, isStandalone: true, selector: "c8y-operations-list-item", inputs: { operation: "operation", collapsed: "collapsed", readOnly: "readOnly", noExpandToggle: "noExpandToggle", isSmartRulesMicroserviceAvailable: "isSmartRulesMicroserviceAvailable" }, providers: [
            {
                provide: PRODUCT_EXPERIENCE_EVENT_SOURCE,
                useExisting: forwardRef(() => OperationsListItemComponent)
            }
        ], viewQueries: [{ propertyName: "listItem", first: true, predicate: ["listItem"], descendants: true, static: true }], usesOnChanges: true, ngImport: i0, template: "<c8y-li\n  class=\"c8y-list__item--double-actions\"\n  [ngClass]=\"{ 'c8y-list__item--no-expand': noExpandToggle }\"\n  [collapsed]=\"collapsed\"\n  #listItem\n  id=\"{{ operation.id }}\"\n>\n  <c8y-li-icon>\n    <button\n      class=\"btn-clean\"\n      type=\"button\"\n      [attr.aria-label]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].label | translate\"\n      [tooltip]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].label | translate\"\n      placement=\"right\"\n      container=\"body\"\n      [delay]=\"500\"\n    >\n      <i\n        [c8yIcon]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].icon\"\n        [ngClass]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].styleClass\"\n      ></i>\n    </button>\n  </c8y-li-icon>\n  <div [ngClass]=\"{ 'content-flex-58': !readOnly, 'content-flex-50': readOnly }\">\n    <div class=\"col-5\">\n      <span title=\"{{ operationTitle | translate }}\" class=\"text-truncate\">\n        {{ operationTitle | translate }}\n      </span>\n    </div>\n    <div class=\"col-3\" *ngIf=\"!deviceId\">\n      <a\n        title=\"{{ operation.deviceName }}\"\n        [routerLink]=\"['/device', operation.deviceId, 'device-info']\"\n        routerLinkActive=\"active\"\n        class=\"text-truncate\"\n      >\n        {{ operation.deviceName }}\n      </a>\n    </div>\n    <div class=\"col-3\">\n      <small class=\"icon-flex text-muted\">\n        <i c8yIcon=\"calendar\" class=\"m-r-4\"></i>\n        {{ operation.creationTime | c8yDate }}\n      </small>\n    </div>\n  </div>\n  <ng-container *ngIf=\"!readOnly\">\n    <c8y-li-action\n      label=\"{{ 'Schedule as bulk operation' | translate }}\"\n      (click)=\"createCustomizedBulkOperation($event)\"\n      icon=\"c8y-icon c8y-icon-energy\"\n      c8yProductExperience\n      inherit\n    ></c8y-li-action>\n    <ng-container *c8yIfAllowed=\"inventoryPermissions; allowAny: true\">\n      <ng-container *c8yIfAllowed=\"smartRuleAdminPermissions; allowAny: true\">\n        <c8y-li-action\n          *ngIf=\"isSmartRulesMicroserviceAvailable\"\n          label=\"{{ 'Create smart rule' | translate }}\"\n          (click)=\"operationsListService.createSmartRule(operation)\"\n          icon=\"sliders\"\n          c8yProductExperience\n          inherit\n        ></c8y-li-action>\n      </ng-container>\n    </ng-container>\n    <c8y-li-action\n      *ngIf=\"operation.status === OPERATION_STATUS.PENDING\"\n      label=\"{{ 'Cancel operation' | translate }}\"\n      (click)=\"$event.stopPropagation(); sharedService.cancel(operation)\"\n      icon=\"times-circle\"\n      c8yProductExperience\n      inherit\n    ></c8y-li-action>\n  </ng-container>\n  <c8y-li-collapse class=\"m-b-16\">\n    <c8y-operation-details-tabs\n      *ngIf=\"!listItem.collapsed\"\n      [operation]=\"operation\"\n      [bulkOperationModalDetailsService]=\"bulkOperationListItemService\"\n    ></c8y-operation-details-tabs>\n  </c8y-li-collapse>\n</c8y-li>\n", dependencies: [{ kind: "ngmodule", type: CoreModule }, { kind: "directive", type: i5.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "pipe", type: i5.C8yTranslatePipe, name: "translate" }, { kind: "directive", type: i6.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i6.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.IfAllowedDirective, selector: "[c8yIfAllowed]", inputs: ["c8yIfAllowed", "c8yIfAllowedAllowAny"] }, { kind: "pipe", type: i5.DatePipe, name: "c8yDate" }, { kind: "component", type: i5.ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: i5.ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "component", type: i5.ListItemActionComponent, selector: "c8y-list-item-action, c8y-li-action", inputs: ["label", "icon", "disabled"], outputs: ["click"] }, { kind: "component", type: i5.ListItemCollapseComponent, selector: "c8y-list-item-collapse, c8y-li-collapse", inputs: ["collapseWay"] }, { kind: "directive", type: i5.ProductExperienceDirective, selector: "[c8yProductExperience]", inputs: ["actionName", "actionData", "inherit", "suppressDataOverriding"] }, { kind: "ngmodule", type: TooltipModule }, { kind: "directive", type: i7.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: "ngmodule", type: OperationsListItemDetailsModule }, { kind: "component", type: i8.OperationDetailsTabsComponent, selector: "c8y-operation-details-tabs", inputs: ["operation", "readOnly", "bulkOperationModalDetailsService"], outputs: ["onRetryFailedOperations", "showFailedOperation"] }, { kind: "directive", type: RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: OperationsListItemComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-operations-list-item', standalone: true, imports: [CoreModule, TooltipModule, OperationsListItemDetailsModule, RouterLink], providers: [
                        {
                            provide: PRODUCT_EXPERIENCE_EVENT_SOURCE,
                            useExisting: forwardRef(() => OperationsListItemComponent)
                        }
                    ], template: "<c8y-li\n  class=\"c8y-list__item--double-actions\"\n  [ngClass]=\"{ 'c8y-list__item--no-expand': noExpandToggle }\"\n  [collapsed]=\"collapsed\"\n  #listItem\n  id=\"{{ operation.id }}\"\n>\n  <c8y-li-icon>\n    <button\n      class=\"btn-clean\"\n      type=\"button\"\n      [attr.aria-label]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].label | translate\"\n      [tooltip]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].label | translate\"\n      placement=\"right\"\n      container=\"body\"\n      [delay]=\"500\"\n    >\n      <i\n        [c8yIcon]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].icon\"\n        [ngClass]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].styleClass\"\n      ></i>\n    </button>\n  </c8y-li-icon>\n  <div [ngClass]=\"{ 'content-flex-58': !readOnly, 'content-flex-50': readOnly }\">\n    <div class=\"col-5\">\n      <span title=\"{{ operationTitle | translate }}\" class=\"text-truncate\">\n        {{ operationTitle | translate }}\n      </span>\n    </div>\n    <div class=\"col-3\" *ngIf=\"!deviceId\">\n      <a\n        title=\"{{ operation.deviceName }}\"\n        [routerLink]=\"['/device', operation.deviceId, 'device-info']\"\n        routerLinkActive=\"active\"\n        class=\"text-truncate\"\n      >\n        {{ operation.deviceName }}\n      </a>\n    </div>\n    <div class=\"col-3\">\n      <small class=\"icon-flex text-muted\">\n        <i c8yIcon=\"calendar\" class=\"m-r-4\"></i>\n        {{ operation.creationTime | c8yDate }}\n      </small>\n    </div>\n  </div>\n  <ng-container *ngIf=\"!readOnly\">\n    <c8y-li-action\n      label=\"{{ 'Schedule as bulk operation' | translate }}\"\n      (click)=\"createCustomizedBulkOperation($event)\"\n      icon=\"c8y-icon c8y-icon-energy\"\n      c8yProductExperience\n      inherit\n    ></c8y-li-action>\n    <ng-container *c8yIfAllowed=\"inventoryPermissions; allowAny: true\">\n      <ng-container *c8yIfAllowed=\"smartRuleAdminPermissions; allowAny: true\">\n        <c8y-li-action\n          *ngIf=\"isSmartRulesMicroserviceAvailable\"\n          label=\"{{ 'Create smart rule' | translate }}\"\n          (click)=\"operationsListService.createSmartRule(operation)\"\n          icon=\"sliders\"\n          c8yProductExperience\n          inherit\n        ></c8y-li-action>\n      </ng-container>\n    </ng-container>\n    <c8y-li-action\n      *ngIf=\"operation.status === OPERATION_STATUS.PENDING\"\n      label=\"{{ 'Cancel operation' | translate }}\"\n      (click)=\"$event.stopPropagation(); sharedService.cancel(operation)\"\n      icon=\"times-circle\"\n      c8yProductExperience\n      inherit\n    ></c8y-li-action>\n  </ng-container>\n  <c8y-li-collapse class=\"m-b-16\">\n    <c8y-operation-details-tabs\n      *ngIf=\"!listItem.collapsed\"\n      [operation]=\"operation\"\n      [bulkOperationModalDetailsService]=\"bulkOperationListItemService\"\n    ></c8y-operation-details-tabs>\n  </c8y-li-collapse>\n</c8y-li>\n" }]
        }], ctorParameters: () => [{ type: i1.BulkOperationListItemService }, { type: i2.OperationsService }, { type: i3.OperationsListService }, { type: i4.ActivatedRoute }, { type: i4.Router }], propDecorators: { operation: [{
                type: Input
            }], collapsed: [{
                type: Input
            }], readOnly: [{
                type: Input
            }], noExpandToggle: [{
                type: Input
            }], isSmartRulesMicroserviceAvailable: [{
                type: Input
            }], listItem: [{
                type: ViewChild,
                args: ['listItem', { static: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 