{% extends 'dashboard/layout.html' %}
{% load sorting_tags %}
{% load i18n %}

{% block title %}
    {{ partner.name }} | {% trans "Partner management" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <ul class="breadcrumb">
        <li>
            <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
            <span class="divider">/</span>
        </li>
        <li>
            <a href="{% url 'dashboard:partner-list' %}">{% trans "Partner management" %}</a>
            <span class="divider">/</span>
        </li>
        <li class="active">{{ partner.name }}</li>
    </ul>
{% endblock %}

{% block headertext %}{{ partner.name }}{% endblock %}

{% block dashboard_content %}
    <div class="row-fluid">
        <div class="span6">
            <h2>{% trans "Details" %}</h2>
            <form class="form-stacked" method="post">
                {% csrf_token %}
                {% include 'partials/form_fields.html' with form=partner_form %}
                <div class="form-actions">
                    <button class="btn btn-large btn-primary" type="submit" name="submit" value="partner_form">{% trans "Save" %}</button>
                </div>
            </form>
        </div>
        <div class="span6">
            <h2>{% trans "Address" %}</h2>
            <form class="form-stacked" method="post">
                {% csrf_token %}
                {% include 'partials/form_fields.html' with form=address_form %}
                <div class="form-actions">
                    <button class="btn btn-large btn-primary" type="submit" name="submit" value="address_form">{% trans "Save" %}</button>
                </div>
            </form>
        </div>
    </div>

    <h2>{% trans "Users" %}</h2>
    {% if users %}
        <table class="table table-striped table-bordered">
            <thead>
                <tr>
                    <th>{% trans 'Email' %}</th>
                    <th>{% trans 'First name' %}</th>
                    <th>{% trans 'Last name' %}</th>
                    <th>&nbsp;</th>
                </tr>
            </thead>
            <tbody>
                {% for user in users %}
                    <tr>
                        <td><a href="{% url 'dashboard:partner-user-update' partner_pk=partner.pk user_pk=user.id %}">{{ user.email }}</a></td>
                        <td>{{ user.first_name|default:"-" }}</td>
                        <td>{{ user.last_name|default:"-" }}</td>
                        <td>
                            <form action="{% url 'dashboard:partner-user-unlink' partner_pk=partner.id user_pk=user.id %}" method="post">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-danger">{% trans 'Unlink user' %}</button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>{% trans "No users linked." %}</p>
    {% endif %}
    <div class="form-actions">
        <a class="btn btn-info" href="{% url 'dashboard:partner-user-create' partner_pk=partner.pk %}" >{% trans "Link a new user" %}</a>
        <a class="btn btn-info" href="{% url 'dashboard:partner-user-select' partner_pk=partner.pk %}" >{% trans "Link an existing user" %}</a>
    </div>
</div>
{% endblock dashboard_content %}
