/**
 * 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 Istates {
    selectedIndex: number,
}

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

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

    gotoSelectRadio(index:any) {
        const { selectedIndex } = this.state;
        if (index === selectedIndex) {
            this.setState({
                selectedIndex: -1
            })
        } else {
            this.setState({
                selectedIndex: index
            })
        }
    }
    goToCheckout = () => {
        this.props.navigation.navigate('Checkout')
    }

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