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

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

  componentRef: MatDialogRef<FlightLegDialogComponent>;

  constructor(public dialog: MatDialog) { }

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