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 MicroserviceListComponent {
    constructor(ecosystemService, wizardService) {
        this.ecosystemService = ecosystemService;
        this.wizardService = wizardService;
        this.reloading = false;
        this.reload$ = new BehaviorSubject(null);
        this.microservices$ = this.reload$.pipe(tap(() => (this.reloading = true)), switchMap(() => this.ecosystemService.getMicroservices()), tap(() => (this.reloading = false)), shareReplay());
        this.isMicroserviceHostingAllowed$ = this.reload$.pipe(switchMap(() => this.ecosystemService.isMicroserviceHostingAllowed()), shareReplay());
    }
    ngOnInit() {
        this.loadMicroservices();
    }
    loadMicroservices() {
        this.reload$.next();
    }
    addMicroservice() {
        const initialState = {
            id: 'uploadMicroservice'
        };
        const modalOptions = { initialState };
        const modalRef = this.wizardService.show(modalOptions);
        modalRef.content.onClose.subscribe(() => {
            this.loadMicroservices();
        });
    }
}
MicroserviceListComponent.decorators = [
    { type: Component, args: [{
                selector: 'c8y-microservice-list',
                template: "<c8y-title>{{ 'Microservices' | 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]=\"'microchip'\"\n    [label]=\"'Microservices' | translate\"\n    [path]=\"'microservices'\"\n  ></c8y-breadcrumb-item>\n</c8y-breadcrumb>\n\n<c8y-action-bar-item\n  [placement]=\"'right'\"\n  [priority]=\"100\"\n  *ngIf=\"isMicroserviceHostingAllowed$ | async\"\n>\n  <button\n    (click)=\"addMicroservice()\"\n    class=\"btn btn-link\"\n    title=\"{{ 'Add microservice' | translate }}\"\n  >\n    <i c8yIcon=\"plus-circle\"></i>\n    {{ 'Add microservice' | translate }}\n  </button>\n</c8y-action-bar-item>\n\n<c8y-action-bar-item [placement]=\"'right'\">\n  <button (click)=\"reload$.next()\" 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]=\"(microservices$ | async)?.length\"\n  ></c8y-list-display-switch>\n</c8y-action-bar-item>\n\n<div *ngIf=\"(microservices$ | 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 microservices to display.</h3>\n  <p translate>Add your first microservice by clicking below.</p>\n  <p>\n    <button\n      (click)=\"addMicroservice()\"\n      class=\"btn btn-primary\"\n      title=\"{{ 'Add microservice' | translate }}\"\n    >\n      {{ 'Add microservice' | translate }}\n    </button>\n  </p>\n</div>\n\n<div [ngClass]=\"listClass\" class=\"card-group\">\n  <div\n    class=\"page-sticky-header hidden-xs flex-row\"\n    *ngIf=\"(microservices$ | 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      {{ 'Microservice' | 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\n    *ngFor=\"let microservice of microservices$ | async\"\n    class=\"col-xs-12 col-sm-4 col-md-3\"\n  >\n    <c8y-application-card\n      (onAppDeleted)=\"loadMicroservices()\"\n      [app]=\"microservice\"\n      class=\"d-contents\"\n    ></c8y-application-card>\n  </div>\n</div>\n"
            },] }
];
MicroserviceListComponent.ctorParameters = () => [
    { type: EcosystemService },
    { type: WizardService }
];
//# sourceMappingURL=data:application/json;base64, 