import { Component, OnInit } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { first, tap } from 'rxjs/operators';
import { UserService } from 'src/app/services/user.service';
import { UserStore } from 'src/app/stores/user.store';

@Component({
  selector: 'app-modal-decconected',
  templateUrl: './modal-decconected.component.html',
  styleUrls: ['./modal-decconected.component.scss'],
})
export class ModalDecconectedComponent implements OnInit {
  private sessionId!: string;
  private setup!: string;
  constructor(
    public dialog: MatDialog,
    private userService: UserService,
    private userStore: UserStore
  ) {}

  ngOnInit(): void {
    this.userStore
      .select('user')
      .pipe(
        tap((res: any) => {
          this.sessionId = res.accessKey;
        })
      )
      .subscribe();
  }

  public closeDialog() {
    this.dialog.closeAll();
  }

  public disconnected() {
    this.closeDialog();
    this.userService.setSessionExpired()
    // this.userService
    //   .logOut(this.sessionId)
    //   .pipe(first())
    //   .subscribe(
    //     (data: any) => {
    //       if (data) this.closeDialog();
    //     },
    //     (error) => {
    //       console.log('errr', error);
    //     }
    //   );
  }
}
