import * as i0 from '@angular/core';
import { PLATFORM_ID, Injectable, Inject } from '@angular/core';
import { ErrorPopupComponent } from '@testlocallibrary/shared-kernel/components/error-popup';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { isPlatformBrowser } from '@angular/common';
import * as i1 from '@testlocallibrary/shared-kernel/services/logger';
import * as i2 from '@angular/router';
import * as i3 from '@angular/material/dialog';
import * as i4 from '@testlocallibrary/shared-kernel/services/error-handler-pop-up-state';

class CustomErrorHandlerService {
    constructor(zone, loggerService, router, dialog, popUpService, destroyRef, platformId) {
        this.zone = zone;
        this.loggerService = loggerService;
        this.router = router;
        this.dialog = dialog;
        this.popUpService = popUpService;
        this.destroyRef = destroyRef;
        this.platformId = platformId;
        this.isPopUpOpen = false;
        this.isBrowser = isPlatformBrowser(platformId);
        popUpService.isPopUpOpenVal.pipe(takeUntilDestroyed(destroyRef))
            .subscribe((state) => {
            this.isPopUpOpen = state;
        });
    }
    handleError(error) {
        this.zone.run(() => {
            if (error.name == "HttpErrorResponse") {
                if (!this.isPopUpOpen) {
                    this.dialog.open(ErrorPopupComponent);
                    this.popUpService.setIsPopUpOpenState(true);
                }
            }
            else {
                this.mapLoggerResuest(error);
            }
        });
    }
    mapLoggerResuest(error) {
        if (this.isBrowser) {
            let hostname = window.location.hostname;
            let loggerRequestDto = {
                StatusCode: error.status?.toString(),
                Discription: error.message,
                ProjectName: 'ldc',
                URL: `${hostname}${this.router.url.toString()}`,
            };
            this.loggerService.createNewLog(loggerRequestDto).pipe(takeUntilDestroyed(this.destroyRef)).subscribe((response) => {
            });
        }
    }
    static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CustomErrorHandlerService, deps: [{ token: i0.NgZone }, { token: i1.LoggerService }, { token: i2.Router }, { token: i3.MatDialog }, { token: i4.ErrorHandlerPopUpStateService }, { token: i0.DestroyRef }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
    static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CustomErrorHandlerService, providedIn: 'root' }); }
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: CustomErrorHandlerService, decorators: [{
            type: Injectable,
            args: [{
                    providedIn: 'root',
                }]
        }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i1.LoggerService }, { type: i2.Router }, { type: i3.MatDialog }, { type: i4.ErrorHandlerPopUpStateService }, { type: i0.DestroyRef }, { type: Object, decorators: [{
                    type: Inject,
                    args: [PLATFORM_ID]
                }] }]; } });

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

export { CustomErrorHandlerService };
//# sourceMappingURL=testlocallibrary-shared-kernel-services-custom-error-handler.mjs.map
