import { Component, OnInit, ViewChild } from '@angular/core';
import { LocalStorage } from "../../core/services/local_storage.service"
import { HyperService } from '../../core/services/http.service';
import { Router } from "@angular/router";
import * as moment from 'moment'; 

@Component({
  selector: 'app-landing',
  templateUrl: './landing.component.html',
  styleUrls: ['./landing.component.scss']
})
export class LandingComponent implements OnInit {

  imageSources = []; //Slider image array 
  user_type: any; //User Am or DSE 
 user_role:any;
 activeBanner:number;
  constructor(private server: HyperService, private router: Router) {}

  ngOnInit() {
      LocalStorage.setValue('is_firsttime', false);
      this.user_role=LocalStorage.getValue('user_data').role ;
      if (LocalStorage.getValue('user_data').role != 7 && LocalStorage.getValue('user_data').role > 7 && LocalStorage.getValue('user_data').role != 14) {
          this.user_type = 0; //Sales Ex
      } else if (LocalStorage.getValue('user_data') != undefined &&( LocalStorage.getValue('user_data').role <= 7 || LocalStorage.getValue('user_data').role ==14)) {
       
          this.user_type = 1; //Manager 
      } 
     // console.log(this.user_type,LocalStorage.getValue('user_data').role)
      this.getBanner(); //get banner details 
      this.activeBanner=0;
  }

  getBanner() {
      this.server.get("banner")
          .then((data) => {
              if (data.status == 200 && data.result.response != 'failed' && data.result.data != null) {
                  for (let i = 0; i < data.result.data.length; i++) {
                      this.imageSources.push(data.result.data[i].image);
                      this.activeBanner = i;
                    //  console.log(this.activeBanner)
                  }
                  this.activeBanner = 0;
              } else if (data.result.status == 401 && data.result.response == 'failed') {
                  this.router.navigateByUrl('');
              } else {
                  this.imageSources = [];
              }
          });
  }
}