import { isPlatformBrowser } from '@angular/common';
import { Component, HostListener, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { Router } from '@angular/router';
declare let $: any;
@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss']
})

export class HeaderComponent implements OnInit {
  public isOtherLoanMenu: boolean = false;
  public isShow: boolean = false;
  public isLoanMenu: boolean = false;
  public city: string = "";//"surat";
  public isShowDropDown: boolean = false
  public isNavToggle: boolean = false;

  constructor(
    private router: Router,
    @Inject(PLATFORM_ID) public platformId: object
  ) { }

  ngOnInit(): void {
    // $.getScript('../../../assets/js/bootstrap.min.js');
    let selectedCity;
    if (isPlatformBrowser(this.platformId))
      selectedCity = sessionStorage.getItem("selectedCity");
    console.log(selectedCity);
    if (selectedCity) {
      this.city = selectedCity
      // } else {
      //   this.city = "surat";
    }
  }

  // @HostListener('window:scroll', ['$event'])
  // onWindowScroll(e: { target: { value: any; }; length: number; }) {
  //   if (window.pageYOffset > 550) {
  //     let element = document.getElementById('navbar');
  //     element!.classList.add('fixed');
  //   } else {
  //     let element = document.getElementById('navbar');
  //     element!.classList.remove('sticky');
  //   }
  // }

  public hidenavbarcontent() {

  }

  public loanMenu() {

    this.isLoanMenu = true;
    this.isOtherLoanMenu = false;
  }

  public redirectTo(url: string) {
    this.isShow = !this.isShow;
    let selectedCity;
    if (isPlatformBrowser(this.platformId))
      selectedCity = sessionStorage.getItem("selectedCity");
    console.log(selectedCity);
    if (selectedCity) {
      this.city = selectedCity
      // } else {
      //   this.city = "surat";
    }
    console.log("Routes City===>" + this.city);
    if (this.city) {
      if (url == "") {
        this.router.navigate([url]);
      } else {
        this.router.navigate([url, this.city]);
      }
    } else {
      this.router.navigate([url]);
    }
  }

}