import { AuthServiceService } from './../../shared/auth-service.service';
import { Component, OnInit, LOCALE_ID, Inject } from '@angular/core';
import { Router } from '@angular/router';
import * as moment from 'moment';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { UserService } from '../../shared/user.service';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.css']
})

export class HeaderComponent implements OnInit {

  imgSrc: string = '../../../assets/image'; 


  constructor(private authSer: AuthServiceService ,
    private userSer: UserService,
    private router: Router) { }
    
    currentDate: any = Date.now();


  ngOnInit() {

    this.authSer.showHeaderLogin = true;
    this.authSer.showHeaderDashBoard = false;


    this.authSer.checkExternalFooter = false;

    if(this.authSer.checkExternalFooter) {
      alert('external');
    } else {
      this.authSer.onGetFooterData('internal').subscribe(
        (responce) => {
          this.authSer.footerData = responce['footer'];
          console.log(this.authSer.footerData);
        },
        (error) => {
          console.log(error);
        }
      );
    }
    
    
    // const m = moment().format('iYYYY/iM/iD');
    // console.log(m);
    this.currentDate = this.authSer.writeHijri(new Date(this.currentDate), 'ar', 'header');

   
    this.userSer.getUserDataProfile();
    console.log();
   
  }

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

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

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


}
