
{% load i18n %}

<table class="plan_table">
    <thead>
    <tr>
        <th></th>
        {% for plan in plan_list %}
            <th class="plan_header {% ifequal forloop.counter0 current_userplan_index %}current{% endifequal %}">
                {% if plan.url %}<a href="{{ plan.url }}" class="info_link plan">{% endif %}
                <span class="plan_name">{{  plan.name }}</span>
                <span class="plan_description">{{ plan.description }}</span>
                {% if plan == userplan.plan %}
                    <span class="current current_plan">{% trans "your current plan" %}</span>
                {% endif %}
                {% if plan.url %}</a>{% endif %}
            </th>
        {% endfor %}
    </tr>

    </thead>
    <tbody>
    {% for quota_row in plan_table %}
        <tr class="quota_row">

            <th class="quota_header">
                {% if quota_row.0.url %}<a href="{{ quota_row.0.url }}" class="info_link quota">{% endif %}
                <span class="quota_name">{{ quota_row.0.name }}</span>
                <span class="quota_description">{{ quota_row.0.description }}</span>
                {% if quota_row.0.url %}</a>{% endif %}
            </th>

            {% for plan_quota in quota_row.1 %}

                <td class="{% ifequal forloop.counter0 current_userplan_index %}current{% endifequal %}">
                    {% ifnotequal plan_quota None %}
                        {% if quota_row.0.is_boolean %}
                            {% if plan_quota.value %} + {% else %} - {% endif %}
                        {% else %}
                            {% if plan_quota.value == None %}{% trans 'no limit' %}{% else %}{{ plan_quota.value }} {{ quota_row.0.unit }}{% endif %}
                        {% endif %}
                    {% endifnotequal %}
                </td>
            {% endfor %}

        </tr>
    {% endfor %}
    </tbody>
    <tfoot>
    <tr>
        <th></th>
        <th colspan="{{ plan_list|length }}" class="periods_footer">{% trans 'Pricings' %}</th>
    </tr>

    {% if user.is_authenticated %}

    <tr>
        <th></th>
        {% for plan in plan_list %}
        <th class="planpricing_footer {% ifequal forloop.counter0 current_userplan_index %}current{% endifequal %}">
            {% if plan != userplan.plan and not userplan.is_expired and not userplan.plan.is_free and userplan.plan %}
                <a href="{% url 'create_order_plan_change' pk=plan.id %}" class="change_plan">{% trans "Change" %}</a>
            {% endif %}
        </th>
        {% endfor %}
    </tr>

    {% endif %}

    <tr>
        <th></th>
        {% for plan in plan_list %}
            <th class="planpricing_footer {% ifequal forloop.counter0 current_userplan_index %}current{% endifequal %}">
                {% if plan.available %}
                    <ul>
                    {% if not plan.is_free %}
                        {% for plan_pricing in plan.planpricing_set.all %}
                            <li>
                            {% if plan_pricing.pricing.url %}<a href="{{ plan_pricing.pricing.url }}" class="info_link pricing">{% endif %}
                            <span class="plan_pricing_name">{{ plan_pricing.pricing.name }}</span>
                            <span class="plan_pricing_period">({{ plan_pricing.pricing.period }} {% trans "days" %})</span>
                            {% if plan_pricing.pricing.url %}</a>{% endif %}
                            <span class="plan_pricing_price">{{ plan_pricing.price }}&nbsp;{{ CURRENCY }}</span>
                            {% if plan_pricing.plan == userplan.plan or userplan.is_expired or userplan.plan.is_free %}
                            <a href="{% url 'create_order_plan' pk=plan_pricing.pk %}" class="buy">{% trans "Buy" %}</a>
                            {% endif %}
                        {% endfor %}
                    {% else %}
                        {# Allow selecting plans with no pricings #}
                        <li>
                            <span class="plan_pricing_name">{% trans "Free" %}</span>
                            <span class="plan_pricing_period">({% trans "no expiry" %})</span>
                            <span class="plan_pricing_price">0&nbsp;{{ CURRENCY }}</span>
                            {% if plan != userplan.plan or userplan.is_expired %}
                                <a href="{% url 'create_order_plan_change' pk=plan.id %}" class="change_plan">
                                    {% if userplan.is_expired or not userplan.plan %}
                                        {% trans "Select" %}
                                    {% else %}
                                        {% trans "Change" %}
                                    {% endif %}
                                </a>
                            {% endif %}
                        </li>
                    {% endif %}
                    </ul>

                   {% else %}
                     <span class="plan_not_available">
                    {% url 'upgrade_plan' as upgrade_url %}
                    {% blocktrans %}
                        This plan is not available anymore and cannot be extended.<p>
                        You need to upgrade your account to any of <a href="{{ upgrade_url }}">currently available plans</a>.
                    {% endblocktrans %}
                    </span>

                {% endif %}
            </th>
        {% endfor %}
    </tr>

    </tfoot>
</table>

<p style="text-align: right;">
    {% trans "Net prices" %}

</p>