import { __decorate, __metadata } from "tslib";
import { Component, Output, EventEmitter, Input } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { debounceTime, distinctUntilChanged, tap, switchMap, shareReplay } from 'rxjs/operators';
import { memoize } from '@c8y/ngx-components';
import { RepositoryService, RepositoryType } from '@c8y/ngx-components/repository/shared';
import { gettext } from '@c8y/ngx-components';
import { TranslateService } from '@ngx-translate/core';
import { property, get } from 'lodash-es';
import { BulkOperationsService } from '@c8y/ngx-components/operations/bulk-operations-service';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components/repository/shared";
import * as i2 from "@c8y/ngx-components/operations/bulk-operations-service";
import * as i3 from "@ngx-translate/core";
import * as i4 from "@c8y/ngx-components";
import * as i5 from "@angular/common";
import * as i6 from "@angular/forms";
import * as i7 from "@c8y/ngx-components/operations/stepper-frames";
export 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: "18.2.13", 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: "18.2.13", type: SelectFirmwareComponent, 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: "directive", type: i4.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i4.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i5.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.NgPlural, selector: "[ngPlural]", inputs: ["ngPlural"] }, { kind: "directive", type: i5.NgPluralCase, selector: "[ngPluralCase]" }, { kind: "directive", type: i4.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: i4.HighlightComponent, selector: "c8y-highlight", inputs: ["pattern", "text", "elementClass", "shouldTrimPattern"] }, { kind: "directive", type: i6.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: i6.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i6.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i4.ListGroupComponent, selector: "c8y-list-group" }, { kind: "component", type: i4.ListItemComponent, selector: "c8y-list-item, c8y-li", inputs: ["active", "highlighted", "emptyActions", "dense", "collapsed", "selectable"], outputs: ["collapsedChange"] }, { kind: "component", type: i4.ListItemIconComponent, selector: "c8y-list-item-icon, c8y-li-icon", inputs: ["icon", "status"] }, { kind: "component", type: i4.ListItemBodyComponent, selector: "c8y-list-item-body, c8y-li-body", inputs: ["body"] }, { kind: "component", type: i4.ListItemRadioComponent, selector: "c8y-list-item-radio, c8y-li-radio", inputs: ["selected", "name", "disabled", "value"], outputs: ["onSelect"] }, { kind: "component", type: i7.SelectStepFrameComponent, selector: "c8y-select-step-frame", inputs: ["header", "noResults"] }, { kind: "pipe", type: i4.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i5.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: "18.2.13", ngImport: i0, type: SelectFirmwareComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-select-firmware-step', 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$: [] } });
//# sourceMappingURL=data:application/json;base64, 