import { Component } from '@angular/core';
import { NavigationPanelService } from 'src/services/navigationPanel/navigation-panel.service';

@Component({
  selector: 'app-journal-home',
  templateUrl: './journal-home.component.html',
  styleUrls: ['./journal-home.component.scss'],
})
export class JournalHomeComponent {
  private isNavigationOpen: boolean = false;
  public constructor(public navigation: NavigationPanelService) {}

  ngOnInit() {
    const width = window.innerWidth;
    this.navigation.showNavigationPanel$.subscribe((state) => {
      this.isNavigationOpen = state;
    });

    window.addEventListener('mousemove', (event) => {
      if (event.clientX < 10 && !this.isNavigationOpen) {
        this.navigation.openNavigation();
      }
    });

    window.addEventListener('mousemove', (event) => {
      if (event.clientX > width / 4 && this.isNavigationOpen) {
        this.navigation.closeNavigation();
      }
    });
  }
}
