import { HttpClient } from '@angular/common/http';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { AuthService } from '../core/services/auth.service';

@Component({
	selector: 'app-disconnection',
	template: 'Déconnexion...'
})
export class DisconnectionComponent implements OnInit {

	constructor(
		private authService: AuthService,
		private router: Router,
		private http: HttpClient
	) {}

	ngOnInit(): void {
		this.http.get('/api/account/logout').subscribe(() => {
			console.log('Logout success.');
			this.authService.setAnonymous();
		}, error => {
			console.error('Error during logout from API.', error);
		}, () => {
			this.router.navigate(['/home']);
		});
	}
}
