import { Component, ViewChild } from '@angular/core';
import { WizardModalService } from '@c8y/ngx-components';
import { BehaviorSubject, Subject } from 'rxjs';
import { shareReplay, switchMap, takeUntil, tap } from 'rxjs/operators';
import { EcosystemService, EcosystemWizards, defaultPackageAvailabilities, ListFiltersComponent } from '@c8y/ngx-components/ecosystem/shared';
import * as i0 from "@angular/core";
import * as i1 from "@c8y/ngx-components/ecosystem/shared";
import * as i2 from "@c8y/ngx-components";
import * as i3 from "@angular/common";
export class ApplicationListComponent {
    constructor(ecosystemService, wizardModalService) {
        this.ecosystemService = ecosystemService;
        this.wizardModalService = wizardModalService;
        this.reloading = false;
        this.reload$ = new BehaviorSubject(null);
        this.apps$ = this.reload$.pipe(tap(() => (this.reloading = true)), switchMap(() => this.ecosystemService.getWebApplications()), tap(apps => {
            apps.forEach(app => {
                app.filterProps = this.ecosystemService.getAppFilterProps(app);
            });
        }), tap(() => (this.reloading = false)), shareReplay());
        this.packageAvailabilities = defaultPackageAvailabilities;
        this.destroy$ = new Subject();
    }
    ngOnInit() {
        this.loadApplications();
    }
    loadApplications() {
        this.reload$.next();
    }
    addApplication() {
        const wizardConfig = {
            headerText: 'Add Application',
            headerIcon: 'c8y-atom'
        };
        const initialState = {
            wizardConfig,
            id: EcosystemWizards.APPLICATION_UPLOAD
        };
        const modalOptions = { initialState };
        const modalRef = this.wizardModalService.show(modalOptions);
        modalRef.content.onClose.pipe(takeUntil(this.destroy$)).subscribe(() => {
            this.loadApplications();
        });
    }
    ngOnDestroy() {
        this.destroy$.next();
        this.destroy$.complete();
    }
    setFilterPipe(pipe) {
        this.filteredApps$ = this.apps$.pipe(src => pipe(src));
    }
    resetFilters() {
        this.filtersComponent.resetAllFilters();
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: ApplicationListComponent, deps: [{ token: i1.EcosystemService }, { token: i2.WizardModalService }], target: i0.ɵɵFactoryTarget.Component }); }
    static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "18.2.9", type: ApplicationListComponent, selector: "c8y-application-list", viewQueries: [{ propertyName: "filtersComponent", first: true, predicate: ListFiltersComponent, descendants: true }], ngImport: i0, template: "<c8y-title>{{ 'Applications' | translate }}</c8y-title>\n\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-atom'\"\n    [label]=\"'Ecosystem' | translate\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-modules'\"\n    [label]=\"'Applications' | translate\"\n    [path]=\"'ecosystem/application/applications'\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<c8y-action-bar-item\n  [placement]=\"'right'\"\n  *c8yIfAllowed=\"['ROLE_APPLICATION_MANAGEMENT_ADMIN']\"\n>\n  <button\n    class=\"btn btn-link\"\n    title=\"{{ 'Add application' | translate }}\"\n    (click)=\"addApplication()\"\n  >\n    <i c8yIcon=\"plus-circle\"></i>\n    {{ 'Add application' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    title=\"{{ 'Reload' | translate }}\"\n    (click)=\"loadApplications()\"\n  >\n    <i\n      c8yIcon=\"refresh\"\n      [ngClass]=\"{ 'icon-spin': reloading }\"\n    ></i>\n    {{ 'Reload' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'left'\">\n  <c8y-list-filters\n    *ngIf=\"apps$ | async\"\n    (filterPipeChange)=\"setFilterPipe($event)\"\n    [packageAvailabilities]=\"packageAvailabilities\"\n  ></c8y-list-filters>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item\n  [placement]=\"'left'\"\n  itemClass=\"navbar-form hidden-xs\"\n>\n  <c8y-list-display-switch\n    (onListClassChange)=\"listClass = $event\"\n    [listLength]=\"(apps$ | async)?.length\"\n  ></c8y-list-display-switch>\n</c8y-action-bar-item>\n\n<c8y-help src=\"/docs/standard-tenant/ecosystem/#managing-applications\"></c8y-help>\n\n<div\n  class=\"c8y-empty-state text-center\"\n  *ngIf=\"(apps$ | async)?.length === 0\"\n>\n  <h1 class=\"c8y-icon c8y-icon-modules c8y-icon-duocolor\"></h1>\n  <h3 translate>No applications to display.</h3>\n  <p translate>Add your first application by clicking below.</p>\n  <p>\n    <button\n      class=\"btn btn-primary\"\n      title=\"{{ 'Add application' | translate }}\"\n      (click)=\"addApplication()\"\n    >\n      {{ 'Add application' | translate }}\n    </button>\n  </p>\n</div>\n\n<div\n  class=\"card-group\"\n  [ngClass]=\"listClass\"\n>\n  <div\n    class=\"page-sticky-header hidden-xs d-flex\"\n    *ngIf=\"(apps$ | async)?.length > 0\"\n  >\n    <div class=\"card-block card-column-40\">\n      <div class=\"card-appicon p-l-32 p-r-16 m-r-0 m-l-4\"></div>\n      {{ 'Application' | translate }}\n    </div>\n    <div class=\"card-block p-0 card-column-80 m-r-40\">\n      <div class=\"card-block card-column-80\">{{ 'Description' | translate }}</div>\n      <div class=\"card-block card-column-20\">{{ 'Type' | translate }}</div>\n      <div class=\"card-block card-column-20\"></div>\n    </div>\n  </div>\n  <div\n    class=\"col-xs-12 col-sm-4 col-md-3\"\n    *ngFor=\"let app of filteredApps$ | async\"\n  >\n    <c8y-application-card\n      class=\"d-contents\"\n      (onAppDeleted)=\"loadApplications()\"\n      (onAppCloned)=\"loadApplications()\"\n      [app]=\"app\"\n    ></c8y-application-card>\n  </div>\n</div>\n\n<c8y-ui-empty-state\n  [icon]=\"'search'\"\n  [title]=\"'No matching applications.' | translate\"\n  [subtitle]=\"'Refine your search terms and/or the filters' | translate\"\n  *ngIf=\"(apps$ | async)?.length > 0 && (filteredApps$ | async)?.length === 0\"\n>\n  <button\n    class=\"btn btn-primary\"\n    title=\"{{ 'Reset filters' | translate }}\"\n    type=\"button\"\n    (click)=\"resetFilters()\"\n  >\n    {{ 'Reset filters' | translate }}\n  </button>\n</c8y-ui-empty-state>\n", dependencies: [{ kind: "component", type: i2.ActionBarItemComponent, selector: "c8y-action-bar-item", inputs: ["placement", "priority", "itemClass", "injector", "groupId", "inGroupPriority"] }, { kind: "component", type: i2.BreadcrumbComponent, selector: "c8y-breadcrumb" }, { kind: "component", type: i2.BreadcrumbItemComponent, selector: "c8y-breadcrumb-item", inputs: ["icon", "translate", "label", "path", "injector"] }, { kind: "component", type: i2.EmptyStateComponent, selector: "c8y-ui-empty-state", inputs: ["icon", "title", "subtitle", "horizontal"] }, { kind: "directive", type: i2.IconDirective, selector: "[c8yIcon]", inputs: ["c8yIcon"] }, { kind: "directive", type: i2.C8yTranslateDirective, selector: "[translate],[ngx-translate]" }, { kind: "directive", type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.IfAllowedDirective, selector: "[c8yIfAllowed]", inputs: ["c8yIfAllowed", "c8yIfAllowedAllowAny"] }, { kind: "component", type: i2.TitleComponent, selector: "c8y-title", inputs: ["pageTitleUpdate"] }, { kind: "component", type: i2.HelpComponent, selector: "c8y-help", inputs: ["src", "isCollapsed", "priority", "icon"] }, { kind: "component", type: i2.ListDisplaySwitchComponent, selector: "c8y-list-display-switch", inputs: ["listKey", "listLength", "filterPipe"], outputs: ["onListClassChange"] }, { kind: "component", type: i1.ApplicationCardComponent, selector: "c8y-application-card", inputs: ["app", "canEdit"], outputs: ["onAppDeleted", "onAppCloned"] }, { kind: "component", type: i1.ListFiltersComponent, selector: "c8y-list-filters", inputs: ["packageTypes", "packageAvailabilities", "packageContents"], outputs: ["filterPipeChange"] }, { kind: "pipe", type: i2.C8yTranslatePipe, name: "translate" }, { kind: "pipe", type: i3.AsyncPipe, name: "async" }] }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.9", ngImport: i0, type: ApplicationListComponent, decorators: [{
            type: Component,
            args: [{ selector: 'c8y-application-list', template: "<c8y-title>{{ 'Applications' | translate }}</c8y-title>\n\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-atom'\"\n    [label]=\"'Ecosystem' | translate\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-modules'\"\n    [label]=\"'Applications' | translate\"\n    [path]=\"'ecosystem/application/applications'\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<c8y-action-bar-item\n  [placement]=\"'right'\"\n  *c8yIfAllowed=\"['ROLE_APPLICATION_MANAGEMENT_ADMIN']\"\n>\n  <button\n    class=\"btn btn-link\"\n    title=\"{{ 'Add application' | translate }}\"\n    (click)=\"addApplication()\"\n  >\n    <i c8yIcon=\"plus-circle\"></i>\n    {{ 'Add application' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    class=\"btn btn-link\"\n    title=\"{{ 'Reload' | translate }}\"\n    (click)=\"loadApplications()\"\n  >\n    <i\n      c8yIcon=\"refresh\"\n      [ngClass]=\"{ 'icon-spin': reloading }\"\n    ></i>\n    {{ 'Reload' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'left'\">\n  <c8y-list-filters\n    *ngIf=\"apps$ | async\"\n    (filterPipeChange)=\"setFilterPipe($event)\"\n    [packageAvailabilities]=\"packageAvailabilities\"\n  ></c8y-list-filters>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item\n  [placement]=\"'left'\"\n  itemClass=\"navbar-form hidden-xs\"\n>\n  <c8y-list-display-switch\n    (onListClassChange)=\"listClass = $event\"\n    [listLength]=\"(apps$ | async)?.length\"\n  ></c8y-list-display-switch>\n</c8y-action-bar-item>\n\n<c8y-help src=\"/docs/standard-tenant/ecosystem/#managing-applications\"></c8y-help>\n\n<div\n  class=\"c8y-empty-state text-center\"\n  *ngIf=\"(apps$ | async)?.length === 0\"\n>\n  <h1 class=\"c8y-icon c8y-icon-modules c8y-icon-duocolor\"></h1>\n  <h3 translate>No applications to display.</h3>\n  <p translate>Add your first application by clicking below.</p>\n  <p>\n    <button\n      class=\"btn btn-primary\"\n      title=\"{{ 'Add application' | translate }}\"\n      (click)=\"addApplication()\"\n    >\n      {{ 'Add application' | translate }}\n    </button>\n  </p>\n</div>\n\n<div\n  class=\"card-group\"\n  [ngClass]=\"listClass\"\n>\n  <div\n    class=\"page-sticky-header hidden-xs d-flex\"\n    *ngIf=\"(apps$ | async)?.length > 0\"\n  >\n    <div class=\"card-block card-column-40\">\n      <div class=\"card-appicon p-l-32 p-r-16 m-r-0 m-l-4\"></div>\n      {{ 'Application' | translate }}\n    </div>\n    <div class=\"card-block p-0 card-column-80 m-r-40\">\n      <div class=\"card-block card-column-80\">{{ 'Description' | translate }}</div>\n      <div class=\"card-block card-column-20\">{{ 'Type' | translate }}</div>\n      <div class=\"card-block card-column-20\"></div>\n    </div>\n  </div>\n  <div\n    class=\"col-xs-12 col-sm-4 col-md-3\"\n    *ngFor=\"let app of filteredApps$ | async\"\n  >\n    <c8y-application-card\n      class=\"d-contents\"\n      (onAppDeleted)=\"loadApplications()\"\n      (onAppCloned)=\"loadApplications()\"\n      [app]=\"app\"\n    ></c8y-application-card>\n  </div>\n</div>\n\n<c8y-ui-empty-state\n  [icon]=\"'search'\"\n  [title]=\"'No matching applications.' | translate\"\n  [subtitle]=\"'Refine your search terms and/or the filters' | translate\"\n  *ngIf=\"(apps$ | async)?.length > 0 && (filteredApps$ | async)?.length === 0\"\n>\n  <button\n    class=\"btn btn-primary\"\n    title=\"{{ 'Reset filters' | translate }}\"\n    type=\"button\"\n    (click)=\"resetFilters()\"\n  >\n    {{ 'Reset filters' | translate }}\n  </button>\n</c8y-ui-empty-state>\n" }]
        }], ctorParameters: () => [{ type: i1.EcosystemService }, { type: i2.WizardModalService }], propDecorators: { filtersComponent: [{
                type: ViewChild,
                args: [ListFiltersComponent]
            }] } });
//# sourceMappingURL=data:application/json;base64, 