{% from '_functions.html' import avatar_thumbnail, badge_thumbnail, show_badges_by_tags, pluralize with context %}

{% extends '_base.html' %}


{% block head %}
<link rel="alternate" type="application/rss+xml" title="Badges Feed for {{ user.nickname }}" href="{{ url_for("tahrir.user_rss", user_id=user.nickname, _external=True) }}" />
<link rel="alternate" type="application/json" title="User {{ user.nickname }} as JSON" href="{{ url_for("tahrir.user_json", user_id=user.nickname, _external=True) }}" />
{% endblock %}


{% block body %}
<div class="page"
     prefix="doap: http://usefulinc.com/ns/doap#"
     prefix="schema: http://schema.org/Person"
     resource=""
     typeof="foaf:Person schema:Person">
  <!-- COLUMN 1 (Left)-->
  <div class="grid-30">
    <div class="shadow">
      <h1 class="section-header">User Info</h1>
      <div class="padded-content clearfix">
        {{ avatar_thumbnail(user, 'responsive', 100, False) }}
        <div class="grid-100">
          <p class="name" property="foaf:nick">{{user.nickname}}</p>
        </div>
        <span property="foaf:account" content="{{user.nickname}}@{{config['TAHRIR_EMAIL_DOMAIN']}}" />

        <div class="grid-100">
          <p>Go to <a href="{{config["TAHRIR_FAS_URL"]}}/user/{{user.nickname}}/">{{user.nickname}}'s Fedora Account</a>
        </div>

        <div class="metadata grid-60">
          <p>Arrived on {{user.created_on.strftime('%Y-%m-%d')}}.</p>

          {% if user.email == g.oidc_user.email %}
            <span property="foaf:mbox_sha1sum" content="{{user.email_sha1}}" />
            <p property="schema:email">{{user.email}}</p>
          {% endif %}

          {% if rank != 0 %}
            <p>
              Ranked {{rank}} out of {{user_count}} ranked users (top {{"{0:.2f}".format(percentile)}}%).</p>
          {% else%}
            <p>Not ranked yet.</p>
          {% endif %}

          <p>
            View user as:
            <a href="{{ url_for('tahrir.user_json', user_id=user.nickname or user.id) }}">JSON</a>,
            <a href="{{ url_for('tahrir.user_rss', user_id=user.nickname or user.id) }}">RSS</a>
          </p>
        </div>
        {% if g.oidc_user.email == user.email %}
          <div class="social grid-30 pull-5">
            <div id="social-activate">
              <button id="share" class="pretty-button" onClick="javascript:activate_social_links();">
                &laquo;Share&raquo;
              </button>
            </div>
            {% if twitter %}
              <div id="twitter-container">
                <a
                   href="https://twitter.com/share"
                   class="twitter-share-button"
                   data-text="{{twitter_user_text}}"
                   data-count="none"
                   data-hashtags="{{twitter_user_hash}}"
                   data-dnt="true">
                  Tweet
                </a>
              </div>
            {% endif %}
          </div> <!-- End social grid -->
        {% endif %}
        <div class="clear spacer"></div>
        {% if g.oidc_user.email == user.email %}
          {% if invitations|length > 0 %}
            <h3>Active Invitations</h3>
            <ul class='pretty-list'>
            {% for i in invitations %}
            <li>
              {{i.badge.name}}, expires {{ i.expires_on | relative_time }},
              <a href="{{ url_for('tahrir.invitation_claim', claim_id=i.id, _external=True) }}">[claim link]</a>,
              <a href="{{ url_for('tahrir.invitation_qrcode', claim_id=i.id) }}">[QR code]</a>.
            </li>
            {% endfor %}
            </ul>
          {% endif %}
          {% if g.oidc_user.awarded_assertions %}
            <button class="pretty-button" onClick="javascript:claim_badges();">
              Export Badges
            </button>
          {% endif %}
          <form method="GET" action="https://www.libravatar.org/openid/login/">
            <input type="hidden" name="openid_identifier" value="{{user.nickname}}.id.fedoraproject.org"/>
            <input
               class="pretty-submit"
               style="height: 50px; width: 100%;"
               name="change-avatar"
               type="submit"
               value="Change Avatar" />
          </form>
          <form method="GET" action="https://notifications.fedoraproject.org/">
            <input
               class="pretty-submit"
               style="height: 50px; width: 100%;"
               type="submit"
               value="Manage Notifications" />
          </form>
          <form method="GET" action="{{ config["TAHRIR_FAS_URL"] }}/user/{{user.nickname}}/settings/profile/">
            <input
               class="pretty-submit"
               style="height: 50px; width: 100%;"
               type="submit"
               value="Edit Profile" />
          </form>
          {% if user.opt_out %}
            <form method="POST">
              <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
              <input
                 class="pretty-submit"
                 style="height: 50px; width: 100%;"
                 name="reactivate-account"
                 type="submit"
                 value="Reactivate Account" />
            </form>
          {% else%}
            <form method="POST">
              <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
              <input
                 class="pretty-submit"
                 style="height: 50px;"
                 name="deactivate-account"
                 type="submit"
                 value="Deactivate Account" />
            </form>
          {% endif %}
        {% elif g.oidc_user.logged_in %}
            <form method="GET" action="{{ url_for('tahrir.diff', id_a=g.oidc_user.person.nickname or g.oidc_user.person.id, id_b=user.nickname or user.id) }}">
              <input
                 class="pretty-submit"
                 style="height: 50px; width: 100%;"
                 type="submit"
                 value="Show Diff" />
            </form>
        {% endif %}
      </div> <!-- End padded content. -->
    </div> <!-- End shadow. -->

    {% if user.assertions %}
    <div class="shadow mobile-hidden">
      <h1 class="section-header">History</h1>
      <div class="padded-content clearfix">
        {% for assertion in (user.assertions|sort(attribute="issued_on", reverse=True))[:history_limit] %}
          <div class="grid-container">
            {{ badge_thumbnail(assertion.badge, 64, 33) }}
            <div class="grid-66 text-64"><p>received on {{assertion.issued_on.strftime('%Y-%m-%d')}}
              {% if assertion.issued_for %}
              for <a href="{{assertion.issued_for}}">this activity</a>
              {% endif %}
              </p></div>
          </div>
        {% endfor %}
        {% if history_limit < user.assertions|length %}
        <div class="grid-container">
          <div class="grid-100 text-64"><p>
            This is only the last {{history_limit}} entries.
            <a href="{{ url_for('tahrir.user', user_id=user.nickname or user.id, history_limit=user.assertions|length) }}">
              Click here to see all of them</a>.
          </p></div>
        </div>
        {% endif %}
      </div> <!-- End padded content. -->
    </div> <!-- End shadow. -->
    {% endif %}

  </div> <!-- End column 1. -->

  <!-- COLUMN 2 (Right)-->
  <div class="grid-70">
    <div class="shadow">
      <h1 class="section-header">Badges Earned</h1>
      <div class="padded-content">
        <div style="text-align: center; font-size: 1.2em; padding: 20px;">
          {% if user_badges|length < 1 %}
            {% if user.email == g.oidc_user.email %}
              <p>You have not earned any badges yet!</p>
            {% else%}
              <p>{{user.nickname}} has not earned any badges yet!</p>
            {% endif %}
          {% else%}
            {% if user.email == g.oidc_user.email %}
              <p>You have earned
            {% else%}
              <p>{{user.nickname}} has earned
            {% endif %}
            <strong>{{user_badges|length}}</strong>
            {{ pluralize("badge", user_badges|length) }}
            (<strong>{{"{0:.1f}".format(percent_earned)}}%</strong> of total).
          {% endif %}
        </div>
        {{ show_badges_by_tags(badges_by_tag, uncategorized_badges) }}
      </div>
    </div> <!-- End padded content. -->
  </div> <!-- End shadow. -->
</div> <!-- End column 2. -->
<div class="clear spacer"></div>
</div>
{% endblock %}
