import { Injectable, ViewContainerRef } from "@angular/core";
import { MatDialog, MatDialogRef } from "@angular/material";
import { Observable } from "rxjs";
import { map } from 'rxjs/operators';
import { ChangeHistoryDialogComponent } from "../change-history-dialog.component";

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

    componentRef: MatDialogRef<ChangeHistoryDialogComponent>;

    constructor(
        public dialog: MatDialog
    ) { }

    loadComponent(viewContainerRef: ViewContainerRef, id): Observable<boolean> {
        this.componentRef = this.dialog.open(ChangeHistoryDialogComponent, {
          width: '640px',
          disableClose: true,
          data: {
            id: id
          }
        });
    
        return this.componentRef.afterClosed().pipe(map(it => {
          return it;
        }));
      }
}