import { Component, OnInit ,ViewChild} from '@angular/core';
import * as moment from 'moment';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
import { HyperService } from '../../core/services/http.service';
import { Router } from "@angular/router";
import { ActivatedRoute } from '@angular/router';
import { LocalStorage } from '../../core/services/local_storage.service';
import { BulletinDetailsComponent } from '../bulletin-details/bulletin-details.component';
declare var $: any;

@Component({
  selector: 'app-product',
  templateUrl: './product_list.component.html',
  styleUrls: ['./product_list.component.scss']
})
export class WalletProductListComponent implements OnInit {
  loader: boolean;
  order_history: any;
  sales_date: any;
  user_dashboard: any;
  percentage: any;
  otpform: FormGroup;
  mpin:string='';
  mpin_error:boolean=false;
  current_amount:any;
  cat_list:any;
  catlist:boolean=true;
  productlist:boolean=false;
  product_list:any;
  sub: any;
  view_type: any;
  constructor(private server: HyperService, private router: Router,private formBuilder: FormBuilder,private route: ActivatedRoute) {
    this.sub = this.route.params.subscribe(params => {
        this.view_type = params['id'];
    });
  }

  ngOnInit() { 
    this.catlist=true;
    this.onClickCategory(this.view_type);
  } 
   
 
onClickCategory(data){
    // this.catlist=false;
    // this.productlist=true;
    this.loader = true
    this.server.get("redeem/category/"+data )
        .then((data) => {
            if (data.status == 200 && data.result.response != 'failed' ) {
                this.loader = false;
                this.product_list = data.result.data._embedded.product;
                console.log(this.product_list[0].images.base_image,"this.product_list")
               
            } else if (data.result.status == 401 && data.result.response == 'failed') {
                this.router.navigateByUrl('');
            }
        });
}
onClickProduct(list){
    this.router.navigateByUrl('wallet/category_list/'+list.id);
}
}