import {CanActivateFn, Router} from '@angular/router';
import {inject} from "@angular/core";
import {AccountService} from "@app/_services";

export const adminGuard: CanActivateFn = (route, state) => {
    const accountService = inject(AccountService);
    if (accountService.isLoggedIn() && accountService.isUserAdmin()) {
        return true;
    }
    inject(Router).navigate(['/account/login'], { queryParams: { returnUrl: state.url }});
    return false;
};
