import {Component, Inject, OnInit, PLATFORM_ID} from '@angular/core';
import {MenubarModule} from 'primeng/menubar';
import {MessageService} from 'primeng/api';
import {FloatLabelModule} from 'primeng/floatlabel';
import {ToastModule} from 'primeng/toast';
import {DialogModule} from 'primeng/dialog';
import {isPlatformBrowser} from '@angular/common';
import {Button} from 'primeng/button';
import {AuthService} from './auth.service';
import {Router, RouterOutlet} from '@angular/router';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [MenubarModule, FloatLabelModule, ToastModule, DialogModule, Button, RouterOutlet],
  providers: [
    MessageService,
  ],
  templateUrl: './app.component.html',
  styleUrl: './app.component.css'
})
export class AppComponent implements OnInit {
  isSessionExpired: boolean = false;

  constructor(@Inject(PLATFORM_ID) private platformId: object,
              protected authService: AuthService,
              private router: Router,) {
  }

  isBrowser(): boolean {
    return isPlatformBrowser(this.platformId)
  }

  setSessionExpiredFalse(): void {
    this.isSessionExpired = false;
    this.authService.setSessionExpired(false);
    this.router.navigate(['/logout']);
  }

  ngOnInit(): void {
    this.authService.sessionExpired$.subscribe(expired => {
      this.isSessionExpired = expired;
    });
  }
}
