var React = require('react'),
    Globals = require('../../globals');;

var Router = require('react-router');



var CartTotal = React.createClass({

            render: function() {
                var counts = this.props.itemCounts;

                var total = 0;

                if (counts && this.props.items) {
                    var items = this.props.items.models;
                    for (var i = 0; i < items.length; i++) {
                        var item = items[i];
                        var count = counts[item.get('id')].get('count');
                        var price = item.get('list_price');
                        total += (price * count)
                    };
                }
                if (this.props.deliveryCosts) {
                    if (this.props.instantDelivery) {
                        total += Number(this.props.deliveryCosts.get('instant_delivery_price'))
                    } else {
                        total += Number(this.props.deliveryCosts.get('delivery_price'))
                    }
                }

                return ( < span > {
                            Globals.FormatCurrency(total)
                        } < /span>);   
    }

});


module.exports = CartTotal;