{% extends "wafer/base.html" %}
{% load i18n %}
{% load debconf %}
{% block title %}{{ object.userprofile.display_name }} - {{ WAFER_CONFERENCE_NAME }}{% endblock %}
{% block main_class %}profile{% endblock %}
{% block content %}
{% with profile=object.userprofile %}
<section>
  <div class="row">
    <div class="col-md-2 text-center" id="profile-avatar">
      {% with profile.avatar_url as avatar_url %}
        {% if avatar_url != None %}
          <img src="{{ profile.avatar_url }}">
        {% endif %}
      {% endwith %}
      {% if can_edit %}
        <a class="btn btn-secondary btn-sm" href="#" rel="popover" data-toggle="popover"
           data-title="{% trans 'Changing your mugshot' %}" data-html="true"
           data-placement="bottom">{% trans 'Edit Mugshot' %}</a>
        <div class="popover-contents">
          {% blocktrans %}
            Pictures provided by <a href="https://www.libravatar.org/">libravatar</a>
            (which falls back to <a href="https://secure.gravatar.com/">Gravatar</a>).<br>
            Change your picture there.
          {% endblocktrans %}
        </div>
      {% endif %}
    </div>
    <div class="col-md">
      {% spaceless %}
        <h1>
          {% if profile.homepage %}
            <a href="{{ profile.homepage_url }}">
          {% endif %}
          {{ profile.display_name }}
          {% if profile.homepage %}
            </a>
          {% endif %}
        </h1>
        {% if profile.twitter_handle %}
          <p>
            <a href="https://twitter.com/{{ profile.twitter_handle }}" class="twitter-follow-button" data-show-count="false">
              {% blocktrans with handle=profile.twitter_handle %}Follow @{{ handle }}{% endblocktrans %}
            </a>
          </p>
        {% endif %}
        {% if profile.github_username %}
          <p>
            <a href="https://github.com/{{ profile.github_username }}">
              {% blocktrans with username=profile.github_username %}GitHub: {{ username }}{% endblocktrans %}
            </a>
          </p>
        {% endif %}
      {% endspaceless %}
    </div>
    {% if can_edit %}
      <div class="col-md-3">
        <div class="list-group">
          <a href="{% url 'wafer_user_edit' object.username %}" class="list-group-item list-group-item-action">{% trans 'Edit Account' %}</a>
          <a href="{% url 'wafer_user_edit_profile' object.username %}" class="list-group-item list-group-item-action">{% trans 'Edit Profile' %}</a>
          {% if WAFER_REGISTRATION_OPEN %}
            {% if profile.is_registered %}
              <a href="{% url 'register' %}" class="list-group-item list-group-item-action">{% trans 'Update Registration' %}</a>
              {% if USING_BADGES_APP %}
                <a href="{% url 'badges.own' %}" class="list-group-item list-group-item-action">{% trans 'Preview my badge' %}</a>
              {% endif %}
              <a href="{% url 'unregister' %}" class="list-group-item list-group-item-action">{% trans 'Unregister' %}</a>
            {% else %}
              <a href="{% url 'register' %}" class="list-group-item list-group-item-action">{% trans 'Register' %}</a>
            {% endif %}
          {% endif %}
          {% if WAFER_TALKS_OPEN %}
            <a href="{% url 'wafer_talk_submit' %}" class="list-group-item list-group-item-action">{% trans 'Submit Talk Proposal' %}</a>
          {% endif %}
        </div>
      </div>
    {% endif %}
  </div>
  {% if profile.bio %}
    <div class="bio">
      {{ profile.bio|linebreaks }}
    </div>
  {% endif %}
  {% if can_edit %}
    {% with attendee=object.attendee %}
      {% if attendee.billable and not attendee.paid %}
        <div class="alert alert-danger">
          Not paid.
          {% if attendee.new_invoices.exists %}
            <a href="#my-invoices">My Invoices</a>
          {% else %}
            <a class="btn btn-primary" href="{% url 'register' %}">Finish Registration</a>
          {% endif %}
        </div>
      {% endif %}
    {% endwith %}
    {% if profile.pending_talks.exists or profile.accepted_talks.exists or profile.provisional_talks.exists %}
      {% if profile.is_registered %}
        <div class="alert alert-success">
          {% blocktrans %}
            Registered
          {% endblocktrans %}
        </div>
      {% elif WAFER_REGISTRATION_OPEN %}
        <div class="alert alert-danger">
          {% blocktrans %}
            <strong>WARNING:</strong>
            Talk proposal submitted, but speaker hasn't registered to attend.
          {% endblocktrans %}
          {% trans "Register now!" %}
        </div>
      {% endif %}
    {% endif %}
  {% endif %}
</section>
{# Accepted talks are globally visible #}
{% if profile.accepted_talks.exists %}
  <section>
    <h2>{% trans 'Accepted Talks:' %}</h2>
    {% for talk in profile.accepted_talks %}
      <div class="card">
        <div class="card-body">
          <h3 class="card-title">
            <a href="{{ talk.get_absolute_url }}">
              {{ talk.title }}
            </a>
          </h3>
          <p>{{ talk.abstract.rendered|safe }}</p>
        </div>
      </div>
    {% endfor %}
  </section>
{% endif %}
{% if profile.cancelled_talks.exists %}
  <section>
    <h2>{% trans 'Cancelled Talks:' %}</h2>
    {% for talk in profile.cancelled_talks %}
      <div class="card">
        <div class="card-body">
          <h3 class="card-title">
            <a href="{{ talk.get_absolute_url }}">
              {{ talk.title }}
            </a>
          </h3>
          <p>{{ talk.abstract.rendered|safe }}</p>
        </div>
      </div>
    {% endfor %}
  </section>
{% endif %}
{# Submitted talk proposals are only visible to the owner #}
{% if can_edit %}
  {% if profile.provisional_talks.exists %}
    <section>
      <h2>{% trans 'Provisionally Accepted Talks:' %}</h2>
      {% for talk in profile.provisional_talks %}
        <div class="card">
          <div class="card-body">
            <h3 class="card-title">
              <a href="{{ talk.get_absolute_url }}">
                {{ talk.title }}
              </a>
            </h3>
            <p>{{ talk.abstract.rendered|safe }}</p>
          </div>
        </div>
      {% endfor %}
    </section>
  {% endif %}
  {% if profile.pending_talks.exists %}
    <section>
      <h2>{% trans 'Submitted or Under Consideration Talks:' %}</h2>
      {% for talk in profile.pending_talks %}
        <div class="card">
          <div class="card-body">
            {% comment %}
            Because this is one of the author's pending talks, we don't need to
            check for edit permission's on the talk explicitly. This doesn't show
            the edit button for people with 'change-talk' permissions, but we
            accept that tradeoff for simplicity here.
            {% endcomment %}
            <a href="{% url 'wafer_talk_edit' talk.pk %}"
               class="float-right btn btn-secondary btn-lg">
              {% trans 'Edit' %}
            </a>
            <h3 class="card-title">
              <a href="{{ talk.get_absolute_url }}">
                {{ talk.title }}
              </a>
            </h3>
            <p>{{ talk.abstract.rendered|safe }}</p>
          </div>
        </div>
      {% endfor %}
    </section>
  {% endif %}
{% endif %}
{% if can_edit and object.bursary and object.bursary.request_any %}
  <section>
    {% with bursary=object.bursary %}
      <h2>{% trans 'My bursary requests:' %}</h2>
      <div class="card-group">
        {% if DEBCONF_ONLINE %}
          <div class="card">
            <div class="card-header">
              <h3>{% trans 'Expenses' %}</h3>
            </div>
            <div class="card-body">
              {% if bursary.request_expenses %}
                <p>{{ bursary.get_expenses_status_display }}</p>
              {% else %}
                <div>{% trans 'Not Requested' %}</div>
              {% endif %}
            </div>
          </div>
        {% else %}
          <div class="card">
            <div class="card-header">
              <h3>{% trans 'Food' %}</h3>
            </div>
            <div class="card-body">
              {% if bursary.request_food %}
                <p>{{ bursary.get_food_status_display }}</p>
                {% if bursary.can_update and bursary.food_status == 'pending' %}
                  <p class="alert alert-success">
                    {% blocktrans with date=bursary.food_accept_before|date %}
                      Your bursary has been granted.
                      You need to confirm it before {{ date }}.
                    {% endblocktrans %}
                  </p>
                {% endif %}
              {% else %}
                <div>{% trans 'Not Requested' %}</div>
              {% endif %}
            </div>
          </div>
          <div class="card">
            <div class="card-header">
              <h3>{% trans 'Accommodation' %}</h3>
            </div>
            <div class="card-body">
              {% if bursary.request_accommodation %}
                <p>{{ bursary.get_accommodation_status_display }}</p>
                {% if bursary.can_update and bursary.accommodation_status == 'pending' %}
                  <p class="alert alert-success">
                    {% blocktrans with date=bursary.accommodation_accept_before|date %}
                      Your bursary has been granted.
                      You need to confirm it before {{ date }}.
                    {% endblocktrans %}
                  </p>
                {% endif %}
              {% else %}
                <div>{% trans 'Not Requested' %}</div>
              {% endif %}
            </div>
          </div>
          <div class="card">
            <div class="card-header">
              <h3>{% trans 'Travel' %}</h3>
            </div>
            <div class="card-body">
              {% if bursary.request_travel %}
                <p>{{ bursary.get_travel_status_display }}</p>
                <table>
                  <tr>
                    <th>{% trans 'Requested' %}</th>
                    <td>{{ bursary.travel_bursary }} {% debconf_setting "BURSARY_CURRENCY" %}</td>
                  </tr>
                  <tr>
                    <th>{% trans 'Reimbursed' %}</th>
                    <td>{{ bursary.reimbursed_amount }} {% debconf_setting "BURSARY_CURRENCY" %}</td>
                  </tr>
                </table>
                {% if bursary.can_update and bursary.travel_status == 'pending' %}
                  <p class="alert alert-success">
                    {% blocktrans with date=bursary.travel_accept_before|date %}
                      Your bursary has been granted.
                      You need to confirm it before {{ date }}.
                    {% endblocktrans %}
                  </p>
                {% endif %}
              {% else %}
                <div>{% trans 'Not Requested' %}</div>
              {% endif %}
            </div>
          </div>
        {% endif %}
      </div>

      {% if bursary.can_update %}
        {% if bursary.must_accept %}
          <p><a href="{% url 'bursary_update' %}" class="btn-lg btn btn-primary btn-success">{% trans 'Accept my bursary' %}</a></p>
        {% else %}
          <p><a href="{% url 'bursary_update' %}" class="btn-lg btn btn-primary">{% trans 'Update my bursary request' %}</a></p>
        {% endif %}
      {% endif %}
    {% endwith %}
  </section>
{% endif %}
{% if can_edit and object.invoices.exists %}
  <section>
    {% with invoices=object.invoices.all %}
      <h2 id="my-invoices">{% trans 'My invoices:' %}</h2>
      <div class="card-group">
        {% for invoice in invoices %}
          <div class="card">
            <div class="card-header">
              <h3 class="card-title">#{{ invoice.reference_number }}</h3>
            </div>
            <div class="card-body">
              <div>
                {% debconf_setting "BILLING_CURRENCY" as billing_currency %}
                {% debconf_setting "LOCAL_CURRENCY" as local_currency %}
                Total: {{ invoice.total }} {{ billing_currency }}
                {% if local_currency != billing_currency %}
                  or {{ invoice.total_local }} {{ local_currency }}
                {% endif %}
              </div>
              <div>Status: {{ invoice.get_status_display }}</div>
              <div><a class='btn btn-outline-primary' href="{% url "invoices:display" reference_number=invoice.reference_number %}">Display</a></div>
            </div>
          </div>
        {% endfor %}
      </div>
    {% endwith %}
  </section>
{% endif %}
{% with accomm=object.attendee.accomm %}
  {% if can_edit and accomm %}
    <section>
      <h2 id="my-accomm">{% trans 'My accommodation' %}</h2>
      <div class="card-group">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">
              Nights
            </h3>
          </div>
          <div class="card-body">
            <ul>
              {% for night in accomm.nights.all %}
                <li>Night of {{ night }}</li>
              {% endfor %}
            </ul>
            <div class="small">The night of is the night after the date specified.</div>
          </div>
        </div>

        <div class="card">
          <div class="card-header">
            <h3 class="card-title">
              Room {{ accomm.room }}
            </h3>
          </div>
          <div class="card-body">
            {% if accomm.room %}
              <div>Roommates:</div>
              <ul>
                {% for mate in accomm.get_roommates %}
                  <li>{{ mate.user.userprofile.display_name }}</li>
                {% endfor %}
              </ul>
            {% else %}
              Your room hasn't been assigned yet.
              Check back, a few days before {{ WAFER_CONFERENCE_NAME }}.
            {% endif %}
          </div>
        </div>
      </div>
    </section>
  {% endif %}
{% endwith %}
{% endwith %}
{% endblock %}
{% block extra_foot %}
  <script type="text/javascript">
    {% if profile.twitter_handle %}
    // Twitter boilerplate
    !function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (! d.getElementById(id)) {
        js = d.createElement(s);
        js.id = id;
        js.src = "//platform.twitter.com/widgets.js";
        fjs.parentNode.insertBefore(js, fjs);
      }
    }(document, "script", "twitter-wjs");
    {% endif %}

    $("#profile-avatar [rel=popover]").attr("data-content", $("#profile-avatar .popover-contents").html());
    $("a[rel=popover]").popover();
  </script>
{% endblock %}
