/**
 * 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 from 'react';
import DeliveryViewComponent from './deliveryView';
import { NavigationStackScreenProps } from 'react-navigation-stack';

interface Iprops extends NavigationStackScreenProps {

}
interface Istate {
    selectedIndex: any;
}

class DeliveryContainerComponent extends React.Component<Iprops,Istate> {
    constructor(props: Iprops) {
        super(props)
        this.state = {
            selectedIndex: null
        }
    }

    goBack = () => {
        this.props.navigation.goBack()
    }

    gotoSelectRadio(index:number) {
        const { selectedIndex } = this.state;
        if (index === selectedIndex) {
            this.setState({
                selectedIndex: null
            })
        } else {
            this.setState({
                selectedIndex: index
            })
        }
    }
    goToCheckout = () => {
        this.props.navigation.navigate('GroceryCheckout')
    }
    setSlectedTabs() {
        this.setState({
            selectedIndex: null
        })
    }

    render() {
        const { selectedIndex } = this.state;
        const addressLocation = 'Delivery Address'
        return (
            <DeliveryViewComponent
                addressLocation={addressLocation}
                goBack={this.goBack}
                selectedIndex={selectedIndex}
                gotoSelectRadio={(index:number) => this.gotoSelectRadio(index)}
                goToCheckout={this.goToCheckout}
                setSlectedTabs={() => this.setSlectedTabs()}
            />
        )
    }
}
export default DeliveryContainerComponent;
