import { Injectable, ViewContainerRef } from "@angular/core";
import { MatDialog, MatDialogRef } from "@angular/material";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { AdditionalParamDialogComponent } from "../additional-param-dialog.component";

@Injectable({
  providedIn: 'root'
})
export class AdditionalParamDialogDialogService {
  componentRef: MatDialogRef<AdditionalParamDialogComponent>;

  constructor(
    public dialog: MatDialog
  ) { }

  loadComponent(viewContainerRef: ViewContainerRef, title: string, record: any, mode: string, showCancelButton?: boolean): Observable<boolean> {
    this.componentRef = this.dialog.open(AdditionalParamDialogComponent, {
      width: '400px',
      height: '290px',
      disableClose: true,
      data: {
        title,
        record,
        mode,
        showCancelButton
      }
    });

    return this.componentRef.afterClosed().pipe(map(it => {
      return it;
    }));
  }
}
