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

{% block title %}
    {% trans "Partners" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{% url 'dashboard:partner-list' %}">{% trans "Partners" %}</a></li>
            <li class="breadcrumb-item active" aria-current="page">{{ partner.name }}</li>
        </ol>
    </nav>
{% endblock %}

{% block header %}
    <div class="page-header">
        <div class="btn-group float-right">
            <a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
                <i class="fas fa-plus-circle"></i>
                {% trans 'Link a user' %}
            </a>
            <ul class="dropdown-menu dropdown-menu-right">
                <li><a href="{% url 'dashboard:partner-user-create' partner_pk=partner.pk %}" >{% trans "Link a new user" %}</a></li>
                <li><a href="{% url 'dashboard:partner-user-select' partner_pk=partner.pk %}" >{% trans "Link an existing user" %}</a></li>
            </ul>
        </div>
        <h1>{% trans "Manage users" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    {% 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_pkuser.id %}" method="post">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-danger" data-loading-text="{% trans 'Unlinking...' %}">{% trans 'Unlink user' %}</button>
                            </form>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% else %}
        <p>{% trans "No users linked." %}</p>
    {% endif %}
    {% include "oscar/dashboard/partials/pagination.html" %}

    <h1>{% trans "Update details" %}</h1>
    {% include 'oscar/dashboard/partials/form.html' %}
{% endblock dashboard_content %}
