import {CanDeactivate, CanDeactivateFn} from '@angular/router';
import {Injectable} from '@angular/core';

export interface CanComponentDeactivate {

  canDeactivate(): boolean;

}

export const pendingGuard: CanDeactivateFn<CanComponentDeactivate> = (component, currentRoute, currentState, nextState) => {
  return component.canDeactivate();
};

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

  canDeactivate(component: CanComponentDeactivate): boolean | Promise<boolean> {
    return component.canDeactivate();
  }

}
