import { UserService } from './../../shared/user.service';
import { HttpClient } from '@angular/common/http';
import { NgxSpinnerService } from 'ngx-spinner';
import { AuthServiceService } from './../../shared/auth-service.service';
import { ActivatedRoute, Router, Params } from '@angular/router';
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-trainning-services',
  templateUrl: './trainning-services.component.html',
  styleUrls: ['./trainning-services.component.css']
})
export class TrainningServicesComponent implements OnInit {

  constructor(private route: ActivatedRoute, 
    private router: Router, 
    private authService: AuthServiceService,
    private spinner: NgxSpinnerService,
    private http: HttpClient,
    private userService: UserService,
    private authSer: AuthServiceService) { }

    trainningServiceId: number;
    visitorId: number;
    pages = [];

  ngOnInit() {

    this.spinner.show();//spinner
    this.authService.checkExternalFooter = false;
    this.authService.arabicTemplate = true; //to make footer is arabic all time
    //show / hide notification search in header
    this.authService.notificationLogin = true;
    this.authService.showSearchHeader = false;
    this.authService.showHeaderLogin = false;
    this.authService.showHeaderDashBoard = true;
    this.authService.showDashboardHeader = true;
    this.authService.internalHeader = false;

    this.route.params.subscribe(
      (params: Params) => {
        this.trainningServiceId = +params['trainningServicesId'];
        this.visitorId = params['visitorId'];
      }
    );

    this.userService.getPagesPermetiotns(this.visitorId, this.trainningServiceId).subscribe(
      (responce) => {
        this.pages = responce['pages'];
        console.log('pages list', this.pages);
        this.spinner.hide();
      },
      (error) => {
        console.log(error);
      }
    );


  }

  onGetService(serviceData: any) {
    console.log(serviceData);
    if(serviceData.id == 41) {
      this.router.navigate(['addRequest/' + this.visitorId]);
    } else if(serviceData.id == 42) {
      this.router.navigate(['allRequests/' + this.visitorId]);
    }
  }

}
