{% extends 'dashboard/layout.html' %}
{% load url from future %}
{% load currency_filters %}
{% load i18n %}

{% block title %}
    {{ title }} | {{ 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=".">{% trans "Accounts" %}</a>
            <span class="divider">/</span>
        </li>
        <li class="active">{{ title }}</li>
    </ul>
{% endblock %}

{% block header %}
    <div class="page-header">
        <a id="create_new_account" href="{% url 'accounts-create' %}" class="btn btn-large btn-primary pull-right">{% trans "Create a new " %} {{ unit_name|lower }}</a></p>
    <h1>{{ title }}</h1>
</div>
{% endblock header %}

{% block dashboard_content %}

    <div class="well">
        <div class="sub-header">
            <h2>{% trans "Search" %}</h2>
        </div>

        <form method="get" action="." class="form-horizontal">
            {% include 'partials/form_fields.html' %}
            <button type="submit" class="btn btn-primary">{% trans "Search" %}</button>
            {% trans "or" %} <a href="{% url 'accounts-list' %}">{% trans "reset" %}</a>.
        </form>
    </div>

    <div class="sub-header">
        <h2>{{ queryset_description }}</h2>
    </div>

    {% if accounts.count %}
        <table class="table table-striped table-bordered">
            <tr>
                <th>{% trans "Name" %}</th>
                <th>{% trans "Code" %}</th>
                <th>{% trans "Status" %}</th>
                <th>{% trans "Start date" %}</th>
                <th>{% trans "End date" %}</th>
                <th>{% trans "Balance" %}</th>
                <th>{% trans "Num transactions" %}</th>
                <th>{% trans "Date created" %}</th>
                <th></th>
            </tr>
            {% for account in accounts %}
                {# When we're using bootstrap 2.1, we can use table row colors #}
                <tr {% if account.is_frozen %}style="color: #aaa"{% endif %}>
                    <td><a href="{% url 'accounts-detail' account.id %}">{{ account.name|default:"-" }}</a></td>
                    <td>{{ account.code|default:"-" }}</td>
                    <td>{{ account.status }}</td>
                    <td>{{ account.start_date|default:"-" }}</td>
                    <td>{{ account.end_date|default:"-" }}</td>
                    <td>{{ account.balance|currency }}</td>
                    <td>{{ account.num_transactions }}</td>
                    <td>{{ account.date_created }}</td>
                    <td>
                        <a href="{% url 'accounts-update' account.id %}" class="btn">{% trans "Edit" %}</a>
                        <a href="{% url 'accounts-detail' account.id %}" class="btn">{% trans "Transactions" %}</a>
                        <a href="{% url 'accounts-top-up' account.id %}" class="btn">{% trans "Top-up" %}</a>
                        {% if not account.is_frozen %}
                            <a href="{% url 'accounts-freeze' account.id %}" class="btn btn-danger">{% trans "Freeze" %}</a>
                        {% else %}
                            <a href="{% url 'accounts-thaw' account.id %}" class="btn btn-success">{% trans "Thaw" %}</a>
                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        </table>
        {% include "partials/pagination.html" %}
    {% else %}
        <p>{% trans "No results found." %}</p>
    {% endif %}
{% endblock dashboard_content %}
