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

@Component({
  selector: 'app-menu-bar',
  templateUrl: './menu-bar.component.html',
  styleUrl: './menu-bar.component.scss',
})
export class MenuBarComponent implements OnDestroy {
  @Input() elements: MenuElement[] = [];
  protected theme = '';
  private unsubscribe$ = new EventEmitter<void>();

  get visibleElements() {
    return this.elements.filter(e => e.visible !== false);
  }

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

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