import TVoxSDK from '@telenia/tvox-client-sdk';
import { Component } from '@angular/core';
import { MatCardModule } from '@angular/material/card';
import { MatListModule } from '@angular/material/list';
import { TVoxService } from 'src/app/tvox-client-sdk.service';
import { MatButtonModule } from '@angular/material/button';
import { Router } from '@angular/router';

@Component({
  selector: 'logout',
  imports: [MatCardModule, MatListModule, MatButtonModule],
  templateUrl: './logout.component.html',
  standalone: true,
})
export class LogoutComponent {
  private client!: TVoxSDK.Client;

  constructor(private tvoxService: TVoxService, private router: Router) {
    this.client = this.tvoxService.getClient(); // recupero il client istanziato in precedenza all'interno del servizio 'TVoxService'
  }

  logout() {
    this.client
      .logout() // metodo per eseguire il logout
      .then(() => {
        console.log('logout COMPLETE');
        this.router.navigate(['/login']);
      })
      .catch((error) => {
        console.error('logout ERROR:', error);
      });
  }
}
