import { Component, Input, OnDestroy } from '@angular/core';
import { MenuElement } from 'src/app/model/view/menu-element';
import { GuiService } from 'src/app/service/gui.service';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

@Component({
  selector: 'app-side-menu',
  templateUrl: './side-menu.component.html',
  styleUrl: './side-menu.component.scss',
})
export class SideMenuComponent implements OnDestroy {
  @Input() elements: MenuElement[] = [];

  debug = false;

  unsubscribe$ = new Subject<void>();

  constructor(private gui: GuiService) {
    this.gui.debug$.pipe(takeUntil(this.unsubscribe$)).subscribe(debug => {
      this.debug = debug;
    });
  }

  ngOnDestroy() {
    this.unsubscribe$.next();
    this.unsubscribe$.complete();
  }

  expand(element: MenuElement): void {
    element.expanded = true;
  }

  collapse(element: MenuElement): void {
    element.expanded = false;
  }
}
