import React from 'react';
import Total from './total.jsx';

const propTypes = {
    cartApi: React.PropTypes.object.isRequired,
    shipmentApi: React.PropTypes.object.isRequired,
    languageApi: React.PropTypes.object.isRequired
};

export default class TotalContainer extends React.Component {

    static get defaultProps(){
        return {
            cartApi: {},
            shipmentApi: {},
            languageApi: {}
        };
    }

    getShipmentPrice() {
        const { methods, selectedMethodId } = this.props.shipmentApi.state;
        var selected = methods.filter(method => method.id == selectedMethodId).pop();
        return selected && selected.price ? selected.price.formatted : null;
    }

    render() {
        const { totalPrice, taxPrice, totalDiscount } = this.props.cartApi.state;
        return <Total
            totalPrice={totalPrice.formatted}
            shipmentPrice={this.getShipmentPrice()}
            taxPrice={taxPrice.formatted}
            totalDiscount={totalDiscount.formatted}
            language={this.props.languageApi.state.total}
            />;
    }
}

TotalContainer.propTypes = propTypes;