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 {


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

  ngOnInit() {

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

    this.authSer.checkExternalFooter = false;

    if(!this.authSer.isAuthenticated()) {
      console.log('user data internal header', this.authSer.returnUserData());
      this.dataLoginUser = this.authSer.returnUserData();
    }


    if(this.authSer.checkExternalFooter) {
    } 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');
  }

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

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

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


}
