import { Component, ElementRef, Input, ViewChild } from '@angular/core';
import { InventoryService, OperationService } from '@c8y/client';
import { AlertService, gettext } from '@c8y/ngx-components';
import { ACTIONS_OPERATIONS, BULK_OPERATION_EVENT, COMPONENTS } from '@c8y/ngx-components/operations/product-experience';
import { OPERATION_STATUS_LABELS, OPERATION_STATUS_OPTIONS_MAP } from '@c8y/ngx-components/operations/shared';
import { omit } from 'lodash-es';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components";
import * as i2 from "@c8y/client";
import * as i3 from "@angular/common";
import * as i4 from "ngx-bootstrap/popover";
import * as i5 from "@angular/router";
import * as i6 from "ngx-bootstrap/tooltip";
/**
 * @deprecated Single operations list in bulk operations details has been replaced by data grid. This component will be removed in the future.
 */
export class SingleOperationItemComponent {
    constructor(alertService, inventoryService, operationService) {
        this.alertService = alertService;
        this.inventoryService = inventoryService;
        this.operationService = operationService;
        this.BULK_OPERATION_EVENT = BULK_OPERATION_EVENT;
        this.ACTIONS = ACTIONS_OPERATIONS;
        this.COMPONENTS = COMPONENTS;
        this.device = {};
        this.OPERATION_STATUS_LABELS = OPERATION_STATUS_LABELS;
        this.OPERATION_STATUS_OPTIONS_MAP = OPERATION_STATUS_OPTIONS_MAP;
        this.readOnly = false;
    }
    async ngOnInit() {
        this.device = (await this.inventoryService.detail(this.operation.deviceId))?.data;
    }
    async retrySingleOperation(singleOperation) {
        const operationToCreate = omit(singleOperation, [
            'id',
            'self',
            'status',
            'failureReason',
            'creationTime',
            'delivery'
        ]);
        try {
            await this.operationService.create(operationToCreate);
            this.alertService.success(gettext('Operation created.'));
        }
        catch (er) {
            this.alertService.addServerFailure(er);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: SingleOperationItemComponent, deps: [{ token: i1.AlertService }, { token: i2.InventoryService }, { token: i2.OperationService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: SingleOperationItemComponent, selector: "c8y-single-operation-item", inputs: { operation: "operation", readOnly: "readOnly" }, viewQueries: [{ propertyName: "failureReasonRef", first: true, predicate: ["failureReason"], descendants: true, static: true }], ngImport: i0, template: "<c8y-li class=\"c8y-list__item--double-actions\">\n  <c8y-li-icon>\n    <i\n      [c8yIcon]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].icon\"\n      [tooltip]=\"operation.status.toString() | translate\"\n      [ngClass]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].styleClass\"\n    ></i>\n  </c8y-li-icon>\n  <div [ngClass]=\"{ 'content-flex-80': !readOnly, 'content-flex-50': readOnly }\">\n    <div class=\"col-4\">\n      <span class=\"m-r-4\">\n        <device-status [mo]=\"device\"></device-status>\n      </span>\n      <a\n        [routerLink]=\"['/device', operation.deviceId, 'device-info']\"\n        routerLinkActive=\"active\"\n      >\n        {{ operation.deviceName }}\n      </a>\n    </div>\n    <div class=\"col-3\">\n      <small class=\"icon-flex text-muted\">\n        <i\n          class=\"m-r-4\"\n          c8yIcon=\"calendar\"\n        ></i>\n        {{ operation.creationTime | c8yDate }}\n      </small>\n    </div>\n    <div class=\"col-5\">\n      <div class=\"d-flex a-i-center\">\n        <span\n          class=\"text-truncate\"\n          #failureReason\n        >\n          {{ operation.failureReason | translate }}\n        </span>\n        <button\n          class=\"btn-help btn-help--sm\"\n          [attr.aria-label]=\"'Help' | translate\"\n          popover=\"{{ operation.failureReason | translate }}\"\n          placement=\"left\"\n          triggers=\"focus\"\n          type=\"button\"\n          *ngIf=\"failureReason.offsetWidth < failureReason.scrollWidth\"\n        >\n          <i [c8yIcon]=\"'info-circle'\"></i>\n        </button>\n        <div\n          class=\"showOnHover p-l-8 p-r-8 fit-h-20 m-l-auto\"\n          *ngIf=\"\n            !readOnly &&\n            operation.status.toString() == OPERATION_STATUS_OPTIONS_MAP.FAILED.status.toString()\n          \"\n        >\n          <button\n            class=\"btn btn-default btn-xs\"\n            title=\"{{ 'Retry operation' | translate }}\"\n            type=\"button\"\n            (click)=\"retrySingleOperation(operation)\"\n            c8yProductExperience\n            [actionName]=\"BULK_OPERATION_EVENT\"\n            [actionData]=\"{ action: ACTIONS.RETRY, component: COMPONENTS.SINGLE_OPERATION_ITEM }\"\n          >\n            <i [c8yIcon]=\"'repeat m-r-4'\"></i>\n            {{ 'Retry operation' | translate }}\n          </button>\n        </div>\n      </div>\n    </div>\n  </div>\n</c8y-li>\n", dependencies: [{ kind: "directive", type: i1.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i1.DeviceStatusComponent, selector: "device-status, c8y-device-status", inputs: ["mo", "size"] }, { kind: "component", type: i1.ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: i1.ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "directive", type: i1.ProductExperienceDirective, selector: "[c8yProductExperience]", inputs: ["actionName", "actionData", "inherit", "suppressDataOverriding"] }, { kind: "directive", type: i4.PopoverDirective, selector: "[popover]", inputs: ["adaptivePosition", "boundariesElement", "popover", "popoverContext", "popoverTitle", "placement", "outsideClick", "triggers", "container", "containerClass", "isOpen", "delay"], outputs: ["onShown", "onHidden"], exportAs: ["bs-popover"] }, { kind: "directive", type: i5.RouterLink, selector: "[routerLink]", inputs: ["target", "queryParams", "fragment", "queryParamsHandling", "state", "info", "relativeTo", "preserveFragment", "skipLocationChange", "replaceUrl", "routerLink"] }, { kind: "directive", type: i5.RouterLinkActive, selector: "[routerLinkActive]", inputs: ["routerLinkActiveOptions", "ariaCurrentWhenActive", "routerLinkActive"], outputs: ["isActiveChange"], exportAs: ["routerLinkActive"] }, { 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: i1.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i1.DatePipe, name: "c8yDate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: SingleOperationItemComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-single-operation-item', template: "<c8y-li class=\"c8y-list__item--double-actions\">\n  <c8y-li-icon>\n    <i\n      [c8yIcon]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].icon\"\n      [tooltip]=\"operation.status.toString() | translate\"\n      [ngClass]=\"OPERATION_STATUS_OPTIONS_MAP[operation.status].styleClass\"\n    ></i>\n  </c8y-li-icon>\n  <div [ngClass]=\"{ 'content-flex-80': !readOnly, 'content-flex-50': readOnly }\">\n    <div class=\"col-4\">\n      <span class=\"m-r-4\">\n        <device-status [mo]=\"device\"></device-status>\n      </span>\n      <a\n        [routerLink]=\"['/device', operation.deviceId, 'device-info']\"\n        routerLinkActive=\"active\"\n      >\n        {{ operation.deviceName }}\n      </a>\n    </div>\n    <div class=\"col-3\">\n      <small class=\"icon-flex text-muted\">\n        <i\n          class=\"m-r-4\"\n          c8yIcon=\"calendar\"\n        ></i>\n        {{ operation.creationTime | c8yDate }}\n      </small>\n    </div>\n    <div class=\"col-5\">\n      <div class=\"d-flex a-i-center\">\n        <span\n          class=\"text-truncate\"\n          #failureReason\n        >\n          {{ operation.failureReason | translate }}\n        </span>\n        <button\n          class=\"btn-help btn-help--sm\"\n          [attr.aria-label]=\"'Help' | translate\"\n          popover=\"{{ operation.failureReason | translate }}\"\n          placement=\"left\"\n          triggers=\"focus\"\n          type=\"button\"\n          *ngIf=\"failureReason.offsetWidth < failureReason.scrollWidth\"\n        >\n          <i [c8yIcon]=\"'info-circle'\"></i>\n        </button>\n        <div\n          class=\"showOnHover p-l-8 p-r-8 fit-h-20 m-l-auto\"\n          *ngIf=\"\n            !readOnly &&\n            operation.status.toString() == OPERATION_STATUS_OPTIONS_MAP.FAILED.status.toString()\n          \"\n        >\n          <button\n            class=\"btn btn-default btn-xs\"\n            title=\"{{ 'Retry operation' | translate }}\"\n            type=\"button\"\n            (click)=\"retrySingleOperation(operation)\"\n            c8yProductExperience\n            [actionName]=\"BULK_OPERATION_EVENT\"\n            [actionData]=\"{ action: ACTIONS.RETRY, component: COMPONENTS.SINGLE_OPERATION_ITEM }\"\n          >\n            <i [c8yIcon]=\"'repeat m-r-4'\"></i>\n            {{ 'Retry operation' | translate }}\n          </button>\n        </div>\n      </div>\n    </div>\n  </div>\n</c8y-li>\n" }]
        }], ctorParameters: () => [{ type: i1.AlertService }, { type: i2.InventoryService }, { type: i2.OperationService }], propDecorators: { operation: [{
                type: Input
            }], readOnly: [{
                type: Input
            }], failureReasonRef: [{
                type: ViewChild,
                args: ['failureReason', { static: true }]
            }] } });
//# sourceMappingURL=data:application/json;base64, 