import { Component, OnInit } from '@angular/core';
import { NavController } from '@ionic/angular';
import { WpServiceService } from '../wp-service.service';
import { ModalController, Platform } from '@ionic/angular';

import { CheckoutPage  } from '../checkout/checkout.page';

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

    searchText: string = '';
    prov: string = "all";
    catName: string = "all";
    products: any;
    
    constructor(public navCtrl: NavController, private wpservice: WpServiceService,public modalController: ModalController) { }

    ngOnInit() {
    }

    filterCat(catName) {
        if(catName == this.catName) {
            this.catName = "all";

        }else {
            this.catName = catName;
        }
        this.prov = "all";
    }

    async openCheckout() {
        const modal = await this.modalController.create({
            component: CheckoutPage,
            /*
            componentProps: {action: data}*/
        });
        return await modal.present();
    }
    ionViewWillEnter() {

        this.wpservice.getProducts().then( res => {
            console.log(res);
            this.products = JSON.parse(res['data']);
            console.log(this.products);
        },
            error => {
                console.log(error);
            }); 
    }
}
