import * as i0 from '@angular/core';
import { Injectable, Optional } from '@angular/core';
import * as i1 from '@ngx-translate/core';
import { BehaviorSubject, ReplaySubject, combineLatest, of } from 'rxjs';
import { PortalMessageService } from '@onecx/angular-integration-interface';

class FakeTopic {
    constructor(initialValue = undefined) {
        if (initialValue !== undefined) {
            this.state = new BehaviorSubject(initialValue);
        }
        else {
            this.state = new ReplaySubject(1);
        }
    }
    asObservable() {
        return this.state.asObservable();
    }
    subscribe(observerOrNext, error, complete) {
        return this.asObservable().subscribe(observerOrNext, error, complete);
    }
    pipe(...operations) {
        return this.asObservable().pipe(...operations);
    }
    publish(value) {
        this.state.next(value);
        return Promise.resolve();
    }
}

function providePortalMessageServiceMock() {
    return [
        { provide: PortalMessageServiceMock, useClass: PortalMessageServiceMock },
        { provide: PortalMessageService, useExisting: PortalMessageServiceMock },
    ];
}
class PortalMessageServiceMock {
    constructor(translateService) {
        this.translateService = translateService;
        this.lastMessages = [];
        this.message$ = new FakeTopic();
    }
    success(msg) {
        this.lastMessages.push({ type: 'success', value: msg });
        this.addTranslated('success', msg);
    }
    info(msg) {
        this.lastMessages.push({ type: 'info', value: msg });
        this.addTranslated('info', msg);
    }
    error(msg) {
        this.lastMessages.push({ type: 'error', value: msg });
        this.addTranslated('error', msg);
    }
    warning(msg) {
        this.lastMessages.push({ type: 'warning', value: msg });
        this.addTranslated('warning', msg);
    }
    addTranslated(severity, msg) {
        if (this.translateService) {
            combineLatest([
                msg.summaryKey ? this.translateService.get(msg.summaryKey || '', msg.summaryParameters) : of(undefined),
                msg.detailKey ? this.translateService.get(msg.detailKey, msg.detailParameters) : of(undefined),
            ]).subscribe(([summaryTranslation, detailTranslation]) => {
                this.message$.publish({
                    ...msg,
                    severity: severity,
                    summary: summaryTranslation,
                    detail: detailTranslation,
                });
            });
        }
        else {
            console.log('TranslationModule not imported in TestBed. Therefore message$ is not updated.');
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PortalMessageServiceMock, deps: [{ token: i1.TranslateService, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PortalMessageServiceMock }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: PortalMessageServiceMock, decorators: [{
            type: Injectable
        }], ctorParameters: () => [{ type: i1.TranslateService, decorators: [{
                    type: Optional
                }] }] });

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

export { PortalMessageServiceMock, providePortalMessageServiceMock };
//# sourceMappingURL=onecx-portal-integration-angular-mocks.mjs.map
