{% extends 'base.html' %}

{% block content %}
<div class="container mt-4">
    <h2>Chart of Accounts</h2>
    <a href="{% url 'create_account' %}" class="btn btn-primary mb-3">+ Create New Account</a>
    <table class="table table-hover" id="accountTable">
        <thead class="table-dark">
            <tr>
                <th>Code</th>
                <th>Name</th>
                <th>Parent</th>
                <th>Sub Type</th>
                
                <th>Status</th>
            </tr>
        </thead>
        <tbody>
            {% for account in accounts %}
            <tr>
                <td>{{ account.code }}</td>
                <td>{{ account.name }}</td>
                <td>{{ account.full_name }}</td>
                <td>{{ account.sub_type.name }}
                    {% if account.parent %}
                        {{ account.parent.name }}
                    {% else %}
                        -
                    {% endif %}
                
                <td>
                    {% if account.is_active %}
                        <span class="badge bg-success">Active</span>
                    {% else %}
                        <span class="badge bg-secondary">Inactive</span>
                    {% endif %}
                </td>
            </tr>
            {% empty %}
            <tr>
                <td colspan="7" class="text-center">No accounts found.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}
