import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { Toast } from 'app/trainersite/toaster/toast.interface';

@Injectable()
export class ToasterService {
  subject: BehaviorSubject<Toast>;
  toast$;

  constructor() {
    this.subject = new BehaviorSubject<Toast>(null);
    this.toast$ = this.subject.asObservable()
      .pipe(filter(toast => toast !== null));
  }

  show(body?: string, delay?: number) {
    this.subject.next({body, delay });
  }
}