{% extends "base.html" %}

{% set display_name = profile.name | default(profile.user.username, true) %}
{% set username  = profile.user.username %}

{% block pageid %}{% endblock %}

{% block bodyclass %}profile{% endblock %}

{% block title %}{{ page_title(profile.user) }}{% endblock %}

{% block site_css %}
    {{ super() }}
    {{ css('demostudio') }}
{% endblock %}

{% block site_js %}
    {{ super() }}
    {{ js('demostudio') }}
{% endblock %}

{% block content %}
<section id="content">
<div class="wrap">

  <section id="content-main" class="full">

    <section id="profile-head" class="vcard">
      <div class="main">
        <h1 class="page-title"><span class="nickname">{{ profile.user.username }}</span> {% if profile.fullname %}<b>(<span class="fn">{{ profile.fullname }}</span>)</b>{% endif %}</h1>
  
      {% if profile.title or profile.organization or profile.location or profile.irc_nickname %}
      <ul class="info">
        {% if profile.title %}<li class="title">{{ profile.title }}</li>{% endif %}
        {% if profile.organization %}<li class="org">{{ profile.organization }}</li>{% endif %}
        {% if profile.location %}<li class="loc">{{ profile.location }}</li>{% endif %}
	{% if profile.irc_nickname %}<li class="irc">IRC: {{ profile.irc_nickname }}</li>{% endif %}
      </ul>
      {% endif %}
  
      <div class="bio">
        <p>{{ profile.bio | nl2br }}</p>
      </div>
        
        {% set tag_ns = 'profile:interest:' %}     
        {% set tags = profile.tags.all_ns(tag_ns) %}
        {% if tags | length %}
        <div class="tags">
          <h2>{{_("Interests")}}</h2>
          <ul class="int-taglist taglist">
            {% for tag in tags%}
                <li><span rel="tag">{{ tag.name.replace(tag_ns,'') }}</span></li>
            {% endfor %}
          </ul>
        </div>
        {% endif %}

        {% set tag_ns = 'profile:expertise:' %}
        {% set tags = profile.tags.all_ns(tag_ns) %}
        {% if tags | length %}
        <div class="tags">
          <h2>{{_("Areas of Expertise")}}</h2>
          <ul class="exp-taglist taglist">
            {% for tag in tags%}
                <li><span rel="tag">{{ tag.name.replace(tag_ns,'') }}</span></li>
            {% endfor %}
          </ul>
        </div>
        {% endif %}

      </div>
      
      <div class="extra">
        <figure class="avatar">
          <img src="{{ profile.gravatar }}" alt="" width="120" height="120" class="photo">
        </figure>
        
        <ul class="links">
        {% for site in profile.website_choices %}
            {% set site_name = site[0] %}
            {% set site_meta = site[1] %}
            {% set href = profile.websites[site_name] %}
            {% if href %}
                <li class="{{site_name}}"><a href="{{href}}" rel="me external" class="url">{{site_meta['label']}}</a></li>
            {% endif %}
          {% endfor %}
          <li class="docs"><a href="/User:{{profile.user.username}}" rel="me">{{_("Docs user page")}}</a></li>
        </ul>
      </div>

      <!-- Only shown for the user and admins -->
      {% if profile.allows_editing_by(request.user) %}
          <p class="edit"><a href="{{ url('devmo.views.profile_edit', username=profile.user.username) }}" class="button">{{_("Edit Profile")}}</a></p>
      {% endif %}
    </section>

    {% if demos_page.object_list | length > 0 %} 
        <section id="profile-demos" class="profile-section">
            {{ submission_listing(
                request, demos_page.object_list, demos_page.has_other_pages(),
                demos_paginator, demos_page,
                _("Subscribe to a feed of {display_name}'s demos") | f(display_name=display_name),
                url('demos_feed_profile', format='atom', username=username), cols_per_row=4,
                show_submit=True
            ) }}
        </section>
    {% elif profile.user == request.user %}
        <section id="profile-demos" class="profile-section">
          <header class="gallery-head">
            <h2 class="count">{{_("No Demos")}}</h2>
          </header>
          <p class="none">{% trans submit_url=url('demos.views.submit') %}You haven't submitted any web technology demos. Build something awesome and <a class="button positive" href="{{submit_url}}">Submit a Demo</a>{% endtrans %}</p>
        </section>
    {% endif %}

    {% if waffle.flag('kumawiki') %}
      {% if wiki_activity and wiki_activity | length > 0 %}
          <section id="docs-activity" class="profile-section kumawiki">
            <header>
              <h2>{{_("Recent Docs Activity")}}</h2>
            </header>
            <table class="activity">
              <thead>
                <th scope="col" class="page">{{_("Page")}}</th>
                <th scope="col" class="date">{{_("Date")}}</th>
                <th scope="col" class="summary">{{_("Comment")}}</th>
              </thead>
              <tbody>
                {% for rev in wiki_activity %}
                <tr>
                  <th scope="row">
                      <h3><a href="{{ rev.document.get_absolute_url() }}">{{ rev.document.title }}</a></h3>
                      <ul class="actions">
                          <li><a href="{{ url('wiki.views.edit_document', rev.document.full_path) }}" class="edit">{{_("Edit page")}}</a></li>
                          <li>{% if rev.get_previous() %}<a href="{{ url('wiki.views.compare_revisions', rev.document.full_path) }}?from={{ rev.get_previous().id }}&to={{ rev.id }}" class="diff">{{_("View complete diff")}}</a>{% endif %}</li>
                          <li><a href="{{ url('wiki.views.document_revisions', rev.document.full_path) }}" class="history">{{_("View page history")}}</a></li>
                      </ul>
                  </th>
                  <td>{{ rev.created.strftime('%B %d, %Y') }}<br>
                      {{ rev.created.strftime('%I:%M %p') }}</td>
                  {# TODO: auto-generate smart comment like "N words changed." #}
                  <td>{{ rev.comment }}</td>
                </tr>
                {% endfor %}
              </tbody>
              <tfoot>
                      {# TODO: create user revision activity feed
                <tr>
                  <td colspan="3">
                      <a href="/index.php?title=Special:Contributions&feed=rss&target={{profile.user.username | urlencode}}" rel="alternate" class="feed">{{_("Feed")}}</a>
                  </td>
                </tr>
                      #}
              </tfoot>
            </table>
          </section>
      {% else %}
        <section id="docs-activity" class="profile-section kumawiki">
          <header>
            <h2>{{_('Recent Docs Activity')}}</h2>
          </header>
          {% if profile.user == request.user %}
            {% trans docs_url=url('docs.views.docs') %}
            <p class="none">You haven't contributed to any MDN docs. <a href="{{docs_url}}">Pitch in!</a></p>
            {% endtrans %}
          {% endif %}
        </section>
      {% endif %}
    {% else %}
      {% if docs_feed_items and docs_feed_items | length > 0 %}
        <section id="docs-activity" class="profile-section mindtouch">
          <header>
            <h2>{{_("Recent Docs Activity")}}</h2>
            <p class="more"><a href="/Special:Contributions?target={{profile.user.username | urlencode}}">{{_("See more history")}}</a></p>
          </header>
          <table class="activity">
            <thead>
              <th scope="col" class="page">{{_("Page")}}</th>
              <th scope="col" class="date">{{_("Date")}}</th>
              <th scope="col" class="summary">{{_("Edit summary")}}</th>
            </thead>
            <tbody>
              {% for item in docs_feed_items %}
              <tr>
                <th scope="row">
                    <h3>
                        {% if item.view_url %}
                          <a href="{{ item.view_url }}">{{ item.rc_title }}</a>
                        {% else %}
                          <span>{{ item.rc_title }}</span>
                        {% endif %}
                    </h3>
                    <ul class="actions">
                        {% if item.edit_url %}
                            <li><a href="{{ item.edit_url }}" class="edit">{{_("Edit page")}}</a></li>
                        {% endif %}
                        {% if item.diff_url %}
                            <li><a href="{{ item.diff_url }}" class="diff">{{_("View complete diff")}}</a></li>
                        {% endif %}
                        {% if item.history_url %}
                            <li><a href="{{ item.history_url }}" class="history">{{_("View page history")}}</a></li>
                        {% endif %}
                    </ul>
                </th>
                <td>{{ item.rc_timestamp.strftime('%B %d, %Y') }}<br>
                    {{ item.rc_timestamp.strftime('%I:%M %p') }}</td>
                <td>{{ item.rc_comment }}</td>
              </tr>
              {% endfor %}
            </tbody>
            <tfoot>
              <tr>
                <td colspan="3">
                    <a href="/index.php?title=Special:Contributions&feed=rss&target={{profile.user.username | urlencode}}" rel="alternate" class="feed">{{_("Feed")}}</a>
                </td>
              </tr>
            </tfoot>
          </table>
        </section>
      {% else %}
        <section id="docs-activity" class="profile-section mindtouch">
          <header>
              <h2>{{_('Recent Docs Activity')}}</h2>
          </header>
        {% if profile.user == request.user %}
          {% trans docs_url=url('docs.views.docs') %}
              <p class="none">You haven't contributed to any MDN docs. <a href="{{docs_url}}">Pitch in!</a></p>
          {% endtrans %}
        {% endif %}
        </section>
      {% endif %}
    {% endif %}

  </section><!-- /#content-main -->
</div>
</section>
{% endblock %}
