import { Injectable } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material';
import { ReservationFlightDialogComponent } from '../reservation-flight-dialog.component';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';

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

  componentRef: MatDialogRef<ReservationFlightDialogComponent>;
  constructor(
    public dialog: MatDialog
  ) { }

  loadComponent(record: any, mode: string, minDate: any): Observable<boolean> {
    this.componentRef = this.dialog.open(ReservationFlightDialogComponent, {
      panelClass: 'custom-dialog',
      width: '1200px',
      disableClose: true,
      data: {
        record,
        mode,
        minDate
      }
    });
    return this.componentRef.afterClosed().pipe(map(it => {
      return it;
    }));
  }
}
