import { Component, OnInit, ViewChild,  ElementRef} from '@angular/core';
import { Router,ActivatedRoute } from '@angular/router';
import { WebService } from '../../provider/web.service';
import { Options } from 'ng5-slider';
import { NgxCarousel } from 'ngx-carousel';

@Component({
  selector: 'app-purchase-home',
  templateUrl: './purchase-home.component.html',
  styleUrls: ['./purchase-home.component.scss']
})
export class PurchaseHomeComponent implements OnInit {
  public carouselTile: NgxCarousel;

  @ViewChild("failureModel") public failureModelRef: ElementRef;
  
  constructor(
    private router        : Router, 
    private route         : ActivatedRoute,
    public webService     : WebService
  ) { }

  value: number = 40;
  highValue: number = 60;
  options: Options = {
    floor: 0,
    ceil: 100
  };

  ngOnInit() {
    this.route.queryParams.subscribe(params => {
      let payStatus = params['status'];

      if(payStatus && payStatus !=''){
        if(payStatus == 'failure')
          this.failureModelRef.nativeElement.click();
      }
    });
    this.unsetProdDetails();
    this.carouselTile = {grid: {xs: 1, sm: 2 , md: 4, lg: 8, all: 0},slide: 1, speed: 400,point: { visible: false },load: 2, touch: true, easing: 'ease'}
  }

  unsetProdDetails(){
    this.webService.removeLocalItem('productDetails');
  }

  goToPage(path,data=null){
    this.router.navigateByUrl(path,{queryParams:data});
    document.body.scrollTop = document.documentElement.scrollTop = 0;
  }

  carouselTileLoad(){ return ''; }

}
