import { Injectable } from '@angular/core';
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material/dialog';
import { map, Observable, take } from 'rxjs';
import { PackageDialogComponent } from '../../components/package-dialog/package-dialog.component';

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

  dialogRef!: MatDialogRef<PackageDialogComponent>;

  constructor(
    private dialog: MatDialog
  ) { }

  public open(options: MatDialogConfig) {
    this.dialogRef = this.dialog.open(PackageDialogComponent, options);
  }

  public confirmed(): Observable<any> {
    return this.dialogRef.afterClosed().pipe(take(1), map(res => {
      return res;
    }
    ));
  }
}
