import { UserService } from './../../../shared/user.service';
import { RolesService } from './../../../shared/roles.service';
import { ActivatedRoute, Params } from '@angular/router';
import { Component, OnInit } from '@angular/core';
import { NgxSpinnerService } from 'ngx-spinner';

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



export class RoleReportComponent implements OnInit {
  
  roleId: number;
  reportPages = [];

  constructor(private route: ActivatedRoute, 
    private roleService:RolesService, 
    private userService: UserService,
    private spinner: NgxSpinnerService ) { 
      this.spinner.show();
    }

  ngOnInit() {
    
    this.userService.getUserDataProfile();
    
    this.route.params.subscribe(
      (params: Params) => {
        this.roleId = params['roleReportId'];
        this.roleService.get_report_pages_inside_roles(this.roleId).subscribe(
          (responce) => {
            //console.log(responce);
            this.reportPages.push(responce['role']);
            console.log(this.reportPages);
            this.spinner.hide();
          }, 
          (error) => {
            console.log(error);
          }
        );
      }
    )  
  };

  //print function
  onPrint() {
    window.print();
  }

}
