import { Component, Input } from '@angular/core';
import { BottomDrawerRef, PluginsService } from '@c8y/ngx-components';
import { defaultPackageTypes, EcosystemService } from '@c8y/ngx-components/ecosystem/shared';
import { BehaviorSubject, map, Observable } from 'rxjs';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components";
import * as i2 from "@c8y/ngx-components/ecosystem/shared";
import * as i3 from "@angular/common";
import * as i4 from "./plugin-list.component";
import * as i5 from "./only-latest-filter/only-latest-filter.component";
export class InstallPluginComponent {
    constructor(bottomDrawerRef, ecosystemService, pluginsService) {
        this.bottomDrawerRef = bottomDrawerRef;
        this.ecosystemService = ecosystemService;
        this.pluginsService = pluginsService;
        this.filteredPlugins$ = new BehaviorSubject([]);
        this.selectedPlugins = [];
        this.packageTypes = defaultPackageTypes;
        this.result = new Promise((resolve, reject) => {
            this._install = resolve;
            this._cancel = reject;
        });
        this.onlyLatestPluginVersion = true;
    }
    setFilterPipe(filterPipe) {
        this.filteredPlugins$ = this.plugins$.pipe(map(plugins => plugins.map(plugin => {
            plugin.filterProps = this.ecosystemService.getAppFilterProps(plugin.originApp);
            return plugin;
        })), src => filterPipe(src));
    }
    cancel() {
        this.bottomDrawerRef.close();
        this._cancel();
    }
    install() {
        this._install(this.selectedPlugins);
        this.bottomDrawerRef.close();
    }
    async showPluginOverview(plugin) {
        this.selectedPlugin = plugin;
        const baseUrl = `/apps/${plugin.id}/`;
        this.pluginBaseUrl = baseUrl;
        this.pluginMarkdown = await this.pluginsService.getReadmeFileContent(baseUrl);
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: InstallPluginComponent, deps: [{ token: i1.BottomDrawerRef }, { token: i2.EcosystemService }, { token: i1.PluginsService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.13", type: InstallPluginComponent, selector: "c8y-install-plugin", inputs: { plugins$: "plugins$" }, host: { classAttribute: "d-contents" }, ngImport: i0, template: "  <div class=\"card-header gap-8 d-col p-l-24 p-r-24 separator-bottom flex-no-shrink\">\n    <div\n      class=\"card-title h4 text-center\"\n      translate\n    >\n      Available plugins\n    </div>\n    <c8y-list-filters\n      (filterPipeChange)=\"setFilterPipe($event)\"\n      [packageTypes]=\"packageTypes\"\n    >\n      <c8y-archived-filter></c8y-archived-filter>\n      <c8y-only-latest-filter></c8y-only-latest-filter>\n    </c8y-list-filters>\n  </div>\n  <div class=\"d-grid grid__col--5-7--md min-height-0 flex-grow\">\n    <c8y-plugin-list\n      class=\"inner-scroll bg-level-1\"\n      (selectedItems)=\"selectedPlugins = $event\"\n      [emptyListText]=\"'No matching plugins' | translate\"\n      [plugins$]=\"filteredPlugins$\"\n      [selectable]=\"true\"\n      [selectedPlugin]=\"selectedPlugin\"\n      (showOverview)=\"showPluginOverview($event)\"\n    ></c8y-plugin-list>\n    <div class=\"inner-scroll bg-component\">\n      <div class=\"card-header separator sticky-top bg-inherit\"\n        *ngIf=\"pluginMarkdown\">\n        <button\n          class=\"m-l-auto btn-clean\"\n          title=\"{{ 'Close' | translate }}\"\n          type=\"button\"\n          (click)=\"selectedPlugin = null; pluginMarkdown = null\"\n        >\n          <i c8yIcon=\"times\"></i>\n        </button>\n      </div>\n      <div class=\"card-block p-l-24 p-r-24\">\n        <div\n          class=\"markdown-content\"\n          *ngIf=\"pluginMarkdown\"\n          [innerHTML]=\"pluginMarkdown | markdownToHtml: { baseUrl: pluginBaseUrl } | async\"\n        ></div>\n        <c8y-ui-empty-state\n          [icon]=\"'user-manual'\"\n          [title]=\"'No plugin selected' | translate\"\n          [subtitle]=\"\n            'Select a plugin from the list to view its documentation.' | translate\"\n          *ngIf=\"!pluginMarkdown\"\n          [horizontal]=\"true\"\n        >\n          <p>\n            <small >\n              {{ 'Documentation availability varies by plugin.' | translate }}\n            </small>\n          </p>\n       </c8y-ui-empty-state>\n      </div>\n    </div>\n  </div>\n  <div class=\"text-center card-footer p-24 separator\">\n    <button\n      class=\"btn btn-default\"\n      title=\"{{ 'Cancel' | translate }}\"\n      type=\"button\"\n      (click)=\"cancel()\"\n      data-cy=\"install-plugin--cancel-button\"\n    >\n      {{ 'Cancel' | translate }}\n    </button>\n    <button\n      class=\"btn btn-primary\"\n      title=\"{{ 'Install' | translate }}\"\n      type=\"button\"\n      (click)=\"install()\"\n      [disabled]=\"selectedPlugins.length === 0\"\n      data-cy=\"install-plugin--install-button\"\n    >\n      {{ 'Install' | translate }}\n      <span\n        class=\"badge\"\n        *ngIf=\"selectedPlugins.length as length\"\n      >\n        {{ length }}\n      </span>\n    </button>\n  </div>\n\n", dependencies: [{ kind: "component", type: i1.EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: i1.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i1.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i2.ListFiltersComponent, selector: "c8y-list-filters", inputs: ["packageTypes", "packageAvailabilities", "packageContents"], outputs: ["filterPipeChange"] }, { kind: "component", type: i2.ArchivedFilterComponent, selector: "c8y-archived-filter" }, { kind: "component", type: i4.PluginListComponent, selector: "c8y-plugin-list", inputs: ["plugins$", "emptyListText", "selectable", "hideSource", "installable", "package", "selectedPlugin"], outputs: ["selectedItems", "showOverview"] }, { kind: "component", type: i5.OnlyLatestFilterComponent, selector: "c8y-only-latest-filter" }, { kind: "pipe", type: i1.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i3.AsyncPipe, name: "async" }, { kind: "pipe", type: i1.MarkdownToHtmlPipe, name: "markdownToHtml" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: InstallPluginComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-install-plugin', host: { class: 'd-contents' }, template: "  <div class=\"card-header gap-8 d-col p-l-24 p-r-24 separator-bottom flex-no-shrink\">\n    <div\n      class=\"card-title h4 text-center\"\n      translate\n    >\n      Available plugins\n    </div>\n    <c8y-list-filters\n      (filterPipeChange)=\"setFilterPipe($event)\"\n      [packageTypes]=\"packageTypes\"\n    >\n      <c8y-archived-filter></c8y-archived-filter>\n      <c8y-only-latest-filter></c8y-only-latest-filter>\n    </c8y-list-filters>\n  </div>\n  <div class=\"d-grid grid__col--5-7--md min-height-0 flex-grow\">\n    <c8y-plugin-list\n      class=\"inner-scroll bg-level-1\"\n      (selectedItems)=\"selectedPlugins = $event\"\n      [emptyListText]=\"'No matching plugins' | translate\"\n      [plugins$]=\"filteredPlugins$\"\n      [selectable]=\"true\"\n      [selectedPlugin]=\"selectedPlugin\"\n      (showOverview)=\"showPluginOverview($event)\"\n    ></c8y-plugin-list>\n    <div class=\"inner-scroll bg-component\">\n      <div class=\"card-header separator sticky-top bg-inherit\"\n        *ngIf=\"pluginMarkdown\">\n        <button\n          class=\"m-l-auto btn-clean\"\n          title=\"{{ 'Close' | translate }}\"\n          type=\"button\"\n          (click)=\"selectedPlugin = null; pluginMarkdown = null\"\n        >\n          <i c8yIcon=\"times\"></i>\n        </button>\n      </div>\n      <div class=\"card-block p-l-24 p-r-24\">\n        <div\n          class=\"markdown-content\"\n          *ngIf=\"pluginMarkdown\"\n          [innerHTML]=\"pluginMarkdown | markdownToHtml: { baseUrl: pluginBaseUrl } | async\"\n        ></div>\n        <c8y-ui-empty-state\n          [icon]=\"'user-manual'\"\n          [title]=\"'No plugin selected' | translate\"\n          [subtitle]=\"\n            'Select a plugin from the list to view its documentation.' | translate\"\n          *ngIf=\"!pluginMarkdown\"\n          [horizontal]=\"true\"\n        >\n          <p>\n            <small >\n              {{ 'Documentation availability varies by plugin.' | translate }}\n            </small>\n          </p>\n       </c8y-ui-empty-state>\n      </div>\n    </div>\n  </div>\n  <div class=\"text-center card-footer p-24 separator\">\n    <button\n      class=\"btn btn-default\"\n      title=\"{{ 'Cancel' | translate }}\"\n      type=\"button\"\n      (click)=\"cancel()\"\n      data-cy=\"install-plugin--cancel-button\"\n    >\n      {{ 'Cancel' | translate }}\n    </button>\n    <button\n      class=\"btn btn-primary\"\n      title=\"{{ 'Install' | translate }}\"\n      type=\"button\"\n      (click)=\"install()\"\n      [disabled]=\"selectedPlugins.length === 0\"\n      data-cy=\"install-plugin--install-button\"\n    >\n      {{ 'Install' | translate }}\n      <span\n        class=\"badge\"\n        *ngIf=\"selectedPlugins.length as length\"\n      >\n        {{ length }}\n      </span>\n    </button>\n  </div>\n\n" }]
        }], ctorParameters: () => [{ type: i1.BottomDrawerRef }, { type: i2.EcosystemService }, { type: i1.PluginsService }], propDecorators: { plugins$: [{
                type: Input
            }] } });
//# sourceMappingURL=data:application/json;base64, 