import { Injectable, Type } from "@angular/core";
import { BehaviorSubject, Observable } from "rxjs";

@Injectable({
    providedIn: 'root'
})
export class ModalService {
    _modalContent: BehaviorSubject<Type<unknown> | undefined> = new BehaviorSubject<Type<unknown> | undefined>(undefined);

    open(componentClass: Type<unknown>): void {
        this._modalContent.next(componentClass);
    }

    close(): void {
        this._modalContent.next(undefined);
    }

    get modalContent(): Observable<Type<unknown> | undefined> {
        return this._modalContent.asObservable();
    }
}