import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { Server } from "socket.io";
import { BehaviorSubject } from 'rxjs';
import { IAMService } from './services/iam/iam.service';
import { environment } from 'src/environments/environment';


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent {
  title = 'vacaciones';
  anio: number;
  menuMCO = false;
  isLoggedIn:Boolean = false;
  events: string[] = [];
  opened: boolean = false;
  pantallaGrande:Boolean =  !this.breakpointObserver.isMatched('(max-width: 1700px)');
  empresas_arr = [
    {
      RFC: "TME700618RC7",
      NOMBRE: "TIMKEN" 
    },

  ]

  //Valor de iniciación

  public activateMenu( response:Boolean ){
    this.isLoggedIn = response;
  }

  constructor( private router: Router, private breakpointObserver:BreakpointObserver, private _IAMService:IAMService) {
    this.anio = new Date().getFullYear();
    this.isLoggedIn = (localStorage.getItem('isLoggedIn') == "true");
    let title = document.getElementById("title-sys");

    let rfc_empresa_local = localStorage.getItem("RFCEMPRESA")
    let filtro_empresa = this.empresas_arr.filter(element => element.RFC == rfc_empresa_local);
    
    if(filtro_empresa.length > 0){
      document.title = "Sistema Integral de Recursos Humanos - " + filtro_empresa[0].NOMBRE;
    }else{
      document.title = "Sistema Integral de Recursos Humanos - ITTEC"
    }

    this.checkURL();
  }

  checkURL(){
    /* if (environment.production) {
      if (location.protocol === 'http:') {
        window.location.href = location.href.replace('http', 'https');
      }
    } */

    if (environment.production) {
      if (location.protocol === 'http:') {
        window.location.href = location.href.replace('http', 'https');
      }
    }
  }
  
  onResize(event:any) {
    this.pantallaGrande = event.target.innerWidth > 1700
    
  }
  

  logout() {
    this._IAMService.logout();
  }
}
