import { Router, ActivatedRoute, Params } from '@angular/router';
import { InternalPageService } from './../../shared/internal-page.service';
import { UserService } from './../../shared/user.service';
import { AuthServiceService } from './../../shared/auth-service.service';
import { Component, OnInit } from '@angular/core';
import 'hijri-date';
import HijriDate,{toHijri} from 'hijri-date/lib/safe';
import { NgxSpinnerService } from 'ngx-spinner';

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

  constructor(private authSer: AuthServiceService, 
    private userservice: UserService, 
    private internalService: InternalPageService, 
    private route: ActivatedRoute,
    private spinner: NgxSpinnerService,
    private router: Router) {
      spinner.show();
     }
  
    
  currentDate: any = Date.now();


  currentEnglishDate: any = Date.now();

  showActiveBackground: boolean = false;
     
  ngOnInit() {
   
     this.authSer.footerData = [];

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

    this.authSer.setLocalLang();
    console.log('tooooken', this.authSer.isAuthenticated());
    this.internalService.getParentData().subscribe(
      (responce) => {
        this.authSer.parentsPage = responce['parents'];
        console.log('parents pageees', this.authSer.parentsPage);
      },
      (error) => {
        console.log(error);
      }
    );
    
    //this.spinner.show();
    this.authSer.showDashboardHeader = false;
    this.internalService.getParentData();
    //console.log(this.checkTokenExpire);
      //get profile data
    this.userservice.getUserDataProfile();

    this.currentDate = this.authSer.writeHijri(new Date(this.currentDate), 'ar', 'header');
  }

  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']);
  }

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

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

  getData(parentData) {
    console.log(parentData);
  }


  





  

}
