import { Component } from '@angular/core';
import { WizardService } from '@c8y/ngx-components';
import { BehaviorSubject } from 'rxjs';
import { shareReplay, switchMap, tap } from 'rxjs/operators';
import { EcosystemService } from './../../ecosystem.service';
export class ApplicationListComponent {
    constructor(ecosystemService, wizardService) {
        this.ecosystemService = ecosystemService;
        this.wizardService = wizardService;
        this.reloading = false;
        this.reload$ = new BehaviorSubject(null);
        this.apps$ = this.reload$.pipe(tap(() => (this.reloading = true)), switchMap(() => this.ecosystemService.getWebApplications()), tap(() => (this.reloading = false)), shareReplay());
    }
    ngOnInit() {
        this.loadApplications();
    }
    loadApplications() {
        this.reload$.next();
    }
    addApplication() {
        const wizardConfig = {
            headerText: 'Add Application',
            headerIcon: 'c8y-atom'
        };
        const initialState = {
            wizardConfig,
            id: 'uploadApplication'
        };
        const modalOptions = { initialState };
        const modalRef = this.wizardService.show(modalOptions);
        modalRef.content.onClose.subscribe(() => {
            this.loadApplications();
        });
    }
}
ApplicationListComponent.decorators = [
    { type: Component, args: [{
                selector: 'c8y-application-list',
                template: "<c8y-title>{{ 'All applications' | translate }}</c8y-title>\n\n<c8y-breadcrumb>\n  <c8y-breadcrumb-item [icon]=\"'c8y-atom'\" [label]=\"'Ecosystem' | translate\"></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-modules'\"\n    [label]=\"'Applications' | translate\"\n    [path]=\"'ecosystem/applications'\"\n  ></c8y-breadcrumb-item>\n  <c8y-breadcrumb-item\n    [icon]=\"'c8y-modules'\"\n    [label]=\"'All applications' | translate\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button\n    (click)=\"addApplication()\"\n    class=\"btn btn-link\"\n    title=\"{{ 'Add application' | translate }}\"\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 (click)=\"loadApplications()\" class=\"btn btn-link\" title=\"{{ 'Reload' | translate }}\">\n    <i [ngClass]=\"{ 'icon-spin': reloading }\" c8yIcon=\"refresh\"></i>\n    {{ 'Reload' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'left'\" itemClass=\"navbar-form hidden-xs\">\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<div *ngIf=\"(apps$ | async)?.length === 0\" class=\"c8y-empty-state text-center\">\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      (click)=\"addApplication()\"\n      class=\"btn btn-primary\"\n      title=\"{{ 'Add application' | translate }}\"\n    >\n      {{ 'Add application' | translate }}\n    </button>\n  </p>\n</div>\n\n<div [ngClass]=\"listClass\" class=\"card-group\">\n  <div class=\"page-sticky-header hidden-xs flex-row\" *ngIf=\"(apps$ | async)?.length > 0\">\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\">\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 *ngFor=\"let app of apps$ | async\" class=\"col-xs-12 col-sm-4 col-md-3\">\n    <c8y-application-card\n      (onAppDeleted)=\"loadApplications()\"\n      [app]=\"app\"\n      class=\"d-contents\"\n    ></c8y-application-card>\n  </div>\n</div>\n"
            },] }
];
ApplicationListComponent.ctorParameters = () => [
    { type: EcosystemService },
    { type: WizardService }
];
//# sourceMappingURL=data:application/json;base64, 