import React from 'react';
import { View, Text, TextInput, StyleSheet, Button, ScrollView } from 'react-native';
import Axios from 'axios'
import { connect } from 'react-redux'
class MenuConfirmation extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            kasproBalance: '',
            kasproPoint: '',
            balanceused: 0,
            pointsused: 0,
            ongkir: 0,
            diskon: 0,
            totalOrder: 0
        }
    }

    render() {
        console.log(this.props)
        let total = 0
        return (
            <ScrollView style={styles.container}>
                {
                    this.props.order_item.map((item, index) => {
                            total = total + item.quantity * item.price
                        return (
                            <View style={{ margin: 10 }} key={index}>
                                <View style={{ flex: 1, margin: 10, flexDirection: 'row', justifyContent: 'space-around' }}>
                                    <View style={{ flex: 0.3, alignItems: 'center' }}>
                                        <Text>{item.quantity}</Text>
                                    </View>
                                    <View style={{ flex: 0.1, alignItems: 'flex-start' }}>
                                        <Text>x</Text>
                                    </View>
                                    <View style={{ flex: 0.3, alignItems: 'baseline' }}>
                                        <Text>{item.name} </Text>
                                    </View>
                                    <View style={{ flex: 0.3, alignItems: 'flex-end' }}>
                                        <Text>{item.quantity * item.price} </Text>
                                    </View>
                                </View>
                            </View>
                        )
                    })
                }
                <View style={{ alignItems: 'flex-end', borderTopWidth: 1, margin: 10, padding: 10 }}>
                    <Text>{total}</Text>
                </View>
                <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}>
                    <View style={{ margin: 10 }}>
                        <Text>Voucher Discount</Text>
                    </View>
                    <View style={{ margin: 10 }}>
                        <Text>0</Text>
                    </View>
                </View>
                <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}>
                    <View style={{ margin: 10 }}>
                        <Text>Delivery Charge</Text>
                    </View>
                    <View style={{ margin: 10 }}>
                        <Text>0</Text>
                    </View>
                </View>
                <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between', borderTopWidth: 1 }}>
                    <View style={{ margin: 10 }}>
                        <Text>Total</Text>
                    </View>
                    <View style={{ margin: 10 }}>
                        <Text>0</Text>
                    </View>
                </View>
                <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between', borderTopWidth: 1 }}>
                    <View style={{ margin: 10 }}>
                        <Text>Balance Used</Text>
                    </View>
                    <View style={{ margin: 10 }}>
                        <Text>{this.props.route.params.balanceUsed}</Text>
                    </View>
                </View>
                <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}>
                    <View style={{ margin: 10 }}>
                        <Text>Point Used</Text>
                    </View>
                    <View style={{ margin: 10 }}>
                        <Text>{this.props.route.params.pointused}</Text>
                    </View>
                </View>
                <View style={{ flexDirection: 'row', margin: 10, justifyContent: 'space-between' }}>
                    <View style={{ margin: 10 }}>
                        <Text>Delivery to</Text>
                    </View>
                    <View style={{ margin: 10 }}>
                        <Text>{this.props.address}</Text>
                    </View>
                </View>
                <View style={{ margin: 10 }}>
                    <Button title='order'/>
                </View>
            </ScrollView>
        )
    }
}

const styles = StyleSheet.create({

    container: {
        flex: 1,
        backgroundColor: 'white',
    },
    header: {

        flex: 0.5,
    },
    images: {
        margin: 10,
        flex: 2,
        backgroundColor: 'green'
    },
    content: {
        flex: 2,
    },
    body: {
        flex: 3,
    },

})

const mapStateToProps = (state) => {
    console.log(state)
    return {
        session_id: state.session_id,
        outlet_id: state.outlet_id,
        order_quantity: state.order_quantity,
        order_total: state.order_total,
        order_item: state.order_item,
        quantity: state.quantity,
        address: state.address
    }
}


export default connect(mapStateToProps)(MenuConfirmation)
