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 { LocalStorage } from '../../core/services/local_storage.service';
import { BulletinDetailsComponent } from '../bulletin-details/bulletin-details.component';
declare var $: any;

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

  @ViewChild(BulletinDetailsComponent) content_modal: BulletinDetailsComponent;

  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;
  constructor(private server: HyperService, private router: Router,private formBuilder: FormBuilder) {}

  ngOnInit() { 
    this.catlist=true;
    this.onClickPurchase();
  } 
   
 
onClickPurchase(){
    // this.router.navigateByUrl('');
    this.loader = true
    this.server.get("redeem/category")
        .then((data) => {
            if (data.status == 200 && data.result.response != 'failed' ) {
              console.log(data);
                this.loader = false;
                // this.cat_list = data.result.data.root_category;
                // console.log(this.cat_list)
                this.cat_list =  [{
                  "category_id": 330,
                  "category_name": "Physical",
                  "category_image": "https://hyper-m.cygnusa.in/images/noimage.jpg"
                    
                  },{
                    
                     "category_id": 57,
                     "category_name": "Digital",
                     "category_image": "https://hyper-m.cygnusa.in/images/noimage.jpg",
                   
                  }]
                
                console.log( this.cat_list ," this.cat_list ")
               
            } else if (data.result.status == 401 && data.result.response == 'failed') {
                this.router.navigateByUrl('');
            }
        });
}
onClickCategory(data){
    // this.catlist=false;
    // this.productlist=true;
    this.router.navigateByUrl('wallet/product_list/330' );
    // this.loader = true
    // this.server.get("redeem/category/"+data.category_id )
    //     .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);
}
}