import { MatDialog } from '@angular/material/dialog';
import { Injectable } from '@angular/core';
import { ConfirmDialogData, ConfirmDialogComponent } from './confirm-dialog/confirm-dialog.component';
import { Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class DialogService {

  constructor(private dialog: MatDialog) { }

  public confirm(title?: String, text?: String, maxWidth?: number): Observable<any>{
    let dialogData: ConfirmDialogData = {
      title: title ? title : 'Potvrzení',
      text: text ? text : 'Opravdu si přejete provést požadovanou akci ?'
    }

    const dialogRef = this.dialog.open(ConfirmDialogComponent, {
      maxWidth: maxWidth ? maxWidth+'px' : '300px',
      data: dialogData
    });

    return dialogRef.afterClosed();
  }

}
