/**
 * Checkout sub-component
 * Handles the Continue Shopping and Checkout elements
 *
 * @type {*|Function}
 *
 * @author Rai Icasiano <ricasiano at cambridge dot org>
 */
window.Checkout = React.createClass({
    checkout: function () {
        this.props.setLoading(true);
        let quantity = document.getElementsByClassName('productQuantityList');
        let ISBN = document.getElementsByClassName('productISBNList');

        let products = [];

        for (let i = 0; i < quantity.length; ++i) {
            products.push({
                "quantity": quantity[i].value,
                "isbn": ISBN[i].value
            });
        }
        
        let successCallback = function () {
            window.location = '/education/africa_order_request_form';
        };

        let failCallback = function(componentReference) {
            componentReference.props.setAPIError(true);
            componentReference.props.setLoading(false);
        };
        
        postCart(this, successCallback, failCallback, products, '/education/africa_order_request_form');

    },
    render: function () {
        return (<div className="twelve columns grand_total_container">
            <div className="twelve columns noPadding alignRight">
                <div className="buttonsRow">
                    <a href="/education" className="button blue large arrow headerButton">Continue shopping</a>
                    <a onClick={this.checkout} className="button large green arrow">Proceed to Checkout</a>
                </div>
            </div>
        </div>);
    }
});