import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs';
import { take, share } from 'rxjs/operators';

@Injectable({
  providedIn: 'root',
})
export class ModalConfirmationService {
  private readonly _afterClosed = new Subject<boolean>();

  constructor() {}

  afterClosed(): Observable<boolean> {
    return this._afterClosed.asObservable().pipe(take(1), share());
  }

  close(dialogResult = false) {
    this._afterClosed.next(dialogResult);
  }
}
