<!DOCTYPE html>

<!--
Keel (LDH middleware)
Copyright 2017-2019 Purism SPC
https://source.puri.sm/liberty/ldh_middleware
SPDX-License-Identifier: AGPL-3.0
-->

<html lang="en">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="{% static 'layout.css' %}"/>
    <link rel="stylesheet" href="{% static 'theme.css' %}"/>
    <title>{% trans "User profile" %}</title>
    <link rel="icon" sizes="960x960" href="{% static 'favicon.png' %}"/>
    <meta name="application-name" content="{{ site_title }}"/>
    <meta charset="UTF-8"/>
</head>

<body>

<header>

    <div id="title_box">
        <a href="{% url 'home' %}"><img class="logo" src="{% static 'logo.png' %}" alt="{{ site_title }}"/></a>
        <div id="title_text">
            <h1>{% trans "User profile" %}</h1>
            {% if haschosenreward and request.user.chosenreward.is_pending %}
            <div class="notice">
              <p>
              {% if request.user.account_type.is_basic %}
                Your registration is pending, please wait two minutes before refreshing this page.
              {% else %}
                Your registration is pending. If you completed the billing process, please wait two minutes before refreshing this page.
              </p>
                {% if not haspaid %}
                <p>If you have <strong><i>not</i></strong> completed the billing process, <a href="{{complete_signup_url}}">please do so now.</a>
                </p>
                <p>
                  Pending registrations are removed after 24 hours.
                </p>
                {% endif %}
              {% endif %}
            </div>
            {% else %}
            <p>{% trans "Service credit and profile management" %}</p>
            {% endif %}
        </div>
    </div>

    <div id="log_state">
        {% if request.user.is_authenticated %}
        {% trans "Logged in as" %} {{ username }}<br/>
        <em>{% trans "Profile" %}</em> |

        {% if request.user.is_superuser %}
        <a href="{% url 'admin:index' %}">{% trans "Admin" %}</a> |
        {% endif %}

        <a href="{% url 'auth_logout' %}">{% trans "Log out" %}</a>
        {% else %}
        {% trans "You are not logged in." %}<br/>
        <a href="{% url 'auth_login' %}">{% trans "Log in" %}</a>
        <!--
        {% trans "or" %}
        <a href="{% url 'registration_register' %}">{% trans "register." %}</a>
        -->
        {% endif %}
    </div>
</header>

<hr/>

{% if (haschosenreward and not request.user.chosenreward.is_pending) or not haschosenreward %}
<main class="col-wrapper form">
    <article class="col-1">

        <h2>{% trans "Services" %}</h2>

        <table>

            <thead>
            <tr>
                <th>{% trans "Service" %}</th>
                <th>{% trans "Active" %}</th>
                <th>{% trans "Renews/Expires" %}</th>
                <th>{% trans "Credit" %}</th>
                <th>{% trans "Actions" %}</th>
            </tr>
            </thead>

            <tbody>
            {% for limit in limits %}
              {% if limit.service_label() != 'Group' %}
            <tr>
              <th class="row_header">{{ limit.service_label() }}</th>
              </th>
                <td>{{ limit.active_label() }}</td>
                <td title="{{ limit.endpoint_full_label() }}">{{ limit.endpoint_short_label() }}</td>
                <td>{{ limit.credit_label() }}</td>
                <td>
                  <form method="post" action="{{ action_function[limit.service_label().upper()] }}">
                    {% csrf_token %}
                    {% if limit.is_active and limit.service_activable_by_user() %}
                    <input type="submit" value="Deactivate"/>
                    {% elif not limit.is_active and limit.service_activable_by_user() %}
                    <input type="submit" value="Activate"/>
                    {% else %}
                    <input type="submit" value="---" disabled/>
                    {% endif %}
                    <input type="hidden" name="enable_tunnel" value="{{ not limit.is_active }}"/>
                  </form>
                </td>
            </tr>
              {% endif %}
            {% endfor %}
            </tbody>

        </table>

        {% if has_limit["GROUP"]%}

          <h2>{% trans "Group members" %}</h2>
            <ul>
              {% if invitations['no_members'] %}
                <li>{% trans "None" %}</li>
              {% else %}
                {% for invitation in invitations['list'] %}
                  {% if invitation['consumed'] %}
                    <li>{{ invitation.guest }}</li>
                  {% endif %}
                {% endfor %}
              {% endif%}
            </ul>
          <h2>{% trans "Group invites" %}</h2>
            <ul>
              {% if not invitations['links_not_used'] %}
                <li>{% trans "No pending links" %}</li>
              {% else %}
                {% for invitation in invitations['list'] %}
                  {% if not invitation['expired'] and not invitation['consumed'] %}
                    <li><a href="{{ invitation["link"] }}">{{ invitation["link"] }}</a></li>
                  {% endif %}
                {% endfor %}
              {% endif %}
            </ul>
          <form method="post" action="{% url 'new_invitation' %}">
            {% csrf_token %}
                    {% if invitations["full"] %}
                    <input type="submit" value="New invitation" disabled/>
                    {% else %}
                    <input type="submit" value="New invitation"/>
                    {% endif %}
          </form>

        {% endif %}

        <h2>{% trans "Profile management" %}</h2>

        <ul>
            <li><a href="{% url 'password_change' %}">{% trans "Change password" %}</a></li>
            <li><a href="{% url 'profile_configure' %}">{% trans "Profile settings" %}</a></li>
            <li><a href="{% url 'delete_account' %}">{% trans "Delete Account" %}</a></li>
            {% if can_upgrade  or pending_upgrade %}
            <li><a href="{% url 'upgrade' %}">{% trans "Manage Subscription" %}</a></li>
            {% endif %}
        </ul>

    </article>
    <nav class="col-2">
        <ul>

            {% for section, link_ordered_dict in link_profile_ordered_dict.items() %}
            <li>
                {{ section }}
                <ul>

                    {% for name, link in link_ordered_dict.items() %}
                    <li><a href="{{ link }}" class="page">{{ name }}</a></li>
                    {% endfor %}

                </ul>
            </li>
            {% endfor %}

        </ul>
    </nav>
</main>
{% endif %}
<footer>
    <div id="footer_block">

        <p>
            <em>{{ site_title }}</em> provided by <a href="{{ site_provider_link }}">{{ site_provider }}</a><br />
            Code shared under AGPL-3.0-or-later
            (<a href="https://source.puri.sm/liberty/ldh_middleware">project</a>,
            <a href="{% url 'download-zip' %}">source</a>,
            <a href="{% url 'jslicense' %}" rel="jslicense">javascript</a>)
        </p>

    </div>
</footer>

</body>
</html>
