import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ModalController } from 'ionic-angular';
import { HealthProvider } from '../../providers/health/health';
import { DetailPage } from '../detail/detail';

/**
 * Generated class for the ProductCatDetailPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-product-cat-detail',
  templateUrl: 'product-cat-detail.html',
})
export class ProductCatDetailPage {
  products;
  imageURL: string;
  catTitle: string;
  constructor(public navCtrl: NavController, public navParams: NavParams, private hp: HealthProvider, private mc: ModalController) {
    console.log(JSON.stringify(this.navParams));
    console.log(this.navParams.get('catId'));
    this.catTitle = this.navParams.get('catTitle');
    this.imageURL = this.hp.imageURL;
    this.hp.getProductsByCat(this.navParams.get('catId'))
      .subscribe(data => {
        console.log("data => ", JSON.stringify(data.output)); 
        this.products = data.output;
      });

  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad ProductCatDetailPage');
  }

  openProductDetail(p) {
    let modal = this.mc.create(DetailPage, { id: p._id.$oid});
    modal.present();

  }

}
