import { Injectable, ViewContainerRef } from '@angular/core';
import { MatDialog, MatDialogRef } from '@angular/material';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { CalendarExceptionDialogComponent } from '../../components/calendar-exception-grid/views/calendar-exception-dialog/calendar-exception-dialog.component';
@Injectable({
  providedIn: 'root'
})
export class CalendarExceptionDialogService {

  componentRef: MatDialogRef<CalendarExceptionDialogComponent>;

  constructor(
    public dialog: MatDialog
  ) { }

  loadComponent(viewContainerRef: ViewContainerRef, title: string, record: any, mode: string): Observable<boolean> {
    this.componentRef = this.dialog.open(CalendarExceptionDialogComponent, {
      width: '500px',
      disableClose: true,
      data: {
        title,
        record,
        mode,
      }
    });
    return this.componentRef.afterClosed().pipe(map(it => {
      return it;
    }));
  }
}
