
import { Component, OnInit } from '@angular/core';
import { Router, RouterOutlet, NavigationEnd } from '@angular/router';
import { CommonModule } from '@angular/common';
import { filter } from 'rxjs/operators';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [RouterOutlet, CommonModule],
  templateUrl: './app.html',
  styleUrls: ['./app.scss'],
})
export class AppComponent implements OnInit {
  title = 'ai-dashboard';
  showSidebar: boolean = false;

  private readonly routesWithoutSidebar = ['/login', '/register', '/forgot-password'];

  constructor(private router: Router) {}

  ngOnInit(): void {
    this.checkIfShouldShowSidebar(this.router.url);

    this.router.events
      .pipe(filter(event => event instanceof NavigationEnd))
      .subscribe((event: NavigationEnd) => {
        this.checkIfShouldShowSidebar(event.url);
      });
  }

  private checkIfShouldShowSidebar(url: string): void {
    this.showSidebar = !this.routesWithoutSidebar.some(route =>
      url.startsWith(route) || url === route
    );
  }
}
