{% extends 'base.html' %}
{% load static %}
{% block title %}{{ fee.name }} — Fee Detail{% endblock %}

{% block content %}
<div class="container-fluid">
  <div class="d-flex justify-content-between align-items-center mb-4">
    <div>
      <h1 class="h3 mb-0">{{ fee.name }}</h1>
      <p class="text-muted mb-0">
        {{ fee.get_section_display }} &bull; {{ fee.get_class_group_display }} &bull; {{ fee.academic_year }}
      </p>
    </div>
    <div class="btn-group">
      <a href="{% url 'finance:fee_list' %}" class="btn btn-outline-secondary">
        <i class="fas fa-arrow-left me-1"></i>Back
      </a>
      <a href="{% url 'finance:fee_edit' fee.pk %}" class="btn btn-warning">
        <i class="fas fa-edit me-1"></i>Edit
      </a>
      <a href="{% url 'finance:fee_delete' fee.pk %}" class="btn btn-danger">
        <i class="fas fa-trash me-1"></i>Delete
      </a>
    </div>
  </div>

  <div class="row">
    <!-- Main details -->
    <div class="col-md-7">
      <div class="card shadow mb-4">
        <div class="card-header py-3">
          <h6 class="m-0 fw-bold text-primary">Fee Details</h6>
        </div>
        <div class="card-body">
          <table class="table table-borderless mb-0">
            <tr>
              <td class="text-muted fw-bold" width="35%">Section</td>
              <td>
                <span class="badge {% if fee.section == 'anglo' %}bg-primary{% else %}bg-success{% endif %}">
                  {{ fee.get_section_display }}
                </span>
              </td>
            </tr>
            <tr>
              <td class="text-muted fw-bold">Class Group</td>
              <td><strong>{{ fee.get_class_group_display }}</strong></td>
            </tr>
            <tr>
              <td class="text-muted fw-bold">Academic Year</td>
              <td>{{ fee.academic_year }}</td>
            </tr>
            <tr><td colspan="2"><hr class="my-1"></td></tr>
            <tr>
              <td class="text-muted fw-bold">Registration — New Pupil</td>
              <td class="fw-bold text-warning">{{ fee.registration_new|floatformat:0 }} XAF</td>
            </tr>
            <tr>
              <td class="text-muted fw-bold">Registration — Returning Pupil</td>
              <td class="fw-bold text-warning">{{ fee.registration_old|floatformat:0 }} XAF</td>
            </tr>
            <tr><td colspan="2"><hr class="my-1"></td></tr>
            <tr>
              <td class="text-muted fw-bold">Total Annual Fees</td>
              <td class="fw-bold text-primary fs-5">{{ fee.total_fees|floatformat:0 }} XAF</td>
            </tr>
            <tr>
              <td class="text-muted fw-bold">1st Installment</td>
              <td class="text-success fw-bold">{{ fee.installment_1|floatformat:0 }} XAF</td>
            </tr>
            <tr>
              <td class="text-muted fw-bold">2nd Installment</td>
              <td class="text-success fw-bold">{{ fee.installment_2|floatformat:0 }} XAF</td>
            </tr>
            <tr><td colspan="2"><hr class="my-1"></td></tr>
            <tr>
              <td class="text-muted fw-bold">Status</td>
              <td>
                {% if fee.is_active %}
                  <span class="badge bg-success">Active</span>
                {% else %}
                  <span class="badge bg-secondary">Inactive</span>
                {% endif %}
              </td>
            </tr>
            {% if fee.description %}
            <tr>
              <td class="text-muted fw-bold">Notes</td>
              <td>{{ fee.description }}</td>
            </tr>
            {% endif %}
          </table>
        </div>
      </div>
    </div>

    <!-- Applicable classes -->
    <div class="col-md-5">
      {% if applicable_classes %}
      <div class="card shadow">
        <div class="card-header py-3">
          <h6 class="m-0 fw-bold text-primary">Pinned to Specific Classes</h6>
        </div>
        <div class="card-body p-0">
          <ul class="list-group list-group-flush">
            {% for cls in applicable_classes %}
            <li class="list-group-item">
              <i class="fas fa-chalkboard text-primary me-2"></i>{{ cls }}
            </li>
            {% endfor %}
          </ul>
        </div>
      </div>
      {% else %}
      <div class="alert alert-light border">
        <i class="fas fa-info-circle me-2 text-muted"></i>
        This fee row applies to <strong>all classes</strong> in its group — no specific class pins.
      </div>
      {% endif %}
    </div>
  </div>
</div>
{% endblock %}