{% extends 'account_layout.html' %}
{% load i18n %}
{% load static %}

{% block pagetitle %}{% trans 'Your account' %}{% endblock %}
{% block headers %}
{% endblock %}

{% block account_content_outer %}
<div class="flex-page-content">
    {% if user_motd %}
    <div class="account-motd">
        <p> {{ user_motd | safe }} </p>
    </div>
    {% endif %}

    <div class="content-box account-status">
        <table>
            <tr>
                <td>{% trans "Username" %}</td>
                <td>{{user.username}}</td>
            </tr>
            <tr>
                <td>{% trans "Status" %}</td>
                <td class="account-status__status">
                    {% if user.vpnuser.is_paid %}
                    {% trans "ACTIVE" %}
                    {% else %}
                    {% trans "INACTIVE" %}
                    {% endif %}
                </td>
            </tr>
            <tr>
                <td>{% trans "Subscription" %}</td>
                <td>
                    {% if subscription.status == 'active' %}
                        {% blocktrans trimmed with until=subscription.next_renew|default:user.vpnuser.expiration|date:'Y-m-d' backend=subscription.backend.backend_verbose_name %}
                        <b>ACTIVE</b>. Renews on {{until}} via {{backend}}.
                        {% endblocktrans %}
                        (<a href="{% url 'payments:cancel_subscr' %}">{% trans "cancel" %}</a>)
                    {% else %}
                        -
                    {% endif %}
                </td>
            </tr>
            {% if not subscription or subscription.status != 'active' %}
            <tr>
                <td>{% trans "Expiration" %}</td>
                <td>
                    {{user.vpnuser.expiration|date:'Y-m-d H:i'|default:'-'}}
                    {% if user.vpnuser.is_paid %}
                        {% blocktrans trimmed with left=user.vpnuser.expiration|timeuntil %}
                        ({{ left }} left)
                        {% endblocktrans %}
                    {% endif %}
                </td>
            </tr>
            {% endif %}
        </table>

    </div>

    {% if not subscription %}
    <div class="content-box account-fund">
        <div class="account-payment-box account-payment-tabs">
            <div class="account-payment-tab">
                <input type="radio" name="type" id="tab_subscr" value="subscr" checked />
                <label for="tab_subscr"><span>{% trans 'Subscription' %}</span></label>
                <div class="tab-content">
                    <form action="/payments/new" method="post" class="pure-form pure-form-aligned centered-form">
                        {% csrf_token %}
                        <input type="hidden" name="recurring" value="1" />

                        <fieldset>
                            <div class="pure-control-group">
                                <label for="ino_time">{% trans 'Pay every' %}</label>
                                <select id="ino_time" name="plan" class="pure-input-1-2">
                                    <option value="3m">3 {% trans 'months' %} ({{price.3}})</option>
                                    <option value="6m">6 {% trans 'months' %} ({{price.6}})</option>
                                    <option value="12m">12 {% trans 'months' %} ({{price.12}})</option>
                                </select>
                            </div>

                            <div class="pure-control-group">
                                <label for="ino_method">{% trans 'by' %}</label>
                                <select id="ino_method" name="payment-method" class="pure-input-1-2">
                                    {% for backend in subscr_backends %}
                                        <option value="{{ backend.backend_id }}" {% if backend.backend_id == default_backend %}selected{% endif %}>
                                            {{ backend.backend_display_name }}
                                        </option>
                                    {% endfor %}
                                </select>
                            </div>

                            <div class="pure-controls">
                                <input type="submit" class="pure-button pure-button-primary"
                                       value="{% trans 'Subscribe' %}" />
                            </div>
                            <p>{% trans 'You can cancel the recurring payment at any time.' %}</p>
                        </fieldset>
                    </form>
                </div>
            </div>
            <div class="account-payment-tab">
                <input type="radio" name="type" id="tab_onetime" value="onetime" />
                <label for="tab_onetime"><span>{% trans 'One-time payment' %}</span></label>
                <div class="tab-content">
                    <form action="/payments/new" method="post" class="pure-form pure-form-aligned centered-form">
                        {% csrf_token %}
                        <input type="hidden" name="subscr" value="0" />

                        <fieldset>
                            <div class="pure-control-group">
                                <label for="ino_time">{% trans 'Add' %}</label>
                                <select id="ino_time" name="plan" class="pure-input-1-2">
                                    <option value="1m">1 {% trans 'month' %} ({{price.1}})</option>
                                    <option value="3m">3 {% trans 'months' %} ({{price.3}})</option>
                                    <option value="6m">6 {% trans 'months' %} ({{price.6}})</option>
                                    <option value="12m">12 {% trans 'months' %} ({{price.12}})</option>
                                </select>
                            </div>

                            <div class="pure-control-group">
                                <label for="ino_method">{% trans 'by' %}</label>
                                <select id="ino_method" name="payment-method" class="pure-input-1-2">
                                    {% for backend in backends %}
                                        <option value="{{ backend.backend_id }}" {% if backend.backend_id == default_backend %}selected{% endif %}>
                                            {{ backend.backend_display_name }}
                                        </option>
                                    {% endfor %}
                                </select>
                            </div>

                            <div class="pure-controls">
                                <input type="submit" class="pure-button pure-button-primary"
                                       value="{% trans 'Buy Now' %}" />
                            </div>
                            <p>{% trans 'If you still have time, the first payment will be delayed.' %}</p>
                        </fieldset>
                    </form>
                </div>
            </div>
            <div class="account-payment-tab">
                <input type="radio" name="type" id="tab_coupon" value="coupon" />
                <label for="tab_coupon"><span>{% trans 'Coupon' %}</span></label>
                <div class="tab-content">
                    <form action="{% url 'payments:redeem_coupon' %}" method="post" class="pure-form pure-form-aligned centered-form">
                        {% csrf_token %}

                        <fieldset>
                            <div class="pure-control-group">
                                <label for="ins_code">{% trans 'Code' %}</label>
                                <input type="text" id="ins_code" name="code" maxlength="32" class="pure-input-1-2"
                                    pattern="[ ]*[a-zA-Z0-9]{1,32}[ ]*" autocomplete="off" />
                            </div>
                            <div class="pure-controls">
                                <input type="submit" class="pure-button pure-button-primary"
                                    value="{% trans 'Use' %}" />
                            </div>
                            <p>{% trans 'Our coupons are alphanumeric codes that give you a fixed duration of VPN access.' %}<br />
                                {% trans 'They can be single or multi use.' %}
                            </p>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
    {% endif %}

    <div class="account-aff-box">
        <p>
            {% blocktrans trimmed %}
            Please recommend us to your friends and on social media!
            We do not advertise and rely on you to help us grow and improve our services.
            {% endblocktrans %}
            <br />
            {% blocktrans trimmed %}
            Every subscription through this link will grant you 1&nbsp;month of VPN access:
            {% endblocktrans %}
        </p>
        <form class="pure-form">
            <fieldset>
                <input type="text" size="30" value="{{ref_url}}" class="pure-input-1" />
            </fieldset>
        </form>
    </div>

</div>
{% endblock %}


