{% extends 'admin/base.html' %}
{% load i18n admin_urls static admin_list %}

{% block extrahead %}
    {{ block.super }}
    {{ media.css }}
    {{ media.js }}
    <style>
        .raw-data-section {
            margin-top: 20px;
            border-top: 1px solid #ccc;
            padding-top: 20px;
        }
        .raw-data-section h2 {
            margin-bottom: 10px;
        }
        .raw-data-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }
        .raw-data-table th, .raw-data-table td {
            border: 1px solid #eee;
            padding: 8px;
            text-align: left;
        }
        .raw-data-table th {
            background-color: #f5f5f5;
        }
    </style>
{% endblock %}

{% block content %}
<div id="content-main">
    <h1>{{ title }}</h1>

    {% if error_message %}
        <p class="errornote">{{ error_message }}</p>
    {% endif %}

    {% if accounts %}
        <div class="module raw-data-section">
            <h2>{% translate "Account Details" %}</h2>
            <table class="raw-data-table">
                <thead>
                    <tr>
                        <th>{% translate "Account UUID" %}</th>
                        <th>{% translate "Net Balance" %}</th>
                        <th>{% translate "Debits Posted" %}</th>
                        <th>{% translate "Credits Posted" %}</th>
                        <th>{% translate "Debits Pending" %}</th>
                        <th>{% translate "Credits Pending" %}</th>
                        <th>{% translate "Ledger" %}</th>
                        <th>{% translate "Code" %}</th>
                        <th>{% translate "Flags" %}</th>
                        <th>{% translate "Timestamp" %}</th>
                        <th>{% translate "User Data 128" %}</th>
                        <th>{% translate "User Data 64" %}</th>
                        <th>{% translate "User Data 32" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for account in accounts %}
                    <tr class="{% cycle 'row1' 'row2' %}">
                        <td>{{ account.uuid }}</td>
                        <td>{{ account.net_balance }}</td>
                        <td>{{ account.debits_posted }}</td>
                        <td>{{ account.credits_posted }}</td>
                        <td>{{ account.debits_pending }}</td>
                        <td>{{ account.credits_pending }}</td>
                        <td>{{ account.ledger }}</td>
                        <td>{{ account.code }}</td>
                        <td>{{ account.flags }}</td>
                        <td>{{ account.timestamp }}</td>
                        <td>{{ account.user_data_128 }}</td>
                        <td>{{ account.user_data_64 }}</td>
                        <td>{{ account.user_data_32 }}</td>
                    </tr>
                    {% empty %}
                    <tr><td colspan="13">{% translate "No account details to display." %}</td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% else %}
        <p>{% translate "No account details to display." %}</p>
    {% endif %}

    {% if transfers %}
        <div class="module raw-data-section">
            <h2>{% translate "Transfer Details" %}</h2>
            <table class="raw-data-table">
                <thead>
                    <tr>
                        <th>{% translate "Transfer ID" %}</th>
                        <th>{% translate "Debit Account" %}</th>
                        <th>{% translate "Credit Account" %}</th>
                        <th>{% translate "Amount" %}</th>
                        <th>{% translate "Ledger" %}</th>
                        <th>{% translate "Code" %}</th>
                        <th>{% translate "Flags" %}</th>
                        <th>{% translate "Timestamp" %}</th>
                        <th>{% translate "Pending ID" %}</th>
                        <th>{% translate "Timeout" %}</th>
                        <th>{% translate "User Data 128" %}</th>
                        <th>{% translate "User Data 64" %}</th>
                        <th>{% translate "User Data 32" %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for transfer in transfers %}
                    <tr class="{% cycle 'row1' 'row2' %}">
                        <td>{{ transfer.id }}</td>
                        <td>{{ transfer.debit_account_id }}</td>
                        <td>{{ transfer.credit_account_id }}</td>
                        <td>{{ transfer.amount }}</td>
                        <td>{{ transfer.ledger }}</td>
                        <td>{{ transfer.code }}</td>
                        <td>{{ transfer.flags }}</td>
                        <td>{{ transfer.timestamp }}</td>
                        <td>{{ transfer.pending_id }}</td>
                        <td>{{ transfer.timeout }}</td>
                        <td>{{ transfer.user_data_128 }}</td>
                        <td>{{ transfer.user_data_64 }}</td>
                        <td>{{ transfer.user_data_32 }}</td>
                    </tr>
                    {% empty %}
                    <tr><td colspan="13">{% translate "No transfer details to display." %}</td></tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    {% else %}
        <p>{% translate "No transfer details to display." %}</p>
    {% endif %}

    <ul class="object-tools">
        <li>
            <a href="{% url 'admin:billing_app_account_changelist' %}" class="viewsitelink">{% translate "Back to Account List" %}</a>
        </li>
    </ul>
</div>
{% endblock %}