import { Injectable } from '@angular/core';
import { CanDeactivate } from '@angular/router';
import { Observable, of } from 'rxjs';
import { RechargeComponent } from '../modules/account/recharge/recharge.component';
import { VipComponent } from '../modules/goods/vip/vip.component';

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

  public canDeactivate(component: RechargeComponent|VipComponent): Observable<boolean> {
    if(component?.paycomp?.isOpen){
      component.paycomp.isOpen = false
      return of(false);
    }else{
      return of(true);
    }
  }
}