import { ErrorHandler, Injectable, NgZone } from '@angular/core';
import { DialogService } from '@progress/kendo-angular-dialog';
import { MessageErrorComponent } from '../shared/menssages/message-error/message-error.component';

@Injectable()
export class ErrorsHandler implements ErrorHandler {
  constructor(private dialogService: DialogService, private ngZone: NgZone) {}

  handleError(error: any) {
    console.log(error.message);
    const dialogRef = this.dialogService
    .open({
      title: 'Error Dialog',
      content: MessageErrorComponent,
      actions: [{ text: 'OK', primary: true }],
      width: 400,
      height: 550,
      minWidth: 250,
    });

    const messageInfo = dialogRef.content.instance;
    messageInfo.status = error.status;
    messageInfo.message = error.message;
    console.log(error.status + '-' + error.message);
    this.ngZone.run(() => {
       dialogRef.result.subscribe((result) => console.log(result));
    });
  }
}

