import * as i0 from '@angular/core';
import { Pipe, Component, Input, NgModule } from '@angular/core';
import { Subject, NEVER } from 'rxjs';
import { takeUntil, switchMap, map, share } from 'rxjs/operators';
import * as i1 from '@angular/common';
import { CommonModule } from '@angular/common';
import * as i1$1 from '@ionic/angular';
import { IonicModule } from '@ionic/angular';
import { TapConfiguratorWriter } from '@iotize/tap/configurator';

class TapConfiguratorStepTitlePipe {
    transform(data) {
        switch (data?.step) {
            case TapConfiguratorWriter.Step.applyConfig:
                return `Appling configuration`;
            case TapConfiguratorWriter.Step.enableSecureCom:
                return `Enabling secure communication`;
            case TapConfiguratorWriter.Step.executeCall:
                return `Writing configuration`;
            case TapConfiguratorWriter.Step.factoryReset:
                return `Clearing configuration`;
            case TapConfiguratorWriter.Step.logout:
                return `User logout`;
            case TapConfiguratorWriter.Step.validatesConfig:
                return `Validating configuration`;
            case TapConfiguratorWriter.Step.writeSecurityOptions:
                return `Writing security options`;
        }
    }
}
/** @nocollapse */ TapConfiguratorStepTitlePipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorStepTitlePipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
/** @nocollapse */ TapConfiguratorStepTitlePipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorStepTitlePipe, name: "tapConfiguratorStepTitle" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorStepTitlePipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'tapConfiguratorStepTitle',
                }]
        }] });

class TapConfiguratorProgressBarComponent {
    constructor() {
        this._eventsStream = new Subject();
        this.destroyed = new Subject();
        this._progressEventStream = this._eventsStream.pipe(takeUntil(this.destroyed), switchMap((stream) => {
            console.log('TapConfiguratorProgressBarComponent EVENT STREAM UPDATE', stream);
            if (stream === undefined) {
                return NEVER;
            }
            else {
                return stream.pipe(map((event) => {
                    const progress = event.progress;
                    const percent = progress ? progress.loaded / progress.total : 0;
                    const step = event.step;
                    return {
                        percent,
                        step,
                    };
                    // switch (event.step) {
                    //   case TapConfiguratorWriter.Step.applyConfig:
                    //     return undefined;
                    //     case TapConfiguratorWriter.Step.executeCall:
                    //       return {
                    //         percent: (event.process as ProgressEvent).total
                    //       };
                    //   default:
                    //     return event as any;
                    // }
                }));
            }
        }), share());
    }
    set events(obs) {
        this._eventsStream.next(obs);
    }
    ngOnDestroy() {
        this.destroyed.next();
        this.destroyed.complete();
    }
    ngOnInit() {
        this._progressEventStream.subscribe((step) => {
            this.step = step;
        });
    }
}
/** @nocollapse */ TapConfiguratorProgressBarComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressBarComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
/** @nocollapse */ TapConfiguratorProgressBarComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: TapConfiguratorProgressBarComponent, selector: "tap-configurator-progress-bar", inputs: { events: "events" }, ngImport: i0, template: "<ng-container *ngIf=\"step\">\n  <p>\n    {{ step | tapConfiguratorStepTitle }}\n  </p>\n  <ion-progress-bar [value]=\"step.percent\"></ion-progress-bar>\n</ng-container>\n", styles: [""], dependencies: [{ kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i1$1.IonProgressBar, selector: "ion-progress-bar", inputs: ["buffer", "color", "mode", "reversed", "type", "value"] }, { kind: "pipe", type: TapConfiguratorStepTitlePipe, name: "tapConfiguratorStepTitle" }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressBarComponent, decorators: [{
            type: Component,
            args: [{ selector: 'tap-configurator-progress-bar', template: "<ng-container *ngIf=\"step\">\n  <p>\n    {{ step | tapConfiguratorStepTitle }}\n  </p>\n  <ion-progress-bar [value]=\"step.percent\"></ion-progress-bar>\n</ng-container>\n" }]
        }], ctorParameters: function () { return []; }, propDecorators: { events: [{
                type: Input
            }] } });

class TapConfiguratorProgressBarModule {
}
/** @nocollapse */ TapConfiguratorProgressBarModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressBarModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
/** @nocollapse */ TapConfiguratorProgressBarModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressBarModule, declarations: [TapConfiguratorProgressBarComponent,
        TapConfiguratorStepTitlePipe], imports: [CommonModule, IonicModule], exports: [TapConfiguratorProgressBarComponent] });
/** @nocollapse */ TapConfiguratorProgressBarModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressBarModule, imports: [CommonModule, IonicModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressBarModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        TapConfiguratorProgressBarComponent,
                        TapConfiguratorStepTitlePipe,
                    ],
                    exports: [TapConfiguratorProgressBarComponent],
                    imports: [CommonModule, IonicModule],
                }]
        }] });

class TapConfiguratorProgressModalComponent {
    constructor() { }
    ngOnInit() { }
}
/** @nocollapse */ TapConfiguratorProgressModalComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressModalComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
/** @nocollapse */ TapConfiguratorProgressModalComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: TapConfiguratorProgressModalComponent, selector: "tap-configurator-progress-modal", ngImport: i0, template: "<ion-header>\n  <ion-toolbar>\n    <ion-title> Tap configuration </ion-title>\n  </ion-toolbar>\n</ion-header>\n<ion-content>\n  <tap-configurator-progress-bar></tap-configurator-progress-bar>\n</ion-content>\n<ion-footer>\n  <ion-item>\n    <ion-buttons slot=\"start\">\n      <ion-button color=\"danger\"> CANCEL </ion-button>\n    </ion-buttons>\n  </ion-item>\n</ion-footer>\n", styles: [""], dependencies: [{ kind: "component", type: i1$1.IonButton, selector: "ion-button", inputs: ["buttonType", "color", "disabled", "download", "expand", "fill", "form", "href", "mode", "rel", "routerAnimation", "routerDirection", "shape", "size", "strong", "target", "type"] }, { kind: "component", type: i1$1.IonButtons, selector: "ion-buttons", inputs: ["collapse"] }, { kind: "component", type: i1$1.IonContent, selector: "ion-content", inputs: ["color", "forceOverscroll", "fullscreen", "scrollEvents", "scrollX", "scrollY"] }, { kind: "component", type: i1$1.IonFooter, selector: "ion-footer", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i1$1.IonHeader, selector: "ion-header", inputs: ["collapse", "mode", "translucent"] }, { kind: "component", type: i1$1.IonItem, selector: "ion-item", inputs: ["button", "color", "counter", "counterFormatter", "detail", "detailIcon", "disabled", "download", "fill", "href", "lines", "mode", "rel", "routerAnimation", "routerDirection", "shape", "target", "type"] }, { kind: "component", type: i1$1.IonTitle, selector: "ion-title", inputs: ["color", "size"] }, { kind: "component", type: i1$1.IonToolbar, selector: "ion-toolbar", inputs: ["color", "mode"] }, { kind: "component", type: TapConfiguratorProgressBarComponent, selector: "tap-configurator-progress-bar", inputs: ["events"] }] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressModalComponent, decorators: [{
            type: Component,
            args: [{ selector: 'tap-configurator-progress-modal', template: "<ion-header>\n  <ion-toolbar>\n    <ion-title> Tap configuration </ion-title>\n  </ion-toolbar>\n</ion-header>\n<ion-content>\n  <tap-configurator-progress-bar></tap-configurator-progress-bar>\n</ion-content>\n<ion-footer>\n  <ion-item>\n    <ion-buttons slot=\"start\">\n      <ion-button color=\"danger\"> CANCEL </ion-button>\n    </ion-buttons>\n  </ion-item>\n</ion-footer>\n" }]
        }], ctorParameters: function () { return []; } });

class TapConfiguratorProgressModalModule {
}
/** @nocollapse */ TapConfiguratorProgressModalModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressModalModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
/** @nocollapse */ TapConfiguratorProgressModalModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressModalModule, declarations: [TapConfiguratorProgressModalComponent], imports: [CommonModule, IonicModule, TapConfiguratorProgressBarModule], exports: [TapConfiguratorProgressModalComponent] });
/** @nocollapse */ TapConfiguratorProgressModalModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressModalModule, imports: [CommonModule, IonicModule, TapConfiguratorProgressBarModule] });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: TapConfiguratorProgressModalModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [TapConfiguratorProgressModalComponent],
                    exports: [TapConfiguratorProgressModalComponent],
                    imports: [CommonModule, IonicModule, TapConfiguratorProgressBarModule],
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { TapConfiguratorProgressBarComponent, TapConfiguratorProgressBarModule, TapConfiguratorProgressModalComponent, TapConfiguratorProgressModalModule };
//# sourceMappingURL=iotize-ionic-configurator.mjs.map
