import { Component, Input } from '@angular/core';
import { jwtDecode } from 'jwt-decode';
import { MatDialog } from '@angular/material/dialog';
@Component({
  selector: 'app-sidebar',
  templateUrl: './sidebar.component.html',
  styleUrl: './sidebar.component.css'
})
export class SidebarComponent {
  @Input() isVisible: boolean = false;
  isSuperAdmin: boolean = false;
  username: string = "";
  decodedToken: any = "";
  showOgBootSub: boolean = false;
  showOgDhcpSub: boolean = false;
  showCommandSub: boolean = false;
  showSoftwareSub: boolean = false;

  toggleOgBootSub() {
    this.showOgBootSub = !this.showOgBootSub;
  }
  toggleOgDhcpSub() {
    this.showOgDhcpSub = !this.showOgDhcpSub;
  }
  toggleCommandSub() {
    this.showCommandSub = !this.showCommandSub;
  }
  toggleSoftwareSub() {
    this.showSoftwareSub = !this.showSoftwareSub;
  }

  constructor(public dialog: MatDialog) {}

  ngOnInit(): void {
    const token = localStorage.getItem('loginToken');
    if (token) {
      try {
        this.decodedToken = jwtDecode(token);
        this.isSuperAdmin = this.decodedToken.roles.includes('ROLE_SUPER_ADMIN');
        localStorage.setItem('isSuperAdmin', String(this.isSuperAdmin));
        this.username = this.decodedToken.username;
      } catch (error) {
        console.error('Error decoding JWT:', error);
      }
    }
  }
}
