import { Component, Input } from '@angular/core';
import { ModalService } from '@c8y/ngx-components';
import { BehaviorSubject, combineLatest } from 'rxjs';
import { BsModalRef } from 'ngx-bootstrap/modal';
import { map } from 'rxjs/operators';
import { EcosystemService } from '@c8y/ngx-components/ecosystem/shared';
import * as i0 from "@angular/core";
import * as i1 from "ngx-bootstrap/modal";
import * as i2 from "@c8y/ngx-components";
import * as i3 from "@c8y/ngx-components/ecosystem/shared";
import * as i4 from "@angular/common";
import * as i5 from "@angular/forms";
import * as i6 from "./plugin-list.component";
import * as i7 from "./only-latest-plugin-version.pipe";
export class InstallPluginComponent {
    constructor(bsModalRef, modal, ecosystemService) {
        this.bsModalRef = bsModalRef;
        this.modal = modal;
        this.ecosystemService = ecosystemService;
        this.filterTerm$ = new BehaviorSubject('');
        this.filteredPlugins$ = new BehaviorSubject([]);
        this.selectedPlugins = [];
        this.result = new Promise((resolve, reject) => {
            this._install = resolve;
            this._cancel = reject;
        });
        this.onlyLatestPluginVersion = true;
    }
    ngOnInit() {
        this.filteredPlugins$ = combineLatest([this.plugins$, this.filterTerm$]).pipe(map(([plugins, filterTerm]) => filterTerm.trim().length === 0
            ? plugins
            : plugins.filter((plugin) => this.ecosystemService.filterContainString(plugin.name, filterTerm))));
    }
    cancel() {
        this.bsModalRef.hide();
        this._cancel();
    }
    install() {
        this._install(this.selectedPlugins);
        this.bsModalRef.hide();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: InstallPluginComponent, deps: [{ token: i1.BsModalRef }, { token: i2.ModalService }, { token: i3.EcosystemService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: InstallPluginComponent, selector: "c8y-install-plugin", inputs: { plugins$: "plugins$" }, ngImport: i0, template: "<div class=\"viewport-modal\">\n  <div class=\"modal-header dialog-header\">\n    <i [c8yIcon]=\"'plugin'\"></i>\n    <div id=\"modal-title\" class=\"modal-title h4\" translate>Available plugins</div>\n  </div>\n  <div class=\"p-t-8 p-16 text-center separator-bottom flex-no-shrink\">\n    <p class=\"text-medium m-b-8\" translate>Select the compatible plugins to install</p>\n    <label class=\"c8y-switch\">\n      <input type=\"checkbox\" [(ngModel)]=\"onlyLatestPluginVersion\" />\n      <span></span>\n      <span translate>Only latest version of plugins</span>\n    </label>\n    <c8y-filter (onSearch)=\"this.filterTerm$.next($event)\"></c8y-filter>\n  </div>\n  <div class=\"modal-inner-scroll\" id=\"modal-body\">\n    <c8y-plugin-list\n      (selectedItems)=\"selectedPlugins = $event\"\n      [emptyListText]=\"'No plugins available' | translate\"\n      [plugins$]=\"filteredPlugins$ | onlyLatestPluginVersion: !onlyLatestPluginVersion\"\n      [selectable]=\"true\"\n      class=\"m-t-16\"\n    ></c8y-plugin-list>\n  </div>\n\n  <div class=\"modal-footer\">\n    <button\n      (click)=\"cancel()\"\n      class=\"btn btn-default\"\n      title=\"{{ 'Cancel' | translate }}\"\n      data-cy=\"install-plugin--cancel-button\"\n      type=\"button\"\n    >\n      {{ 'Cancel' | translate }}\n    </button>\n    <button\n      (click)=\"install()\"\n      [disabled]=\"selectedPlugins.length === 0\"\n      class=\"btn btn-primary\"\n      title=\"{{ 'Install' | translate }}\"\n      data-cy=\"install-plugin--install-button\"\n      type=\"button\"\n    >\n      {{ 'Install' | translate }}\n      <span class=\"badge\" *ngIf=\"selectedPlugins.length as length\">{{ length }}</span>\n    </button>\n  </div>\n</div>\n", dependencies: [{ kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i2.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i4.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i5.CheckboxControlValueAccessor, selector: "input[type=checkbox][formControlName],input[type=checkbox][formControl],input[type=checkbox][ngModel]" }, { kind: "directive", type: i5.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i5.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "component", type: i2.FilterInputComponent, selector: "c8y-filter", inputs: ["icon"], outputs: ["onSearch"] }, { kind: "component", type: i6.PluginListComponent, selector: "c8y-plugin-list", inputs: ["plugins$", "emptyListText", "selectable", "hideSource", "installable", "package"], outputs: ["selectedItems"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i7.OnlyLatestPluginVersionPipe, name: "onlyLatestPluginVersion" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: InstallPluginComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-install-plugin', template: "<div class=\"viewport-modal\">\n  <div class=\"modal-header dialog-header\">\n    <i [c8yIcon]=\"'plugin'\"></i>\n    <div id=\"modal-title\" class=\"modal-title h4\" translate>Available plugins</div>\n  </div>\n  <div class=\"p-t-8 p-16 text-center separator-bottom flex-no-shrink\">\n    <p class=\"text-medium m-b-8\" translate>Select the compatible plugins to install</p>\n    <label class=\"c8y-switch\">\n      <input type=\"checkbox\" [(ngModel)]=\"onlyLatestPluginVersion\" />\n      <span></span>\n      <span translate>Only latest version of plugins</span>\n    </label>\n    <c8y-filter (onSearch)=\"this.filterTerm$.next($event)\"></c8y-filter>\n  </div>\n  <div class=\"modal-inner-scroll\" id=\"modal-body\">\n    <c8y-plugin-list\n      (selectedItems)=\"selectedPlugins = $event\"\n      [emptyListText]=\"'No plugins available' | translate\"\n      [plugins$]=\"filteredPlugins$ | onlyLatestPluginVersion: !onlyLatestPluginVersion\"\n      [selectable]=\"true\"\n      class=\"m-t-16\"\n    ></c8y-plugin-list>\n  </div>\n\n  <div class=\"modal-footer\">\n    <button\n      (click)=\"cancel()\"\n      class=\"btn btn-default\"\n      title=\"{{ 'Cancel' | translate }}\"\n      data-cy=\"install-plugin--cancel-button\"\n      type=\"button\"\n    >\n      {{ 'Cancel' | translate }}\n    </button>\n    <button\n      (click)=\"install()\"\n      [disabled]=\"selectedPlugins.length === 0\"\n      class=\"btn btn-primary\"\n      title=\"{{ 'Install' | translate }}\"\n      data-cy=\"install-plugin--install-button\"\n      type=\"button\"\n    >\n      {{ 'Install' | translate }}\n      <span class=\"badge\" *ngIf=\"selectedPlugins.length as length\">{{ length }}</span>\n    </button>\n  </div>\n</div>\n" }]
        }], ctorParameters: () => [{ type: i1.BsModalRef }, { type: i2.ModalService }, { type: i3.EcosystemService }], propDecorators: { plugins$: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 