<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="cart" tagdir="/WEB-INF/tags/responsive/cart" %>
<%@ taglib prefix="cms" uri="http://hybris.com/tld/cmstags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="ycommerce" uri="http://hybris.com/tld/ycommercetags" %>
<%@ taglib prefix="importData" tagdir="/WEB-INF/tags/addons/braintreeb2baddon/responsive/util/pages" %>

<jsp:include page="../../../messages/braintreeErrorMessages.jsp"/>

<c:set var="srcEnabled" scope="session" value="${braintreeConfigData.srcConfigurationData.enabled}"/>
<c:set var="srcImgUrl" scope="session" value="${braintreeCheckoutData.srcPaymentMethod.srcImgUrl}"/>
<c:set var = "payPalExpressEnabled" scope = "session" value = "${braintreeConfigData.payPalConfigurationData.expressCheckout}"/>
<c:set var = "applePayEnabled" scope = "session" value = "${braintreeConfigData.applePayConfigurationData.enabled}"/>
<c:set var="applePayOnExpressCheckoutEnabled" scope="session" value="${braintreeConfigData.applePayConfigurationData.expressCheckout}"/>
<c:set var = "googlePayEnabled" scope = "session" value = "${braintreeConfigData.googlePayConfigurationData.enabled}"/>
<c:set var="googlePayOnExpressCheckoutEnabled" scope="session" value="${braintreeConfigData.googlePayConfigurationData.expressCheckout}"/>
<c:set var="dropInEnabled" scope="session" value="${braintreeConfigData.generalConfigurationData.dropIn}"/>
<c:set var="isAnonymousUser" scope = "session" value = "${isAnonymousUser}"/>

<c:url value="/cart/checkout" var="checkoutUrl" scope="session"/>
<div class="row">
    <div class="col-xs-12 col-sm-10 col-md-7 col-lg-6 pull-right cart-actions--print">
        <div class="express-checkout">
            <div class="headline"><spring:theme code="text.expresscheckout.header"/></div>
            <strong><spring:theme code="text.expresscheckout.title"/></strong>
            <ul>
                <li><spring:theme code="text.expresscheckout.line1"/></li>
                <li><spring:theme code="text.expresscheckout.line2"/></li>
                <li><spring:theme code="text.expresscheckout.line3"/></li>
            </ul>
            <sec:authorize access="isFullyAuthenticated()">
                <c:if test="${expressCheckoutAllowed}">
                    <div class="checkbox">
                        <label>
                            <c:url value="/checkout/multi/express" var="expressCheckoutUrl" scope="session"/>
                            <input type="checkbox" class="express-checkout-checkbox" data-express-checkout-url="${expressCheckoutUrl}">
                            <spring:theme text="I would like to Express checkout" code="cart.expresscheckout.checkbox"/>
                        </label>
                    </div>
                </c:if>
            </sec:authorize>
        </div>
        <div id="globalMessages"></div>
        <div id="cart-page-container">
        <c:choose>
            <c:when test="${dropInEnabled}">
                <importData:importCartCheckoutData  braintreeCheckoutData="${braintreeCheckoutData}" braintreeConfigData="${braintreeConfigData}" cartPage="cartPage"/>

                <c:choose>
                    <c:when test="${isAnonymousUser}">
                        <div style="display: none" id="dropin-container" class="dropin-container-express-checkout hidden"></div>
                    </c:when>
                    <c:otherwise>
                        <div id="dropin-container" class="dropin-container-express-checkout hidden"></div>
                    </c:otherwise>
                </c:choose>

                <div class="bt_center">
                <cms:pageSlot position="PayPalCartPageCreditMessageB2B" var="feature" element="div">
                    <cms:component component="${feature}" />
                </cms:pageSlot>
                </br>
                </div>
                <div class="orSeparator bt_center">
                    <spring:theme code="braintree.cart.or"/>
                </div>

                <div class="cart-actions">
                    <div class="row">
                        <div class="col-sm-3 col-md-4 pull-right">
                            <button class="btn btn-primary btn-block btn--continue-checkout js-continue-checkout-button"
                                    data-checkout-url="${checkoutUrl}"><spring:theme code="checkout.checkout"/></button>
                        </div>

                        <div class="col-sm-5 pull-right">
                            <button class="btn btn-default btn-block btn--continue-shopping js-continue-shopping-button"
                                    data-continue-shopping-url="${continueShoppingUrl}"><spring:theme text="Continue Shopping"
                                                                                                      code="cart.page.continue"/></button>
                        </div>
                        <cart:saveCart/>
                    </div>
                </div>
            </c:when>
            <c:when test="${payPalExpressEnabled or applePayEnabled or googlePayEnabled or srcEnabled and !dropInEnabled}">
                <importData:importCartCheckoutData  braintreeCheckoutData="${braintreeCheckoutData}" braintreeConfigData="${braintreeConfigData}" cartPage="cartPage"/>
                <script>
                  var payPalButtonConfig = ${not empty payPalButtonConfig ? payPalButtonConfig : '{}'};
                  var googlePayButtonConfig = ${not empty googlePayButtonConfig ? googlePayButtonConfig : '{}'};
                  var payPalShouldBeSaved = "${payPalShouldBeSaved}";
                  var contextPath = "${request.contextPath}";
                  var applePayShape = "${not empty applePayButtonConfig.shape ? applePayButtonConfig.shape : 'pill'}";
                  var applePayExpressEnabled = ${applePayOnExpressCheckoutEnabled};
                </script>
                <sec:authorize access="hasAnyRole('ROLE_ANONYMOUS')">
                    <script>
                      isAnonymous = true;
                    </script>
                </sec:authorize>
                <div class="row cart-actions">
                    <div id="paypal_express_error bt_right"></div>

                </div>
                <div class="row cart-actions">
                    <div class="col-sm-6">

                    </div>
                    <div class="col-sm-6">
                        <div class="bt_center">
                            <div id="paypal_express_error"></div>
                            <c:if test="${applePayEnabled and applePayOnExpressCheckoutEnabled and !isAnonymousUser}">
                                <style>
                                    .apple-pay-button {
                                        display: inline-block;
                                        -webkit-appearance: -apple-pay-button;
                                        -apple-pay-button-type: ${not empty applePayButtonConfig.type ? applePayButtonConfig.type : 'check-out'};
                                        -apple-pay-button-style: ${not empty applePayButtonConfig.color ? applePayButtonConfig.color : 'white'};
                                        -apple-pay-button-border-radius: 0px;
                                    }
                                </style>
                                <div id="apple-pay-button" class="apple-pay-button apple-pay-button-container hide"></div>
                            </c:if>
                            <div id="paypal-button" class="paypal-button paypal_button_container paypal-button-horizontal"></div>
                            <cms:pageSlot position="PayPalCartPageCreditMessageB2B" var="feature" element="div">
                                <cms:component component="${feature}" />
                            </cms:pageSlot>
                            </br>
                            <c:if test="${!payPalExpressEnabled || isAnonymousUser}">
                                <script>
                                  document.getElementById('paypal-button').style.display = "none";
                                </script>
                            </c:if>
                            <c:if test="${googlePayEnabled and googlePayOnExpressCheckoutEnabled and !isAnonymousUser}">
                                <div id="google-pay-button" class="google_pay_container"></div>
                            </c:if>
                            <c:if test="${srcEnabled and !isAnonymousUser}">
                                <div id="src-button" class="src_container">
                                    <img src="${srcImgUrl}" alt="Visa Checkout" class="v-button" role="button"/>
                                </div>
                            </c:if>
                        </div>
                        <div class="orSeparator bt_center">
                            <spring:theme code="braintree.cart.or"/>
                        </div>
                    </div>
                </div>
                <div class="cart-actions">
                    <div class="row">
                        <div class="col-sm-3 col-md-4 pull-right">
                            <button class="btn btn-primary btn-block btn--continue-checkout js-continue-checkout-button"
                                    data-checkout-url="${checkoutUrl}"><spring:theme code="checkout.checkout"/></button>
                        </div>

                        <div class="col-sm-5 pull-right">
                            <button class="btn btn-default btn-block btn--continue-shopping js-continue-shopping-button"
                                    data-continue-shopping-url="${continueShoppingUrl}"><spring:theme text="Continue Shopping"
                                                                                                      code="cart.page.continue"/></button>
                        </div>
                        <cart:saveCart/>
                    </div>
                </div>

            </c:when>

            <c:otherwise>
                <importData:importCartCheckoutData  braintreeCheckoutData="${braintreeCheckoutData}" braintreeConfigData="${braintreeConfigData}" cartPage="cartPage"/>

                <div class="row cart-actions">
                    <div class="col-sm-6"></div>

                    <div class="col-sm-6">
                        <div class="bt_center">

                            <div id="paypal-button" class="paypal-button paypal_button_container paypal-button-horizontal"></div>
                            <cms:pageSlot position="PayPalCartPageCreditMessageB2B" var="feature" element="div">
                                <cms:component component="${feature}" />
                            </cms:pageSlot>
                            </br>
                            <c:if test="${!payPalExpressEnabled}">
                                <script>
                                  document.getElementById('paypal-button').style.display = "none";
                                </script>
                            </c:if>

                        </div>
                    </div>
                </div>

                <div class="cart-actions">
                    <div class="row">
                        <div class="col-sm-3 col-md-4 pull-right">
                            <button class="btn btn-primary btn-block btn--continue-checkout js-continue-checkout-button"
                                    data-checkout-url="${checkoutUrl}"><spring:theme code="checkout.checkout"/></button>
                        </div>

                        <div class="col-sm-5 pull-right">
                            <button class="btn btn-default btn-block btn--continue-shopping js-continue-shopping-button"
                                    data-continue-shopping-url="${continueShoppingUrl}"><spring:theme text="Continue Shopping"
                                                                                                      code="cart.page.continue"/></button>
                        </div>
                        <cart:saveCart/>
                    </div>
                </div>

            </c:otherwise>
        </c:choose>
    </div>
    </div>
</div>

<c:if test="${showCheckoutStrategies && not empty cartData.entries}">
    <div class="cart-actions">
        <div class="row">
            <div class="col-xs-12 col-sm-5 col-md-3 col-lg-2 pull-right">
                <input type="hidden" name="flow" id="flow"/>
                <input type="hidden" name="pci" id="pci"/>
                <select id="selectAltCheckoutFlow" class="doFlowSelectedChange form-control">
                    <option value="multistep"><spring:theme code="checkout.checkout.flow.select"/></option>
                    <option value="multistep"><spring:theme code="checkout.checkout.multi"/></option>
                    <option value="multistep-pci"><spring:theme code="checkout.checkout.multi.pci"/></option>
                </select>
                <select id="selectPciOption" class="display-none">
                    <option value=""><spring:theme code="checkout.checkout.multi.pci.select"/></option>
                    <c:if test="${!isOmsEnabled}">
                        <option value="default"><spring:theme code="checkout.checkout.multi.pci-ws"/></option>
                        <option value="hop"><spring:theme code="checkout.checkout.multi.pci-hop"/></option>
                    </c:if>
                    <option value="sop"><spring:theme code="checkout.checkout.multi.pci-sop" text="PCI-SOP"/></option>
                </select>
            </div>
        </div>
</c:if>
</div>
