import { inject } from '@angular/core';
import { CanActivateFn } from '@angular/router';
import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';

import { UserService } from '@services';

export const noauthGuard: CanActivateFn = (): Observable<boolean> => {
    /*
    const router = inject(Router);
    const userService = inject(UserService);
    return userService.isAuthenticated.pipe(take(1)).pipe(map(data => {
        if (data) {
            router.navigate(['/']);
            return false;
        } else {
            return true;
        }
    }));
    */
    const userService = inject(UserService);
    return userService.isAuthenticated.pipe(take(1), map(isAuth => !isAuth));
};
