{% extends "pretixcontrol/organizers/base.html" %}
{% load i18n %}
{% load urlreplace %}
{% load bootstrap3 %}
{% load money %}
{% block title %}{% trans "Customers" %}{% endblock %}
{% block inner %}
    <h1>
        {% trans "Customers" %}
    </h1>
    {% if customers|length == 0 and not filter_form.filtered %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    No customer accounts have been created yet.
                {% endblocktrans %}
            </p>
            <a href="{% url "control:organizer.customer.create" organizer=request.organizer.slug %}"
               class="btn btn-primary btn-lg"><i class="fa fa-plus"></i> {% trans "Create a new customer" %}</a>
        </div>
    {% else %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Filter" %}</h3>
            </div>
            <form class="panel-body filter-form" action="" method="get">
                <div class="row">
                    <div class="col-md-6 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.query layout='inline' %}
                    </div>
                    <div class="col-md-3 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.status layout='inline' %}
                    </div>
                    <div class="col-md-3 col-sm-6 col-xs-12">
                        {% bootstrap_field filter_form.memberships layout='inline' %}
                    </div>
                </div>
                <div class="text-right">
                    <button class="btn btn-primary btn-lg" type="submit">
                        <span class="fa fa-filter"></span>
                        {% trans "Filter" %}
                    </button>
                </div>
            </form>
        </div>
        <p>
            <a href="{% url "control:organizer.customer.create" organizer=request.organizer.slug %}"
               class="btn btn-default"><i class="fa fa-plus"></i> {% trans "Create a new customer" %}</a>
        </p>
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>{% trans "Customer ID" %}
                        <a href="?{% url_replace request 'ordering' '-identifier' %}"><i
                                class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'identifier' %}"><i class="fa fa-caret-up"></i></a>
                    </th>
                    <th>{% trans "Email" %}
                        <a href="?{% url_replace request 'ordering' '-email' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'email' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Name" %}
                        <a href="?{% url_replace request 'ordering' '-name' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'name' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "External identifier" %}
                        <a href="?{% url_replace request 'ordering' '-external_identifier' %}"><i class="fa fa-caret-down"></i></a>
                        <a href="?{% url_replace request 'ordering' 'external_identifier' %}"><i class="fa fa-caret-up"></i></a></th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                {% for c in customers %}
                    <tr>
                        <td>
                            <a href="{% url "control:organizer.customer" organizer=request.organizer.slug customer=c.identifier %}">
                                {% if not c.is_active %}<strike>{% endif %}
                                <strong>#{{ c.identifier }}</strong>
                                {% if not c.is_active %}</strike>{% endif %}
                            </a>
                        </td>
                        <td>
                            {% if not c.is_verified %}<strike>{% endif %}
                            {{ c.email|default_if_none:"" }}
                            {% if not c.is_verified %}</strike>{% endif %}
                        </td>
                        <td>{{ c.name }}</td>
                        <td>{% if c.external_identifier %}{{ c.external_identifier }}{% endif %}</td>
                        <td class="text-right">
                            <a href="{% url "control:organizer.customer" organizer=request.organizer.slug customer=c.identifier %}"
                                    class="btn btn-default btn-sm" data-toggle="tooltip" title="{% trans "Details" %}">
                                <i class="fa fa-eye"></i>
                            </a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
