{% extends "site_base.html" %}

{% load i18n %}
{% load proposal_tags %}
{% load review_tags %}
{% load teams_tags %}
{% load registrasion_tags %}
{% load account_tags %}

{% block head_title %}Dashboard{% endblock %}

{% block body_class %}auth{% endblock %}

{% block body %}

    <div class="panel panel-default">
      <div class="panel-heading">
          <h3 class="panel-title">
              <i class="fa fa-user-o"></i>
              Account
              <span class="pull-right">
                <i class="fa fa-user"></i> {% user_display request.user %}
              </span>
          </h3>
      </div>
      <div class="panel-body">
        <li>
            <a href="{% url 'account_password' %}">{% trans "Change password" %}</a>
        </li>
      </div>
    </div>

    {% include "registrasion/dashboard_widget.html" %}

    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="pull-right">
                {% if not user.speaker_profile %}
                    <a href="{% url "speaker_create" %}" class="btn btn-xs btn-default">
                        <i class="fa fa-plus-sign"></i> Create a speaker profile
                    </a>
                {% else %}
                    <a href="{% url "speaker_edit" %}" class="btn btn-xs btn-default">
                        <i class="fa fa-pencil"></i> Edit your speaker profile
                    </a>
                    <a href="/proposals/submit/talk" class="btn btn-xs btn-default">
                        <i class="fa fa-plus-sign"></i> Submit a new proposal
                    </a>
                {% endif %}
            </div>
            <h3 class="panel-title">
                <i class="fa fa-bullhorn"></i>
                {% trans "Speaking" %}
            </h3>
        </div>

        <div class="panel-body">
            {% if not user.speaker_profile %}
                <p>To submit a proposal, you must first <a href="{% url "speaker_create" %}">create a speaker profile</a>.</p>
            {% else %}
                <h4>Your Proposals</h4>
                {% if not user.speaker_profile.proposals.exists %}
                    <p>No proposals submitted yet.</p>
                {% endif %}
            {% endif %}
        </div>
        {% if user.speaker_profile.proposals.exists %}
            <table class="table">
                <tr>
                    <th>Title</th>
                    <th>Session type</th>
                    <th>Status</th>
                    <th>Actions</th>
                </tr>
                {% for proposal in user.speaker_profile.proposals.all %}
                    {% include "symposion/proposals/_proposal_row.html" %}
                {% endfor %}
            </table>
        {% endif %}

        {% if user.speaker_profile %}
            {% associated_proposals as associated_proposals %}
            {% if associated_proposals %}
                <div class="panel-body">
                    <h4>Proposals you have joined as an additional speaker</h4>
                </div>
                <table class="table">
                    <tr>
                        <th>Title</th>
                        <th>Session type</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                    {% for proposal in associated_proposals %}
                        {% include "symposion/proposals/_proposal_row.html" %}
                    {% endfor %}
                </table>
            {% endif %}

            {% pending_proposals as pending_proposals %}
            {% if pending_proposals %}
                <div class="panel-body"><h4>Proposals you have been invited to join</h4></div>
                <table class="table">
                    <tr>
                        <th>Title</th>
                        <th>Session type</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                    {% for proposal in pending_proposals %}
                        {% include "symposion/proposals/_pending_proposal_row.html" %}
                    {% endfor %}
                </table>
            {% endif %}
        {% endif %}
    </div>

{% comment %}
    {% include "registrasion/dashboard_widget.html" %}
{% endcomment %}

    <div class="panel panel-default">
        <div class="panel-heading">
            <div class="pull-right header-actions">
                {% if not user.sponsorships.exists %}
                    <a href="{% url "sponsor_apply" %}" class="btn btn-xs btn-default">
                        <i class="fa fa-plus-sign"></i>
                        Apply to be a sponsor
                    </a>
                {% endif %}
            </div>
            <h3 class="panel-title">
                <i class="fa fa-briefcase"></i>
                {% trans "Sponsorship" %}
            </h3>
        </div>

        <div class="panel-body">
            {% if not user.sponsorships.exists %}
                <p>If you or your organization would be interested in sponsorship opportunities, <a href="{% url "sponsor_apply" %}">use our online form to apply to be a sponsor</a>.
            {% else %}
                <h4>Your Sponsorship</h4>
                <ul class="list-group">
                    {% for sponsorship in user.sponsorships.all %}
                        <li class="list-group-item">
                            <a href="{% url "sponsor_detail" sponsorship.pk %}"><b>{{ sponsorship.name }}</b></a>
                            ({{ sponsorship.level }})
                            {% if not sponsorship.active %}
                                <span class="label label-warning">awaiting approval</span>
                            {% endif %}
                        </li>
                    {% endfor %}
                </ul>
            {% endif %}
            {% if user.is_staff %}
                <p>
                    As staff, you can directly <a href="{% url "sponsor_add" %}">add a sponsor</a> if the organization isn't
                    applying themselves.
                </p>
            {% endif %}
        </div>
    </div>

    {% if review_sections %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-briefcase"></i>
                    {% trans "Reviews" %}
                </h3>
            </div>
            <div class="panel-body">
                <h4>Reviews by Section</h4>
                <ul>
                    {% for section in review_sections %}
                        <h5>{{ section }}</h5>
                        <li><a href="{% url "review_section" section.section.slug %}">All</a></li>
                        <li><a href="{% url "user_reviewed" section.section.slug %}">Reviewed by you</a></li>
                        <li><a href="{% url "user_not_reviewed" section.section.slug %}">Not Reviewed by you</a></li>
                    {% endfor %}
                </ul>

                {% comment %}
                <h4>My Assignments</h4>
                <table class="table">
                    <thead>
                        <td>Proposal Title</td>
                        <td>Score</td>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Title Three</td>
                            <td>-1</td>
                        </tr>
                        <tr>
                            <td>Title Four</td>
                            <td>+2</td>
                        </tr>
                    </tbody>
                </table>
                {% endcomment %}

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

    {% available_teams as available_teams %}
    {% if user.memberships.exists or available_teams %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-group"></i>
                    {% trans "Teams" %}
                </h3>
            </div>

            {% if user.memberships.exists %}
                <div class="panel-body">
                    <h4>Your Teams</h4>
                </div>
                <table class="table table-striped">
                    {% for membership in user.memberships.all %}
                        <tr>
                            <td>
                                <a href="{% url "team_detail" membership.team.slug %}">{{ membership.team.name }}</a>
                                {% if membership.team.description %}<br>{{ membership.team.description }}{% endif %}
                            </td>
                            <td>
                                <span class="label{% if membership.state == 'invited' %} label-info{% endif %}">{{ membership.get_state_display }}</span>
                            </td>
                            <td>
                                {% if membership.state == "manager" or user.is_staff %}
                                    {% if membership.team.applicants %}{{ membership.team.applicants.count }} applicant{{ membership.team.applicants.count|pluralize }}{% endif %}
                                {% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            {% endif %}
            {% if available_teams %}
                <div class="panel-body">
                    <h4>Available Teams</h4>
                </div>
                <table class="table table-striped">
                    {% for team in available_teams %}
                        <tr>
                            <td>
                                <a href="{% url team_detail team.slug %}">{{ team }}</a>
                                {% if team.description %}<br>{{ team.description }}{% endif %}
                            </td>
                            <td>
                                <span class="label label-default">{{ team.get_access_display }}</span>
                            </td>
                        </tr>
                    {% endfor %}
                </table>
            {% endif %}
        </div>
    {% endif %}
{% endblock %}
