{% extends "base.html" %}

{% block content %}

    <h1>{{ object.label }}</h1>

    <table class="table table-sm">
        <tr>
            <th>Role</th>
            <td>{{ object.role }}</td>
        </tr>
        <tr>
            <th>Organization</th>
            <td>{{ object.organization }}</td>
        </tr>
        <tr>
            <th>Division</th>
            <td>{{ object.division }}</td>
        </tr>
    </table>

    <h3>Contests ({{ object.contests.count }})</h3>

    {% for obj in object.contests.all %}
    <h5>{{ obj.contest.election }}</h5>
    <table class="table table-sm">
        <thead>
            <tr>
                <th>Name</th>
                <th>Party</th>
                <th>Incumbent</th>
                <th>Status</th>
                <th>Sources</th>
            </tr>
        </thead>
        <tbody>
        {% for candidate in obj.candidacies.all %}
        <tr>
            <td>
                <a href="{% url 'person_detail' candidate.person.id %}">
                    {{ candidate.person }}
                </a>
            </td>
            <td>{{ candidate.party }}</td>
            <td>{{ candidate.is_incumbent }}</td>
            <td>{{ candidate.registration_status }}</td>
            <td>
                {% for obj in obj.sources.all %}
                    <a href="{{ obj.url }}">{{ forloop.counter }}{% if not forloop.last %},{% endif %}</a>
                {% endfor %}
            </td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
    {% endfor %}


{% endblock %}
