/**
 * React Native Full App (https://store.enappd.com/product/react-native-full-app)
 *
 * Copyright © 2019-present Enappd. All rights reserved.
 *
 * This source code is licensed as per the terms found in the
 * LICENSE.md file in the root directory of this source tree.
 */
import React, { Component } from 'react';
import ProductListView from './productListView';
import { NavigationStackScreenProps } from 'react-navigation-stack';

interface Iprops extends NavigationStackScreenProps {

}
interface Istate {
    segment: boolean,
    text: number,
    button: boolean,
    remove: string,
    add: string,
}

class ProductListContainer extends Component<Iprops,Istate> {

    constructor(props:Iprops) {
        super(props)
         this.state = {
            segment: false,
            text: 0,
            button: true,
            remove: 'red',
            add: 'red',
        }
    }
    goBack = () => {
         this.props.navigation.goBack()
    }
    goForProductdetails(items:any) {
         this.props.navigation.navigate('GroceryProductdetails', { items })
    }
    goToMyCart = () => {
        this.props.navigation.navigate('GroceryMycart')
    }
    gotoAdd = () => {
        this.setState({
            text: 1
        })
    }
    addCount = () => {
        this.setState({
            text: this.state.text + 1,
            add: 'green',
            remove: 'red',
        })
    }

    subtractCount = () => {
        this.setState({
            text: this.state.text - 1,
            add: 'red',
            remove: 'green',
        })
    }
    render() {
        const productDetails = this.props.navigation.getParam('products');
         return (
            <ProductListView
                productDetails={productDetails}
                goBack={this.goBack}
                title={productDetails.name}
                goForProductdetails={(items:any) => this.goForProductdetails(items)}
                goToMyCart={this.goToMyCart}
                gotoAdd={this.gotoAdd}
                subtractCount={this.subtractCount}
                remove={this.state.remove}
                text={this.state.text}
                addCount={this.addCount}
                add={this.state.add}
            />
        )
    }

}
export default ProductListContainer;
