import { ExternalPageService } from './../../shared/external-page.service';
import { AuthServiceService } from './../../shared/auth-service.service';
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-external-page-header',
  templateUrl: './external-page-header.component.html',
  styleUrls: ['./external-page-header.component.css']
})
export class ExternalPageHeaderComponent implements OnInit {

  constructor(private authSer: AuthServiceService, 
    private externalService: ExternalPageService,
    private router: Router) { }
    
    currentDate: any = Date.now();//ararbic date 
    currentEnglishDate: any = Date.now(); //english date

  ngOnInit() {

    this.authSer.arabicTemplate = true;
    this.authSer.showDashboardHeader = false;
    this.authSer.setLocalLang(); //set languages icons
    this.currentDate = this.authSer.writeHijri(new Date(this.currentDate), 'ar', 'header');

    this.authSer.footerData = [];

    this.authSer.onGetFooterData('external').subscribe(
      (responce) => {
        this.authSer.footerData = responce['footer'];
        console.log('fooooooooooooooter dattaaa' , this.authSer.footerData);
      },
      (error) => {
        console.log(error);
      }
    );
    

    //get header data 
    this.externalService.getHeader().subscribe(
      (responce) => {
        console.log(responce);
        this.externalService.headerMenus = responce['parents'];
        console.log('menu data' , this.externalService.headerMenus);
      },
      (error) => {
        console.log(error);
      }
    );
  }

  onDashBoard() {
    this.router.navigate(['services/' + this.authSer.dataLoginUser['id']]);
  }

  goToHome() {
    this.router.navigate(['/ExternalPage']);
  }


  onLogin() {
    this.router.navigate(['/login']);
  }

  onGetProfile() {
    console.log('profile/'  + this.authSer.dataLoginUser['id']);
    this.router.navigate(['profile/'  + this.authSer.dataLoginUser['id']]);
  }

  //log out function
  onLogout() { 
    localStorage.clear();
    this.router.navigate(['login']);
  }

}
