window.Checkout = React.createClass({
    checkout: function (e) {
        let submitStatus = this.props.handleSubmit(e);
        this.generateCartItemsPost();
        if(submitStatus){
            document.instituteForm.submit();
        }
    },
    generateCartItemsPost: function () {
        let quantities = document.getElementsByClassName('productQuantity');
        let ISBNs = document.getElementsByClassName('productISBN');
        let productTitles = document.getElementsByClassName('productTitle');
        let productPrices = document.getElementsByClassName('productTotal');
        let cartContentsTotalCost = document.getElementById("totalCartPriceContainer").textContent;
        let products = [];

        for (let i = 0; i < quantities.length; ++i) {
            products.push({
                "quantity": quantities[i].textContent,
                "ean": ISBNs[i].textContent,
                "link": CCM_BASE_URL + '/' + ISBNs[i].textContent,
                "title": productTitles[i].textContent,
                "price": productPrices[i].textContent,

            });
        }

        products = JSON.stringify(products);
        document.getElementById('cartItemsPost').value = products.replace(/\"/g, "quot_");
        document.getElementById('cartTotalPricePost').value = cartContentsTotalCost;
    },
    render: function () {
        return (
            <div className="twelve columns back-next">
                <a style={{width: '143px', marginRight: '9px'}} className="grey large button" href="/education/cart"><i className="fa fa-shopping-cart">&nbsp;</i> Modify
                    cart</a><br className="breaker"/>
                <label for="submitOrder" className="green large button" onClick={this.checkout} id="submitOrder"><i className="fa fa-check-square-o">&nbsp;</i> Request
                    Order
                </label>
                <br/><br/>
            </div>
        );
    }
});