{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load authnames %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
<li><a href="{% url 'profile' %}">{% trans "Your profile" %}</a></li>
{% endblock %}

{% block content %}

{% if form.errors or userform.errors or subscriptionform.errors %}
{% show_message "error" _("Please fix errors in the form.") %}
{% endif %}

<form method="post" action="{% url 'profile' %}">
{% csrf_token %}

<ul class="nav nav-pills">
<li class="active"><a data-toggle="tab" href="#languages">{% trans "Languages" %}</a></li>
<li><a data-toggle="tab" href="#preferences">{% trans "Preferences" %}</a></li>
<li><a data-toggle="tab" href="#subscriptions">{% trans "Subscriptions" %}</a></li>
<li><a data-toggle="tab" href="#account">{% trans "Account" %}</a></li>
<li><a data-toggle="tab" href="#auth">{% trans "Authentication" %}</a></li>
<li><a data-toggle="tab" href="#profile">{% trans "Profile" %}</a></li>
<li><a data-toggle="tab" href="#licenses">{% trans "Licenses" %}</a></li>
<li><a data-toggle="tab" href="#api">{% trans "API access" %}</a></li>
{% if user.billing %}
<li><a data-toggle="tab" href="#billing">{% trans "Billing" %}</a></li>
{% endif %}
</ul>

<div class="tab-content">
<div class="tab-pane active" id="languages">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Languages" %}</h4></div>
  <div class="panel-body">
    {{ form|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>
      {% blocktrans %}Choose which languages you prefer to translate. These will be offered to you on the dashboard to have easier access to chosen translations.{% endblocktrans %}
    </p>
    <p>
      {% blocktrans %}The secondary languages are shown next to the source string when translating.{% endblocktrans %}
    </p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'languages' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="preferences">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Preferences" %}</h4></div>
  <div class="panel-body">
    {{ usersettingsform|crispy }}
    {{ dashboardsettingsform|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>
      {% blocktrans %}Customize Weblate behavior to match your personal preferences.{% endblocktrans %}
    </p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'preferences' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="subscriptions">
<div class="row">
<div class="col-lg-6">
{% with user.project_set.all as managed_projects %}
{% if managed_projects %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Managed projects" %}</h4></div>
  <div class="panel-body">
    <div class="list-group">
{% for project in managed_projects %}
      <a class="list-group-item" href="{{ project.get_absolute_url }}">{{ project }}</a>
{% endfor %}
    </div>
    <p class="helptext">{% trans "You will automatically receive important notifications on managed projects." %}</p>
  </div>
</div>
{% endif %}
{% endwith %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Subscribed projects" %}</h4></div>
  <div class="panel-body">
{% crispy subscriptionform %}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "You will receive chosen notifications via email for all your languages." %}</p>
    <p>{% trans "Subscribed projects are also shown on dashboard, so choose all projects you want to translate." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'subscriptions' %}">{% trans "Documentation" %}</a>
  </div>
</div>
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Subscription settings" %}</h4></div>
  <div class="panel-body">
{{ subscriptionsettingsform|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="account">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Account" %}</h4></div>
  <div class="panel-body">
{{ userform|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "Your name and email will appear as author on the commits." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="auth">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "User identities" %}</h4></div>
  <div class="panel-body">
<p>{% trans "You can manage identities which are associated to this account and which can be used to log in." %}</p>
<p>{% trans "Currently associated:" %}</p>
<table class="table table-condensed">
<thead>
<tr>
<th>{% trans "Identity" %}</th>
<th>{% trans "User ID" %}</th>
<th>{% trans "Action" %}</th>
</tr>
<tbody>
<tr>
<th>{% trans "Password" %}</th>
<td>{{ request.user.username }}</td>
<td>
<a href="{% url 'password' %}" class="btn btn-default">{% if request.user.has_usable_password %}{% trans "Change password" %}{% else %}{% trans "Set password" %}{% endif %}</a>
</td>
</tr>
{% for assoc in associated %}
<tr>
<th>{% auth_name assoc.provider '' ' ' %}</th>
<td>{{ assoc.uid }}</td>
<td>
{% if associated.count > 1 %}
<a href="{% url 'social:disconnect_individual' assoc.provider assoc.id %}?next={% url 'profile' %}" class="disconnect btn btn-danger"><i class="fa fa-trash"></i> {% trans "Disconnect" %}</a>
{% endif %}
</td>

</tr>
{% endfor %}
</tbody>
</table>

{% if new_backends %}
<p>{% trans "Add new association:" %}</p>
{% for name in new_backends %}
  <a class="btn btn-link" href="{% url 'social:begin' name %}?next={% url 'profile' %}">{% auth_name name %}</a>
{% endfor %}
{% endif %}
</div>
</div>


<div class="panel panel-danger">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Removal" %}</h4></div>
  <div class="panel-body">

    <p>{% trans "Removal of the account deletes all your private data." %}</p>
   </div>
   <div class="panel-footer">
    <a class="btn btn-danger" href="{% url 'remove' %}"><i class="fa fa-trash"></i> {% trans "Remove my account" %}</a>
   </div>
</div>

</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "You can configure how you will log in on this site." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'authentication' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>

</div>
<div class="tab-pane" id="profile">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Your summary" %}</h4></div>
  <div class="panel-body">
<table class="table table-condensed">
{% with request.user as user %}
{% include 'user-activity.html' %}
{% endwith %}
<tr>
{% url 'user_page' user=request.user.username as user_page%}
<th>{% trans "Your public profile" %}</th>
<td><a href="{{ user_page }}">{{ user_page }}</a></td>
</tr>
</table>
</div>
</div>

{% if enable_avatars %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Your avatar" %}</h4></div>
  <div class="panel-body">
<p class="border"><img src="{% url 'user_avatar' user=request.user.username size=128 %}" /></p>
<p><a href="https://www.libravatar.org/">{% trans "Avatars are provided using libravatar." %}</a></p>
</div>
</div>
{% endif %}

</div>

<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "Your public appearance on this site." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'avatar' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>

</div>

</div>

<div class="tab-pane" id="api">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "API access" %}</h4></div>
  <div class="panel-body">
<p>
<table class="table">
<tr>
<th>{% trans "Your personal API key:" %}</th>
<td>
    {{ user.auth_token.key }} 
    <a class="pull-right flip btn btn-default btn-xs" href="{% url 'reset-api-key' %}">{% trans "Regenerate" %}</a>
</td>
</tr>
<tr>
<th>{% trans "API root URL:" %}</th>
<td><a href="{{ site_url }}{% url 'api:api-root' %}">{{ site_url }}{% url 'api:api-root' %}</a></td>
</tr>
<tr>
<th colspan="2">{% trans "API usage example:" %}</th>
</tr>
<tr>
<td colspan="2">
<pre>
curl \
    -H "Authorization: Token {{ user.auth_token.key }}" \
    {{ site_url }}{% url 'api:api-root' %}
</pre>
</td>
</tr>
</table>
</p>

</div>
</div>

</div>

<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    {% doc_url 'api' as api_doc %}
    <p>{% blocktrans %}You can control Weblate using HTTP REST API. Please check <a href="{{ api_doc }}">API documentation</a> for more details.{% endblocktrans %}</p>
  </div>
</div>
</div>

</div>

</div>
<div class="tab-pane" id="licenses">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Licenses" %}</h4></div>
  <div class="panel-body">
<p>
{% trans "By registering you agree to use your name and email in the commits and provide your contribution under license defined by each translated project." %}
</p>

{% if licenses %}
<p>{% trans "Following translations have explicitly specified their licensing and copyright conditions:" %}</p>
<table class="table">
<thead>
<tr><th>{% trans "Project" %}</th><th>{% trans "License" %}</th></tr>
</thead>
<tbody>
{% for component in licenses %}
<tr>
<th><a href="{{ component.get_absolute_url }}">{{ component }}</a></th>
<td>
{% if component.license_url %}
<a href="{{ component.license_url }}">{{ component.license }}</a></p>
{% else %}
{{ component.license }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</div>

</div>

<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "Please pay attention to the licensing information as these specify how others are allowed to use your translations." %}</p>
  </div>
</div>
</div>

</div>

</div>

{% if user.billing %}
{% with user.billing as billing %}
<div class="tab-pane" id="billing">
<div class="row">

<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Billing plan" %}</h4></div>
  <div class="panel-body">

  {% with billing.plan as plan %}
  <table class="table">
  <tr><th>{% trans "Current plan" %}</th><td>{{ plan.name }} ({{ billing.get_state_display }})</td><td><a href="https://weblate.org/hosting/" class="btn btn-default btn-xs pull-right flip">{% trans "See other plans" %}</a></td></tr>
  <tr><th>{% trans "Monthly price" %}</th><td>{{ plan.price }} EUR</td><td></td></tr>
  <tr><th>{% trans "Yearly price" %}</th><td>{{ plan.yearly_price }} EUR</td><td></td></tr>
  <tr><th>{% trans "Strings limit" %}</th>
  {% with plan.limit_strings as max and plan.display_limit_strings as total and billing.count_strings as used %}
  {% include "billing-used.html" %}
  {% endwith %}
  </tr>
  <tr><th>{% trans "Languages limit" %}</th>
  {% with plan.limit_languages as max and plan.display_limit_languages as total and billing.count_languages as used %}
  {% include "billing-used.html" %}
  {% endwith %}
  </tr>
  <tr><th>{% trans "Repositories limit" %}</th>
  {% with plan.limit_repositories as max and plan.display_limit_repositories as total and billing.count_repositories as used %}
  {% include "billing-used.html" %}
  {% endwith %}
  </tr>
  <tr><th>{% trans "Projects limit" %}</th>
  {% with plan.limit_projects as max and plan.display_limit_projects as total and billing.projects.count as used %}
  {% include "billing-used.html" %}
  {% endwith %}
  </tr>
  </table>
  {% endwith %}
</div>
</div>
</div>

<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Invoices" %}</h4></div>
  <div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Invoice period" %}</th>
<th>{% trans "Invoice amount" %}</th>
<th>{% trans "Download invoice" %}</th>
</tr>
</thead>
<tbody>
{% for invoice in billing.invoice_set.all %}
<tr>
<td>{{ invoice.start|date:"SHORT_DATE_FORMAT" }} - {{ invoice.end|date:"SHORT_DATE_FORMAT" }}</td>
<td>{{ invoice.payment }} {{ invoice.get_currency_display }}</td>
<td>
{% if invoice.ref %}
<a href="{% url 'invoice-download' pk=invoice.pk %}">{{ invoice.filename }}</a>
{% else %}
{% trans "Not available" %}
{% endif %}
</td>
</tr>
{% empty %}
<tr><td colspan="3">{% trans "No invoices found!" %}</td/></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>

</div>

</div>
{% endwith %}
{% endif %}

</div>


</form>
<form method="post" action="" id="disconnect-form">{% csrf_token %}</form>

{% endblock %}
