import * as i0 from '@angular/core';
import { EventEmitter, Output, Input, Component, NgModule } from '@angular/core';
import { gettext } from '@c8y/ngx-components/gettext';
import { IconDirective, ListItemComponent, ListItemIconComponent, ListItemBodyComponent, ListGroupComponent, ForOfDirective, ListItemRadioComponent, HighlightComponent, C8yTranslateDirective, C8yTranslatePipe, memoize, ListItemCollapseComponent } from '@c8y/ngx-components';
import { BaseStepperComponent, BulkOperationStepper, CustomStep } from '@c8y/ngx-components/operations/bulk-operation-stepper';
import * as i2 from '@c8y/ngx-components/operations/bulk-operations-service';
import { BulkOperationType, hookListBulkType, baseUrl } from '@c8y/ngx-components/operations/bulk-operations-service';
import * as i3 from '@ngx-translate/core';
import { get, property } from 'lodash-es';
import { BehaviorSubject, Observable, defer, of } from 'rxjs';
import { __decorate, __metadata } from 'tslib';
import { debounceTime, distinctUntilChanged, switchMap, tap, shareReplay, catchError, distinctUntilKeyChanged, map } from 'rxjs/operators';
import * as i1 from '@c8y/ngx-components/repository/shared';
import { RepositoryType } from '@c8y/ngx-components/repository/shared';
import { SelectStepFrameComponent, PreviewSelectionFrameComponent } from '@c8y/ngx-components/operations/stepper-frames';
import * as i4 from '@angular/forms';
import { FormsModule } from '@angular/forms';
import { NgIf, NgPlural, NgPluralCase, AsyncPipe } from '@angular/common';
import * as i2$1 from '@c8y/client';

class SelectFirmwareComponent {
    constructor(repositoryService, bulkOpsService, translate) {
        this.repositoryService = repositoryService;
        this.bulkOpsService = bulkOpsService;
        this.translate = translate;
        this.firmware = new EventEmitter();
        this.elementCount = 0;
        this.DD_LOW_COUNT = 10;
        this.textFilter$ = new BehaviorSubject('');
        this.firmwares$ = this.textFilter$
            .pipe(debounceTime(400), distinctUntilChanged())
            .pipe(switchMap(text => this.getFirmwares(text)), tap(resp => {
            this.elementCount = resp.data ? resp.data.length : 0;
        }), shareReplay(1));
        this.isLegacy = this.repositoryService.isLegacyEntry.bind(this.repositoryService);
        this.DEVICE_TYPE_NOT_AVAILABLE = gettext('No device type available.');
        this.DESCRIPTION_NOT_AVAILABLE = gettext('No description available.');
    }
    ngOnInit() {
        this.DD_LOW_COUNT = this.bulkOpsService.DD_LOW_COUNT;
    }
    selectFirmware(selected, fw) {
        if (selected) {
            this.firmware.emit(fw);
        }
    }
    getBaseVersionsCount$(firmware) {
        return this.firmwares$.pipe(switchMap(() => this.repositoryService.getBaseVersionsCount$(firmware)), shareReplay(1));
    }
    getDescriptionTitle(firmware) {
        return get(firmware, 'description', this.translate.instant(this.DESCRIPTION_NOT_AVAILABLE));
    }
    getDeviceTypeTitle(firmware) {
        return get(firmware, 'c8y_Filter.type', this.translate.instant(this.DEVICE_TYPE_NOT_AVAILABLE));
    }
    getFirmwares(partialName) {
        return this.repositoryService.listRepositoryEntries(RepositoryType.FIRMWARE, { partialName });
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: SelectFirmwareComponent, deps: [{ token: i1.RepositoryService }, { token: i2.BulkOperationsService }, { token: i3.TranslateService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: SelectFirmwareComponent, isStandalone: true, selector: "c8y-select-firmware-step", inputs: { selected: "selected" }, outputs: { firmware: "firmware" }, ngImport: i0, template: "<c8y-select-step-frame\n  [header]=\"'Select firmware' | translate\"\n  [noResults]=\"(textFilter$ | async).length > 0 && elementCount === 0\"\n>\n  <label\n    class=\"sr-only\"\n    for=\"fFilter\"\n  >\n    {{ 'Filter\u2026' | translate }}\n  </label>\n  <div\n    class=\"input-group input-group-search\"\n    filters\n  >\n    <input\n      class=\"form-control\"\n      title=\"{{ 'Filter\u2026' | translate }}\"\n      id=\"fFilter\"\n      placeholder=\"{{ 'Filter\u2026' | translate }}\"\n      type=\"search\"\n      [ngModel]=\"textFilter$ | async\"\n      (ngModelChange)=\"textFilter$.next($event)\"\n    />\n    <span class=\"input-group-addon\">\n      <i\n        c8yIcon=\"search\"\n        *ngIf=\"(textFilter$ | async).length === 0\"\n      ></i>\n      <i\n        class=\"text-muted\"\n        c8yIcon=\"times\"\n        *ngIf=\"(textFilter$ | async).length > 0\"\n        (click)=\"textFilter$.next('')\"\n      ></i>\n    </span>\n  </div>\n  <c8y-li\n    class=\"hidden-sm hidden-xs m-r-8 m-l-8\"\n    header\n  >\n    <c8y-li-icon><i class=\"p-l-32 p-r-40\"></i></c8y-li-icon>\n    <c8y-li-body class=\"content-flex-40\">\n      <div class=\"col-3\">\n        <span\n          class=\"text-truncate\"\n          title=\" {{ 'Name' | translate }} \"\n        >\n          {{ 'Name' | translate }}\n        </span>\n      </div>\n      <div class=\"col-4\">\n        <span\n          class=\"text-truncate\"\n          title=\"{{ 'Description' | translate }}\"\n        >\n          {{ 'Description' | translate }}\n        </span>\n      </div>\n      <div class=\"col-3\">\n        <span\n          class=\"text-truncate\"\n          title=\"{{ 'Device type' | translate }}\"\n        >\n          {{ 'Device type' | translate }}\n        </span>\n      </div>\n      <div class=\"col-2\">\n        <span\n          class=\"text-truncate\"\n          title=\"{{ 'Versions' | translate }}\"\n        >\n          {{ 'Versions' | translate }}\n        </span>\n      </div>\n    </c8y-li-body>\n  </c8y-li>\n  <c8y-list-group list>\n    <c8y-li *c8yFor=\"let firmware of firmwares$ | async; let i = index; loadMore: 'auto'\">\n      <c8y-li-radio\n        (onSelect)=\"selectFirmware($event, firmware)\"\n        [selected]=\"firmware === selected\"\n      ></c8y-li-radio>\n      <c8y-li-icon>\n        <i c8yIcon=\"c8y-firmware\"></i>\n      </c8y-li-icon>\n\n      <c8y-li-body class=\"content-flex-40\">\n        <div class=\"col-3 m-b-xs-8\">\n          <div\n            class=\"text-truncate\"\n            title=\"{{ firmware.name }}\"\n          >\n            <c8y-highlight\n              [text]=\"firmware.name\"\n              [pattern]=\"textFilter$ | async\"\n            ></c8y-highlight>\n          </div>\n        </div>\n        <div class=\"col-4 m-b-xs-8\">\n          <div\n            class=\"text-truncate\"\n            title=\"{{ getDescriptionTitle(firmware) }}\"\n          >\n            <span\n              class=\"text-label-small m-r-8 visible-xs visible-sm\"\n              translate\n            >\n              Description\n            </span>\n            <small *ngIf=\"firmware.description; else noDesc\">\n              {{ firmware.description }}\n            </small>\n            <ng-template #noDesc>\n              <small>\n                <em\n                  class=\"text-muted\"\n                  translate\n                >\n                  No description available.\n                </em>\n              </small>\n            </ng-template>\n          </div>\n        </div>\n        <div class=\"col-3 m-b-xs-8\">\n          <div\n            class=\"text-truncate\"\n            title=\"{{ 'Device type' | translate }}: {{ getDeviceTypeTitle(firmware) }}\"\n          >\n            <span\n              class=\"text-label-small m-r-8 visible-xs visible-sm\"\n              translate\n            >\n              Device type\n            </span>\n            <span *ngIf=\"firmware.c8y_Filter?.type; else noType\">\n              {{ firmware.c8y_Filter?.type }}\n            </span>\n            <ng-template #noType>\n              <em\n                class=\"text-muted\"\n                translate\n              >\n                Undefined`device type`\n              </em>\n            </ng-template>\n          </div>\n        </div>\n        <div class=\"col-2\">\n          <span\n            class=\"label label-warning m-l-auto-sm\"\n            *ngIf=\"isLegacy(firmware)\"\n          >\n            <span translate>Legacy</span>\n          </span>\n\n          <span *ngIf=\"!isLegacy(firmware)\">\n            <span *ngIf=\"(getBaseVersionsCount$(firmware) | async) === null\">\n              <span class=\"label label-info\">\n                <i\n                  class=\"icon-spin\"\n                  c8yIcon=\"circle-o-notch\"\n                ></i>\n              </span>\n            </span>\n            <span *ngIf=\"(getBaseVersionsCount$(firmware) | async) !== null\">\n              <span [ngPlural]=\"getBaseVersionsCount$(firmware) | async\">\n                <ng-template ngPluralCase=\"=0\">\n                  <span class=\"label label-default\">\n                    <span translate>No versions</span>\n                  </span>\n                </ng-template>\n                <ng-template ngPluralCase=\"=1\">\n                  <span\n                    class=\"text-label-small m-r-8 visible-xs visible-sm\"\n                    translate\n                  >\n                    version\n                  </span>\n                  <span class=\"badge badge-info m-l-auto-sm\">1</span>\n                </ng-template>\n                <ng-template ngPluralCase=\"other\">\n                  <span\n                    class=\"text-label-small m-r-8 visible-xs visible-sm\"\n                    translate\n                  >\n                    versions\n                  </span>\n                  <span class=\"badge badge-info m-l-auto-sm\">\n                    {{ getBaseVersionsCount$(firmware) | async }}\n                  </span>\n                </ng-template>\n              </span>\n            </span>\n          </span>\n        </div>\n      </c8y-li-body>\n    </c8y-li>\n  </c8y-list-group>\n</c8y-select-step-frame>\n", dependencies: [{ kind: "component", type: SelectStepFrameComponent, selector: "c8y-select-step-frame", inputs: ["header", "noResults"] }, { kind: "ngmodule", type: FormsModule }, { kind: "directive", type: i4.DefaultValueAccessor, selector: "input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]" }, { kind: "directive", type: i4.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i4.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "component", type: ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "component", type: ListItemBodyComponent, selector: "c8y-list-item-body, c8y-li-body", inputs: ["body"] }, { kind: "component", type: ListGroupComponent, selector: "c8y-list-group" }, { kind: "directive", type: 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: ListItemRadioComponent, selector: "c8y-list-item-radio, c8y-li-radio", inputs: ["selected", "name", "disabled", "value"], outputs: ["onSelect"] }, { kind: "component", type: HighlightComponent, selector: "c8y-highlight", inputs: ["pattern", "text", "elementClass", "shouldTrimPattern"] }, { kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: NgPlural, selector: "[ngPlural]", inputs: ["ngPlural"] }, { kind: "directive", type: NgPluralCase, selector: "[ngPluralCase]" }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }] }); }
}
__decorate([
    memoize(property('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Observable)
], SelectFirmwareComponent.prototype, "getBaseVersionsCount$", null);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: SelectFirmwareComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-select-firmware-step', imports: [
                        SelectStepFrameComponent,
                        FormsModule,
                        NgIf,
                        IconDirective,
                        ListItemComponent,
                        ListItemIconComponent,
                        ListItemBodyComponent,
                        ListGroupComponent,
                        ForOfDirective,
                        ListItemRadioComponent,
                        HighlightComponent,
                        C8yTranslateDirective,
                        NgPlural,
                        NgPluralCase,
                        C8yTranslatePipe,
                        AsyncPipe
                    ], template: "<c8y-select-step-frame\n  [header]=\"'Select firmware' | translate\"\n  [noResults]=\"(textFilter$ | async).length > 0 && elementCount === 0\"\n>\n  <label\n    class=\"sr-only\"\n    for=\"fFilter\"\n  >\n    {{ 'Filter\u2026' | translate }}\n  </label>\n  <div\n    class=\"input-group input-group-search\"\n    filters\n  >\n    <input\n      class=\"form-control\"\n      title=\"{{ 'Filter\u2026' | translate }}\"\n      id=\"fFilter\"\n      placeholder=\"{{ 'Filter\u2026' | translate }}\"\n      type=\"search\"\n      [ngModel]=\"textFilter$ | async\"\n      (ngModelChange)=\"textFilter$.next($event)\"\n    />\n    <span class=\"input-group-addon\">\n      <i\n        c8yIcon=\"search\"\n        *ngIf=\"(textFilter$ | async).length === 0\"\n      ></i>\n      <i\n        class=\"text-muted\"\n        c8yIcon=\"times\"\n        *ngIf=\"(textFilter$ | async).length > 0\"\n        (click)=\"textFilter$.next('')\"\n      ></i>\n    </span>\n  </div>\n  <c8y-li\n    class=\"hidden-sm hidden-xs m-r-8 m-l-8\"\n    header\n  >\n    <c8y-li-icon><i class=\"p-l-32 p-r-40\"></i></c8y-li-icon>\n    <c8y-li-body class=\"content-flex-40\">\n      <div class=\"col-3\">\n        <span\n          class=\"text-truncate\"\n          title=\" {{ 'Name' | translate }} \"\n        >\n          {{ 'Name' | translate }}\n        </span>\n      </div>\n      <div class=\"col-4\">\n        <span\n          class=\"text-truncate\"\n          title=\"{{ 'Description' | translate }}\"\n        >\n          {{ 'Description' | translate }}\n        </span>\n      </div>\n      <div class=\"col-3\">\n        <span\n          class=\"text-truncate\"\n          title=\"{{ 'Device type' | translate }}\"\n        >\n          {{ 'Device type' | translate }}\n        </span>\n      </div>\n      <div class=\"col-2\">\n        <span\n          class=\"text-truncate\"\n          title=\"{{ 'Versions' | translate }}\"\n        >\n          {{ 'Versions' | translate }}\n        </span>\n      </div>\n    </c8y-li-body>\n  </c8y-li>\n  <c8y-list-group list>\n    <c8y-li *c8yFor=\"let firmware of firmwares$ | async; let i = index; loadMore: 'auto'\">\n      <c8y-li-radio\n        (onSelect)=\"selectFirmware($event, firmware)\"\n        [selected]=\"firmware === selected\"\n      ></c8y-li-radio>\n      <c8y-li-icon>\n        <i c8yIcon=\"c8y-firmware\"></i>\n      </c8y-li-icon>\n\n      <c8y-li-body class=\"content-flex-40\">\n        <div class=\"col-3 m-b-xs-8\">\n          <div\n            class=\"text-truncate\"\n            title=\"{{ firmware.name }}\"\n          >\n            <c8y-highlight\n              [text]=\"firmware.name\"\n              [pattern]=\"textFilter$ | async\"\n            ></c8y-highlight>\n          </div>\n        </div>\n        <div class=\"col-4 m-b-xs-8\">\n          <div\n            class=\"text-truncate\"\n            title=\"{{ getDescriptionTitle(firmware) }}\"\n          >\n            <span\n              class=\"text-label-small m-r-8 visible-xs visible-sm\"\n              translate\n            >\n              Description\n            </span>\n            <small *ngIf=\"firmware.description; else noDesc\">\n              {{ firmware.description }}\n            </small>\n            <ng-template #noDesc>\n              <small>\n                <em\n                  class=\"text-muted\"\n                  translate\n                >\n                  No description available.\n                </em>\n              </small>\n            </ng-template>\n          </div>\n        </div>\n        <div class=\"col-3 m-b-xs-8\">\n          <div\n            class=\"text-truncate\"\n            title=\"{{ 'Device type' | translate }}: {{ getDeviceTypeTitle(firmware) }}\"\n          >\n            <span\n              class=\"text-label-small m-r-8 visible-xs visible-sm\"\n              translate\n            >\n              Device type\n            </span>\n            <span *ngIf=\"firmware.c8y_Filter?.type; else noType\">\n              {{ firmware.c8y_Filter?.type }}\n            </span>\n            <ng-template #noType>\n              <em\n                class=\"text-muted\"\n                translate\n              >\n                Undefined`device type`\n              </em>\n            </ng-template>\n          </div>\n        </div>\n        <div class=\"col-2\">\n          <span\n            class=\"label label-warning m-l-auto-sm\"\n            *ngIf=\"isLegacy(firmware)\"\n          >\n            <span translate>Legacy</span>\n          </span>\n\n          <span *ngIf=\"!isLegacy(firmware)\">\n            <span *ngIf=\"(getBaseVersionsCount$(firmware) | async) === null\">\n              <span class=\"label label-info\">\n                <i\n                  class=\"icon-spin\"\n                  c8yIcon=\"circle-o-notch\"\n                ></i>\n              </span>\n            </span>\n            <span *ngIf=\"(getBaseVersionsCount$(firmware) | async) !== null\">\n              <span [ngPlural]=\"getBaseVersionsCount$(firmware) | async\">\n                <ng-template ngPluralCase=\"=0\">\n                  <span class=\"label label-default\">\n                    <span translate>No versions</span>\n                  </span>\n                </ng-template>\n                <ng-template ngPluralCase=\"=1\">\n                  <span\n                    class=\"text-label-small m-r-8 visible-xs visible-sm\"\n                    translate\n                  >\n                    version\n                  </span>\n                  <span class=\"badge badge-info m-l-auto-sm\">1</span>\n                </ng-template>\n                <ng-template ngPluralCase=\"other\">\n                  <span\n                    class=\"text-label-small m-r-8 visible-xs visible-sm\"\n                    translate\n                  >\n                    versions\n                  </span>\n                  <span class=\"badge badge-info m-l-auto-sm\">\n                    {{ getBaseVersionsCount$(firmware) | async }}\n                  </span>\n                </ng-template>\n              </span>\n            </span>\n          </span>\n        </div>\n      </c8y-li-body>\n    </c8y-li>\n  </c8y-list-group>\n</c8y-select-step-frame>\n" }]
        }], ctorParameters: () => [{ type: i1.RepositoryService }, { type: i2.BulkOperationsService }, { type: i3.TranslateService }], propDecorators: { selected: [{
                type: Input
            }], firmware: [{
                type: Output
            }], getBaseVersionsCount$: [] } });

class VersionOrPatchComponent {
    constructor(repositoryService, inventoryService, bulkOpsService) {
        this.repositoryService = repositoryService;
        this.inventoryService = inventoryService;
        this.bulkOpsService = bulkOpsService;
        this.versionOrPatch = new EventEmitter();
        this.elementCount = 0;
        this.DD_LOW_COUNT = 10;
        this.firmware$ = this.bulkOpsService.firmwareId.pipe(distinctUntilChanged(), switchMap(id => defer(() => this.inventoryService.detail(id).then(result => result.data)).pipe(catchError(error => of(error)))), shareReplay(1));
        this.baseVersions$ = this.firmware$.pipe(distinctUntilKeyChanged('id'), switchMap(firmware => this.repositoryService.listBaseVersions(firmware)), tap(resp => {
            this.elementCount = resp.data ? resp.data.length : 0;
        }), shareReplay(1));
        this.isLegacy$ = this.firmware$.pipe(map(firmware => this.repositoryService.isLegacyEntry(firmware)), shareReplay(1));
        this.expanded = {};
        this.DD_LOW_COUNT = this.bulkOpsService.DD_LOW_COUNT;
    }
    getBinaryName$(binaryUrl) {
        return this.repositoryService.getBinaryName$(binaryUrl);
    }
    getBaseVersionAndPatches$(baseVersion) {
        return this.firmware$.pipe(distinctUntilKeyChanged('id'), switchMap(firmware => this.repositoryService.listBaseVersionAndPatches(firmware, baseVersion)), shareReplay(1));
    }
    getPatchVersionsCount$(baseVersion) {
        return this.firmware$.pipe(distinctUntilKeyChanged('id'), switchMap(() => this.firmware$), switchMap(firmware => this.repositoryService.getPatchVersionsCount$(firmware, baseVersion)), shareReplay(1));
    }
    selectVersionOrPatch(selected, versionOrPatch) {
        if (selected) {
            this.versionOrPatch.emit(versionOrPatch);
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VersionOrPatchComponent, deps: [{ token: i1.RepositoryService }, { token: i2$1.InventoryService }, { token: i2.BulkOperationsService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: VersionOrPatchComponent, isStandalone: true, selector: "c8y-version-or-patch-step", inputs: { selected: "selected" }, outputs: { versionOrPatch: "versionOrPatch" }, ngImport: i0, template: "<c8y-list-group\n  class=\"m-b-16\"\n  *ngIf=\"(baseVersions$ | async)?.data.length > 0\"\n>\n  <c8y-li *c8yFor=\"let baseVersion of baseVersions$ | async; let i = index; loadMore: 'auto'\">\n    <c8y-li-icon>\n      <i c8yIcon=\"c8y-firmware\"></i>\n    </c8y-li-icon>\n\n    <c8y-li-body class=\"content-flex-50\">\n      <div class=\"col-10\">\n        <p>{{ baseVersion.c8y_Firmware.version }}</p>\n      </div>\n      <div class=\"col-2\">\n        <span\n          class=\"label label-warning\"\n          *ngIf=\"isLegacy$ | async\"\n        >\n          {{ 'Legacy' | translate }}\n        </span>\n\n        <span *ngIf=\"!(isLegacy$ | async)\">\n          <span *ngIf=\"(getPatchVersionsCount$(baseVersion) | async) === null\">\n            <span class=\"label label-info\">\n              <i\n                class=\"icon-spin\"\n                c8yIcon=\"circle-o-notch\"\n              ></i>\n            </span>\n          </span>\n\n          <span *ngIf=\"(getPatchVersionsCount$(baseVersion) | async) !== null\">\n            <span [ngPlural]=\"getPatchVersionsCount$(baseVersion) | async\">\n              <ng-template ngPluralCase=\"=0\">\n                <span class=\"label label-default\"><span translate>No patches</span></span>\n              </ng-template>\n              <ng-template ngPluralCase=\"=1\">\n                <span class=\"label label-info\">\n                  <span translate>1 patch</span>\n                </span>\n              </ng-template>\n              <ng-template ngPluralCase=\"other\">\n                <span class=\"label label-info\">\n                  <span\n                    ngNonBindable\n                    translate\n                    [translateParams]=\"{ count: getPatchVersionsCount$(baseVersion) | async }\"\n                  >\n                    {{ count }} patches\n                  </span>\n                </span>\n              </ng-template>\n            </span>\n          </span>\n        </span>\n      </div>\n    </c8y-li-body>\n\n    <c8y-li-collapse>\n      <c8y-list-group>\n        <c8y-li\n          *c8yFor=\"\n            let patchVersion of getBaseVersionAndPatches$(baseVersion) | async;\n            let i = index;\n            loadMore: 'auto'\n          \"\n        >\n          <c8y-li-radio\n            (onSelect)=\"selectVersionOrPatch($event, patchVersion)\"\n            [selected]=\"patchVersion === selected\"\n          ></c8y-li-radio>\n          <c8y-li-icon>\n            <i c8yIcon=\"c8y-firmware\"></i>\n          </c8y-li-icon>\n          <c8y-li-body class=\"content-flex-50\">\n            <div class=\"col-3\">\n              {{ patchVersion.c8y_Firmware.version }}\n            </div>\n            <div class=\"col-3\">\n              <span\n                class=\"label label-info\"\n                *ngIf=\"patchVersion.c8y_Patch; else version\"\n                translate\n              >\n                patch\n              </span>\n              <ng-template #version>\n                <span\n                  class=\"label label-primary\"\n                  translate\n                >\n                  version\n                </span>\n              </ng-template>\n            </div>\n            <div class=\"col-6 text-truncate\">\n              <span\n                class=\"text-label-small m-r-4\"\n                translate\n              >\n                File\n              </span>\n              <ng-container *ngIf=\"patchVersion.c8y_Firmware.url === '$PROVIDED'; else fileName\">\n                <span title=\"{{ 'Provided by device' | translate }}\">\n                  {{ 'Provided by device' | translate }}\n                </span>\n              </ng-container>\n              <ng-template #fileName>\n                <span title=\"{{ getBinaryName$(patchVersion.c8y_Firmware.url) | async }}\">\n                  {{ getBinaryName$(patchVersion.c8y_Firmware.url) | async }}\n                </span>\n              </ng-template>\n            </div>\n          </c8y-li-body>\n        </c8y-li>\n      </c8y-list-group>\n    </c8y-li-collapse>\n  </c8y-li>\n</c8y-list-group>\n", dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: ListGroupComponent, selector: "c8y-list-group" }, { kind: "directive", type: 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: ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "directive", type: IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "component", type: ListItemBodyComponent, selector: "c8y-list-item-body, c8y-li-body", inputs: ["body"] }, { kind: "directive", type: NgPlural, selector: "[ngPlural]", inputs: ["ngPlural"] }, { kind: "directive", type: NgPluralCase, selector: "[ngPluralCase]" }, { kind: "directive", type: C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "component", type: ListItemCollapseComponent, selector: "c8y-list-item-collapse, c8y-li-collapse", inputs: ["collapseWay"] }, { kind: "component", type: ListItemRadioComponent, selector: "c8y-list-item-radio, c8y-li-radio", inputs: ["selected", "name", "disabled", "value"], outputs: ["onSelect"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: AsyncPipe, name: "async" }] }); }
}
__decorate([
    memoize(),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], VersionOrPatchComponent.prototype, "getBinaryName$", null);
__decorate([
    memoize(property('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], VersionOrPatchComponent.prototype, "getBaseVersionAndPatches$", null);
__decorate([
    memoize(property('id')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], VersionOrPatchComponent.prototype, "getPatchVersionsCount$", null);
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: VersionOrPatchComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-version-or-patch-step', imports: [
                        NgIf,
                        ListGroupComponent,
                        ForOfDirective,
                        ListItemComponent,
                        ListItemIconComponent,
                        IconDirective,
                        ListItemBodyComponent,
                        NgPlural,
                        NgPluralCase,
                        C8yTranslateDirective,
                        ListItemCollapseComponent,
                        ListItemRadioComponent,
                        C8yTranslatePipe,
                        AsyncPipe
                    ], template: "<c8y-list-group\n  class=\"m-b-16\"\n  *ngIf=\"(baseVersions$ | async)?.data.length > 0\"\n>\n  <c8y-li *c8yFor=\"let baseVersion of baseVersions$ | async; let i = index; loadMore: 'auto'\">\n    <c8y-li-icon>\n      <i c8yIcon=\"c8y-firmware\"></i>\n    </c8y-li-icon>\n\n    <c8y-li-body class=\"content-flex-50\">\n      <div class=\"col-10\">\n        <p>{{ baseVersion.c8y_Firmware.version }}</p>\n      </div>\n      <div class=\"col-2\">\n        <span\n          class=\"label label-warning\"\n          *ngIf=\"isLegacy$ | async\"\n        >\n          {{ 'Legacy' | translate }}\n        </span>\n\n        <span *ngIf=\"!(isLegacy$ | async)\">\n          <span *ngIf=\"(getPatchVersionsCount$(baseVersion) | async) === null\">\n            <span class=\"label label-info\">\n              <i\n                class=\"icon-spin\"\n                c8yIcon=\"circle-o-notch\"\n              ></i>\n            </span>\n          </span>\n\n          <span *ngIf=\"(getPatchVersionsCount$(baseVersion) | async) !== null\">\n            <span [ngPlural]=\"getPatchVersionsCount$(baseVersion) | async\">\n              <ng-template ngPluralCase=\"=0\">\n                <span class=\"label label-default\"><span translate>No patches</span></span>\n              </ng-template>\n              <ng-template ngPluralCase=\"=1\">\n                <span class=\"label label-info\">\n                  <span translate>1 patch</span>\n                </span>\n              </ng-template>\n              <ng-template ngPluralCase=\"other\">\n                <span class=\"label label-info\">\n                  <span\n                    ngNonBindable\n                    translate\n                    [translateParams]=\"{ count: getPatchVersionsCount$(baseVersion) | async }\"\n                  >\n                    {{ count }} patches\n                  </span>\n                </span>\n              </ng-template>\n            </span>\n          </span>\n        </span>\n      </div>\n    </c8y-li-body>\n\n    <c8y-li-collapse>\n      <c8y-list-group>\n        <c8y-li\n          *c8yFor=\"\n            let patchVersion of getBaseVersionAndPatches$(baseVersion) | async;\n            let i = index;\n            loadMore: 'auto'\n          \"\n        >\n          <c8y-li-radio\n            (onSelect)=\"selectVersionOrPatch($event, patchVersion)\"\n            [selected]=\"patchVersion === selected\"\n          ></c8y-li-radio>\n          <c8y-li-icon>\n            <i c8yIcon=\"c8y-firmware\"></i>\n          </c8y-li-icon>\n          <c8y-li-body class=\"content-flex-50\">\n            <div class=\"col-3\">\n              {{ patchVersion.c8y_Firmware.version }}\n            </div>\n            <div class=\"col-3\">\n              <span\n                class=\"label label-info\"\n                *ngIf=\"patchVersion.c8y_Patch; else version\"\n                translate\n              >\n                patch\n              </span>\n              <ng-template #version>\n                <span\n                  class=\"label label-primary\"\n                  translate\n                >\n                  version\n                </span>\n              </ng-template>\n            </div>\n            <div class=\"col-6 text-truncate\">\n              <span\n                class=\"text-label-small m-r-4\"\n                translate\n              >\n                File\n              </span>\n              <ng-container *ngIf=\"patchVersion.c8y_Firmware.url === '$PROVIDED'; else fileName\">\n                <span title=\"{{ 'Provided by device' | translate }}\">\n                  {{ 'Provided by device' | translate }}\n                </span>\n              </ng-container>\n              <ng-template #fileName>\n                <span title=\"{{ getBinaryName$(patchVersion.c8y_Firmware.url) | async }}\">\n                  {{ getBinaryName$(patchVersion.c8y_Firmware.url) | async }}\n                </span>\n              </ng-template>\n            </div>\n          </c8y-li-body>\n        </c8y-li>\n      </c8y-list-group>\n    </c8y-li-collapse>\n  </c8y-li>\n</c8y-list-group>\n" }]
        }], ctorParameters: () => [{ type: i1.RepositoryService }, { type: i2$1.InventoryService }, { type: i2.BulkOperationsService }], propDecorators: { selected: [{
                type: Input
            }], versionOrPatch: [{
                type: Output
            }], getBinaryName$: [], getBaseVersionAndPatches$: [], getPatchVersionsCount$: [] } });

class StepperBulkTypeFirmwareComponent extends BaseStepperComponent {
    constructor(bulkOperationService, translate) {
        super();
        this.bulkOperationService = bulkOperationService;
        this.translate = translate;
        this.type = BulkOperationType.FIRMWARE;
        this.descriptionTemplate = gettext('{{ name }} (version {{ version }})');
        this.textFilter$ = new BehaviorSubject('');
        this.stepData = {
            firmware: undefined,
            versionOrPatch: undefined
        };
    }
    goToVersionOrPatchStep({ stepper }) {
        const selectedFirmware = this.stepData.firmware;
        this.bulkOperationService.setFirmwareId(selectedFirmware.id);
        this.deviceTypes = (selectedFirmware.c8y_Filter || {}).type;
        stepper.next();
    }
    onVersionOrPatchSelected(versionOrPatch) {
        this.stepData.versionOrPatch = versionOrPatch;
    }
    onFirmwareSelected(fw) {
        this.stepData.firmware = fw;
    }
    ngOnDestroy() {
        if (this.subscription) {
            this.subscription.unsubscribe();
        }
    }
    retrieveOperationPrototype() {
        const selectedFirmware = this.stepData.firmware;
        const selectedVersionOrPatch = this.stepData.versionOrPatch;
        if (!selectedFirmware || !selectedVersionOrPatch) {
            return;
        }
        const firmware = {
            name: selectedFirmware.name,
            version: selectedVersionOrPatch.c8y_Firmware.version,
            url: selectedVersionOrPatch.c8y_Firmware.url
        };
        if (selectedVersionOrPatch.c8y_Patch) {
            firmware.isPatch = true;
            firmware.dependency = selectedVersionOrPatch.c8y_Patch.dependency;
        }
        const name = selectedFirmware.name;
        const version = selectedVersionOrPatch.c8y_Firmware.version;
        const description = `Update firmware to: ${name} (version: ${version}).`;
        return {
            name: gettext('Firmware update'),
            description: this.translate.instant(this.descriptionTemplate, {
                name: get(this.stepData, 'firmware.name'),
                version: get(this.stepData, 'versionOrPatch.c8y_Firmware.version')
            }),
            prototype: {
                description,
                c8y_Firmware: firmware
            }
        };
    }
    onSelectionChange(event) {
        this.textFilter$.next('');
        super.onSelectionChange(event);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: StepperBulkTypeFirmwareComponent, deps: [{ token: i2.BulkOperationsService }, { token: i3.TranslateService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.19", type: StepperBulkTypeFirmwareComponent, isStandalone: true, selector: "c8y-stepper-firmware", usesInheritance: true, ngImport: i0, template: "<c8y-bulk-operation-stepper [type]=\"type\">\n  <ng-container\n    *customStep=\"\n      'Select firmware' | translate;\n      completed: !!stepData?.firmware;\n      buttonsDisabled: !stepData?.firmware;\n      onNext: goToVersionOrPatchStep.bind(this)\n    \"\n  >\n    <c8y-select-firmware-step\n      [selected]=\"stepData?.firmware\"\n      (firmware)=\"onFirmwareSelected($event)\"\n      class=\"d-contents\"\n    ></c8y-select-firmware-step\n  ></ng-container>\n  <ng-container\n    *customStep=\"\n      'Select version or patch' | translate;\n      completed: !!stepData?.versionOrPatch;\n      buttonsDisabled: !stepData?.versionOrPatch\n    \"\n  >\n    <c8y-preview-selection-frame\n      [header]=\"'Select version or patch' | translate\"\n      [name]=\"stepData?.firmware?.name\"\n      [description]=\"stepData?.firmware?.description\"\n    >\n      <c8y-version-or-patch-step\n        list\n        [selected]=\"stepData?.versionOrPatch\"\n        (versionOrPatch)=\"onVersionOrPatchSelected($event)\"\n      >\n      </c8y-version-or-patch-step>\n    </c8y-preview-selection-frame>\n  </ng-container>\n</c8y-bulk-operation-stepper>\n", dependencies: [{ kind: "component", type: BulkOperationStepper, selector: "c8y-bulk-operation-stepper", inputs: ["type"], outputs: ["selectionChange"] }, { kind: "directive", type: CustomStep, selector: "[customStep]", inputs: ["customStep", "customStepCompleted", "customStepButtonsDisabled", "customStepOnNext"] }, { kind: "component", type: SelectFirmwareComponent, selector: "c8y-select-firmware-step", inputs: ["selected"], outputs: ["firmware"] }, { kind: "component", type: PreviewSelectionFrameComponent, selector: "c8y-preview-selection-frame", inputs: ["header", "name", "description", "type"] }, { kind: "component", type: VersionOrPatchComponent, selector: "c8y-version-or-patch-step", inputs: ["selected"], outputs: ["versionOrPatch"] }, { kind: "pipe", type: C8yTranslatePipe, name: "translate" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: StepperBulkTypeFirmwareComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-stepper-firmware', imports: [
                        BulkOperationStepper,
                        CustomStep,
                        SelectFirmwareComponent,
                        PreviewSelectionFrameComponent,
                        VersionOrPatchComponent,
                        C8yTranslatePipe
                    ], template: "<c8y-bulk-operation-stepper [type]=\"type\">\n  <ng-container\n    *customStep=\"\n      'Select firmware' | translate;\n      completed: !!stepData?.firmware;\n      buttonsDisabled: !stepData?.firmware;\n      onNext: goToVersionOrPatchStep.bind(this)\n    \"\n  >\n    <c8y-select-firmware-step\n      [selected]=\"stepData?.firmware\"\n      (firmware)=\"onFirmwareSelected($event)\"\n      class=\"d-contents\"\n    ></c8y-select-firmware-step\n  ></ng-container>\n  <ng-container\n    *customStep=\"\n      'Select version or patch' | translate;\n      completed: !!stepData?.versionOrPatch;\n      buttonsDisabled: !stepData?.versionOrPatch\n    \"\n  >\n    <c8y-preview-selection-frame\n      [header]=\"'Select version or patch' | translate\"\n      [name]=\"stepData?.firmware?.name\"\n      [description]=\"stepData?.firmware?.description\"\n    >\n      <c8y-version-or-patch-step\n        list\n        [selected]=\"stepData?.versionOrPatch\"\n        (versionOrPatch)=\"onVersionOrPatchSelected($event)\"\n      >\n      </c8y-version-or-patch-step>\n    </c8y-preview-selection-frame>\n  </ng-container>\n</c8y-bulk-operation-stepper>\n" }]
        }], ctorParameters: () => [{ type: i2.BulkOperationsService }, { type: i3.TranslateService }] });

/** Module for the 'Firmware update' operation type stepper */
class StepperBulkTypeFirmwareModule {
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: StepperBulkTypeFirmwareModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
    static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.3.19", ngImport: i0, type: StepperBulkTypeFirmwareModule, imports: [StepperBulkTypeFirmwareComponent, VersionOrPatchComponent, SelectFirmwareComponent], exports: [StepperBulkTypeFirmwareComponent] }); }
    static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: StepperBulkTypeFirmwareModule, providers: [
            hookListBulkType({
                type: BulkOperationType.FIRMWARE,
                c8yIcon: 'c8y-firmware',
                name: gettext('Firmware update'),
                path: `${baseUrl}firmware`,
                component: StepperBulkTypeFirmwareComponent,
                fragments: ['c8y_Firmware'],
                selected: false
            })
        ], imports: [StepperBulkTypeFirmwareComponent, VersionOrPatchComponent, SelectFirmwareComponent] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.19", ngImport: i0, type: StepperBulkTypeFirmwareModule, decorators: [{
            type: NgModule,
            args: [{
                    imports: [StepperBulkTypeFirmwareComponent, VersionOrPatchComponent, SelectFirmwareComponent],
                    providers: [
                        hookListBulkType({
                            type: BulkOperationType.FIRMWARE,
                            c8yIcon: 'c8y-firmware',
                            name: gettext('Firmware update'),
                            path: `${baseUrl}firmware`,
                            component: StepperBulkTypeFirmwareComponent,
                            fragments: ['c8y_Firmware'],
                            selected: false
                        })
                    ],
                    exports: [StepperBulkTypeFirmwareComponent]
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { SelectFirmwareComponent, StepperBulkTypeFirmwareComponent, StepperBulkTypeFirmwareModule, VersionOrPatchComponent };
//# sourceMappingURL=c8y-ngx-components-operations-stepper-bulk-type-firmware.mjs.map
