import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { ISettings } from '@shared/models/settings.model';
import { HelperService } from '@shared/services/helper.service';
import { Title } from '@angular/platform-browser';


@Component({
  selector: 'app-navigation',
  templateUrl: './navigation.component.html',
  styleUrls: ['./navigation.component.scss']
})
export class NavigationComponent implements OnInit {

  settings: ISettings = {} as ISettings;

  constructor(private router: Router, private helperService: HelperService, private titleService: Title) {
  }

  ngOnInit(): void {
    this.initialize();
  }

  initialize(): void {
    this.helperService.getSettings().subscribe({
      next: (data: ISettings) => {
        this.settings = data;
      },
      complete: () => {
        this.titleService.setTitle(this.settings.blogTitle);
      }
    });
  }

  openMenu(): void {
    const element = document.getElementsByClassName('topnav')[0];
    if (element.className === 'topnav') {
      element.className += ' responsive';
    } else {
      element.className = 'topnav';
    }
  }

  isCurrentPage(url: string): boolean {
    return this.router.url === url;
  }

}
