{% extends "datacenterlight/base_hosting.html" %}
{% load staticfiles bootstrap3 i18n cms_tags humanize %}

{% block css_extra %}
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/paymentfont/1.1.2/css/paymentfont.min.css"/>
{% endblock css_extra %}

{% block navbar %}
    {% include "datacenterlight/includes/_navbar.html" %}
{% endblock navbar %}

{% block content %}
<!-- Credit card form -->
<div class="dcl-order-container">
    <div class="payment-container">
        <div class="dcl-payment-grid">
            <div class="dcl-payment-box">
                <div class="dcl-payment-section">
                    {% if request.user.is_authenticated %}
                        <div class="dcl-payment-user">
                            <h4>{% trans "Welcome back" %} {{request.user.name}}!</h4>
                            <p>{% trans "Review your billing address and card details and proceed to make payment." %}</p>
                        </div>
                    {% else %}
                        <h3>{%trans "Log in" %}</h3>
                        <hr class="top-hr">
                        <p style="margin-bottom: 20px;">{% blocktrans %}Already signed up?<br>By logging in you can retrieve saved billing information.{% endblocktrans %}</p>
                        <form role="form" id="login-form" method="post" action="" novalidate>
                            {% for field in login_form %}
                            {% csrf_token %}
                            {% bootstrap_field field show_label=False type='fields'%}
                            {% endfor %}
                            <p class="text-danger">{{login_form.non_field_errors|striptags}}</p>
                            <input type='hidden' name='next' value='{{request.path}}'/>
                            <div class="form-group text-right">
                                <button type="submit" class="btn btn-wide btn-vm-contact" name="login_form">{% trans "LOGIN" %}</button>
                            </div>
                        </form>
                        <p>
                            {% trans "Don't have an account yet?" %}<br>
                            {% trans "You can sign up by filling in the information below." %}<br>
                            <a href="{% url 'hosting:reset_password' %}" target="_blank">{% trans "Forgot password?" %}</a> or <a href="{% url 'hosting:resend_activation_link' %}" target="_blank">{% trans "Resend activation link" %}?</a>
                        </p>
                    {% endif %}
                </div>
            </div>
            <div class="dcl-payment-box">
                <div class="dcl-payment-section">
                    {% if not request.user.is_authenticated %}
                        <h3><b>{%trans "Sign up"%}</b></h3>
                    {% else %}
                        <h3><b>{%trans "Billing Address"%}</b></h3>
                    {% endif %}
                    <hr class="top-hr">
                    {% for message in messages %}
                        {% if 'duplicate_email' in message.tags %}
                        <p class="text-danger">{{message}}</p>
                        {% endif %}
                    {% endfor %}
                    <form role="form" id="billing-form" method="post" action="" novalidate>
                        {% csrf_token %}
                        {% for field in billing_address_form %}
                        {% bootstrap_field field show_label=False type='fields'%}
                        {% endfor %}
                    </form>
                </div>
            </div>
            <div class="dcl-payment-box">
                <div class="dcl-payment-section">
                    {% if generic_payment_form %}
                        <h3>{%trans "Make a payment" %}</h3>
                        <hr class="top-hr">
                        <form role="form" id="generic-payment-form" method="post" action="" novalidate>
                            {% csrf_token %}
                            <input type="hidden" name="product" value="1" />
                            {% for field in generic_payment_form %}
                            {% bootstrap_field field show_label=False type='fields'%}
                            {% endfor %}
                            <p class="text-danger">{{generic_payment_form.non_field_errors|striptags}}</p>
                        </form>
                    {% else %}
                        <h3>{%trans "Your Order" %}</h3>
                        <hr class="top-hr">
                        <div class="dcl-payment-order">
                            <p>{% trans "Cores"%} <strong class="pull-right">{{request.session.specs.cpu|floatformat}}</strong></p>
                            <hr>
                            <p>{% trans "Memory"%} <strong class="pull-right">{{request.session.specs.memory|floatformat}} GB</strong></p>
                            <hr>
                            <p>{% trans "Disk space"%} <strong class="pull-right">{{request.session.specs.disk_size|floatformat}} GB</strong></p>
                            <hr>
                            <p>{% trans "Configuration"%} <strong class="pull-right">{{request.session.template.name}}</strong></p>
                            <hr>
                            <p>
                                <strong>{%trans "Total" %}</strong>&nbsp;&nbsp;
                                <small>
                                    ({% if vm_pricing.vat_inclusive %}{%trans "including VAT" %}{% else %}{%trans "excluding VAT" %}{% endif %})
                                </small>
                                <strong class="pull-right">{{request.session.specs.price|intcomma}} CHF/{% trans "Month" %}</strong>
                            </p>
                            <hr>
                            {% if vm_pricing.discount_amount %}
                            <p class="mb-0">
                                {%trans "Discount" as discount_name %}
                                <strong>{{ vm_pricing.discount_name|default:discount_name }}</strong>&nbsp;&nbsp;
                                <strong class="pull-right text-primary">- {{ vm_pricing.discount_amount }} CHF/{% trans "Month" %}</strong>
                            </p>
                            <p>
                                ({% trans "Will be applied at checkout" %})
                            </p>
                            {% endif %}
                        </div>
                    {% endif %}
                </div>
            </div>
            <div class="dcl-payment-box">
                <div class="dcl-payment-section">
                    {% with card_list_len=cards_list|length %}
                    <h3><b>{%trans "Credit Card"%}</b></h3>
                    <hr class="top-hr">
                    <p>
                        {% if card_list_len > 0 %}
                        {% blocktrans %}Please select one of the cards that you used before or fill in your credit card information below. We are using <a href="https://stripe.com" target="_blank">Stripe</a> for payment and do not store your information in our database.{% endblocktrans %}
                        {% else %}
                        {% blocktrans %}Please fill in your credit card information below. We are using <a href="https://stripe.com" target="_blank">Stripe</a> for payment and do not store your information in our database.{% endblocktrans %}
                        {% endif %}
                    </p>
                        <div>
                            {% for card in cards_list %}
                                <div class="credit-card-info">
                                    <div class="col-xs-6 no-padding">
                                        <h5 class="billing-head">{% trans "Credit Card" %}</h5>
                                        <h5 class="membership-lead">{% trans "Last" %} 4: ***** {{card.last4}}</h5>
                                        <h5 class="membership-lead">{% trans "Type" %}: {{card.brand}}</h5>
                                    </div>
                                    <div class="col-xs-6 text-right align-bottom">
                                        <a class="btn choice-btn choice-btn-faded" href="#" data-id_card="{{card.id}}">{% trans "SELECT" %}</a>
                                    </div>
                                </div>
                            {% endfor %}
                            {% if card_list_len > 0 %}
                                <div class="new-card-head">
                                    <div class="row">
                                        <div class="col-xs-6">
                                            <h4>{% trans "Add a new credit card" %}</h4>
                                        </div>
                                        <div class="col-xs-6 text-right new-card-button-margin">
                                            <button data-toggle="collapse" data-target="#newcard" class="btn choice-btn">
                                                <span class="fa fa-plus"></span>&nbsp;&nbsp;{% trans "NEW CARD" %}
                                            </button>
                                        </div>
                                    </div>
                                </div>
                                <div id="newcard" class="collapse">
                                    <hr class="thick-hr">
                                    <div class="card-details-box">
                                        <h3>{%trans "New Credit Card" %}</h3>
                                        <hr>
                                        {% include "hosting/includes/_card_input.html" %}
                                    </div>
                                </div>
                            {% else%}
                                {% include "hosting/includes/_card_input.html" %}
                            {% endif %}
                        </div>
                    {% endwith %}
                </div>
            </div>
        </div>
    </div>
</div>

<!-- stripe key data -->
{% if stripe_key %}
{% get_current_language as LANGUAGE_CODE %}
<script type="text/javascript">
    window.processing_text = '{%trans "Processing" %}';
    window.enter_your_card_text = '{%trans "Enter your credit card number" %}';

    (function () {
        window.stripeKey = "{{stripe_key}}";
        window.current_lan = "{{LANGUAGE_CODE}}";
    })();
</script>
{%endif%}
{%endblock%}
