import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { UserEditComponent } from './user-edit.component';
import { Observable, of } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class LeaveGuard implements CanDeactivate<UserEditComponent> {

  public canDeactivate(component: UserEditComponent): Observable<boolean> {
    if (component.moduleChange && typeof(component.moduleChange) === 'function') {
      return component.moduleChange();
    } else {
      return of(true);
    }
  }
}