{% extends 'user/base.html'  %}
{% load core i18n profile_tags assets common_tags %}

{% block body_id %}profile-page{% endblock %}

{% block header_block %}{% endblock %}

{% block content %}
<div id="user-profile" lang="{{ LANGUAGE_CODE }}">

  <div id="user-meta">
    <img src="{{ object|gravatar:150 }}" width="150" height="150" class="avatar"
    {% if user == object %} title="{% trans "You can set or change your avatar image at www.gravatar.com" %}"{% endif %} />
    <h1 class="user-name">
      {% if object.is_anonymous %}
        {% trans 'Anonymous User' %}
      {% else %}
        {{ object.display_name }}
      {% endif %}
    </h1>
    {% if user_is_manager %}
    <p><a class="admin" href="mailto:{{ object.email }}">{{ object.email }}</a></p>
    {% endif %}
  </div>

{% if not object.is_meta %}
  <div id="user-stats">
    <h2 class="user-score-title">{% trans 'Score:' %}</h2>
    <h3 class="user-score">
      {% if user == object and object.public_score > 0 %}
        <a class="js-popup-tweet" href="https://twitter.com/share?text={% filter urlencode %}{% blocktrans with server_title=settings.POOTLE_TITLE score=object.public_score %}My current score at {{ server_title }} is {{ score }} {% endblocktrans %}{% endfilter %}" title="{% blocktrans %}Tweet this!{% endblocktrans %}">{{ object.public_score }}</a>
      {% else %}
        {{ user_score }}
      {% endif %}
    </h3>

    <h3 class="user-position">
    {% with pos=user_top_language.0 lang=user_top_language.1 %}
    {% if pos == -1 %}
      {% trans 'No contributions in the last 30 days' %}
    {% else %}
      {% if user == object %}
        <a class="js-popup-tweet" href="https://twitter.com/share?text={% filter urlencode %}{% blocktrans with server_title=settings.POOTLE_TITLE lang_name=lang.name url=lang.get_absolute_url %}I am #{{ pos }} contributor in {{ lang_name }} in the last 30 days at {{ server_title }}! {% endblocktrans %}{% endfilter %}" title="{% blocktrans %}Tweet this!{% endblocktrans %}">
          {% blocktrans with lang_name=lang.name trimmed %}
          #{{ pos }} contributor in {{ lang_name }} in the last 30 days
          {% endblocktrans %}
        </a>
      {% else %}
        {% blocktrans with lang_name=lang.name url=lang.get_absolute_url trimmed %}
        #{{ pos }} contributor in <a href="{{ url }}">{{ lang_name }}</a> in the last 30 days
        {% endblocktrans %}
      {% endif %}
    {% endif %}
    {% endwith %}
    </h3>

    {% with last_event=object.last_event %}
    {% if last_event %}
    <div class="user-last-activity">
      <div class="label">{% trans 'Latest activity:' %}</div>
      <div class="last-action">
	{% avatar object.username object.email_hash 20 %}
	<span class="user-info">{{ last_event.message }} {{ last_event.since }}</span>
      </div>
    </div>
    {% endif %}
    {% endwith %}
  </div>

  {% if object.bio or object.has_contact_details or user == object %}
  <div id="user-details">
    {% if object.has_contact_details %}
    <ul class="user-contact">
      {% if object.website %}
      <li><a href="{{ object.website }}"><i class="icon-user-website"></i>{% trans 'My Website' %}</a></li>
      {% endif %}
      {% if object.twitter %}
      <li><a href="{{ object.twitter_url }}"><i class="icon-user-twitter"></i>@{{ object.twitter }}</a></li>
      {% endif %}
      {% if object.linkedin %}
      <li><a href="{{ object.linkedin }}"><i class="icon-user-linkedin"></i>{% trans 'My LinkedIn Profile' %}</a></li>
      {% endif %}
    </ul>
    {% endif %}
    {% if object.bio %}
    <div class="user-bio">&ldquo;{{ object.bio }}&rdquo;</div>
    {% endif %}
    {% if user == object %}
      {% if not object.has_contact_details or not object.bio %}
        <div class="user-bio placeholder">{% trans 'Show others who you are, tell about yourself<br/>and make your public profile look gorgeous!' %}</div>
      {% endif %}
      <div class="js-user-profile-edit"></div>
    {% endif %}
  </div>
  {% endif %}
{% else %}
  <div id="user-details" class="meta-user">
    <div class="user-bio placeholder">
    {% if object.is_anonymous %}
      {% trans 'Some translations are provided by anonymous volunteers. These are registered under this special meta-account.' %}
    {% elif object.is_system %}
      {% trans 'Some translations are imported from external files. These are registered under this special meta-account.' %}
    {% else %}
      {{ object.bio }}
    {% endif%}
    </div>
  </div>
{% endif %}

</div>
{% endblock %}

{% block scripts_extra %}
{{ block.super }}
{% if user == object %}
{% assets 'js_user_app' %}
<script type="text/javascript" src="{{ ASSET_URL }}"></script>
{% endassets %}
<script type="text/javascript">
$(function() {
  PTL.user.init({
    userData: {{ user.field_values|to_js }},
    appRoot: '{{ user.get_absolute_url }}',
  });
});
</script>
{% endif %}
{% endblock %}
