<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AO Records</title>
    <style>
        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background-color: #f8f9fa; padding: 20px; color: #333; }
        .container { max-width: 95%; margin: auto; background: white; padding: 30px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
        h2 { text-align: center; margin-bottom: 20px; }
        .btn { padding: 8px 15px; border-radius: 5px; text-decoration: none; color: white; border: none; cursor: pointer; font-size: 14px; }
        .btn-add { background-color: #28a745; display: inline-block; margin-bottom: 20px; }
        .btn-update { background-color: #007bff; }
        .btn-delete { background-color: #dc3545; }
        .action-cell form { display: inline-block; margin-left: 5px; }
        .table-wrapper { overflow-x: auto; }
        table { width: 100%; border-collapse: collapse; margin-top: 20px; }
        th, td { padding: 12px; border: 1px solid #dee2e6; text-align: right; white-space: nowrap; }
        th { background-color: #343a40; color: white; text-align: center; }
        tr:nth-child(even) { background-color: #f2f2f2; }
        td:first-child, th:first-child { text-align: left; }
        .alert { padding: 10px 15px; margin-bottom: 20px; border-radius: 5px; }
        .alert-success { background-color: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
        .alert-danger { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
    </style>
</head>
<body>
    <div class="container">
        <h2>Assessing Officer Records 👨‍💼</h2>

        <!-- Flash Messages -->
        {% with messages = get_flashed_messages(with_categories=true) %}
          {% if messages %}
            {% for category, message in messages %}
              <div class="alert alert-{{ category }}">{{ message }}</div>
            {% endfor %}
          {% endif %}
        {% endwith %}

        <a href="{{ url_for('add_ao') }}" class="btn btn-add">➕ Add AO Record</a>

        {% if ao_records %}
            <div class="table-wrapper">
                <table>
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Year</th>
                      <th>Gross Total Income</th>
                      <th>Net Taxable Income</th>
                      <th>Total Tax</th>
                      <th>Actions</th>
                    </tr>
                  </thead>
                  <tbody>
                    {% for ao in ao_records %}
                    <tr>
                      <td>{{ ao.id }}</td>
                      <td>{{ ao.year }}</td>
                      <td>{{ ao.gross_total_income }}</td>
                      <td>{{ ao.net_taxable_income }}</td>
                      <td>{{ ao.total_tax }}</td>
                      <td class="action-cell">
                          <a href="{{ url_for('update_ao', id=ao.id) }}" class="btn btn-update">Edit</a>
                          <form action="{{ url_for('delete_ao', id=ao.id) }}" method="POST" style="display:inline;">
                              <button type="submit" class="btn btn-delete" onclick="return confirm('Are you sure you want to delete this AO?');">Delete</button>
                          </form>
                      </td>
                    </tr>
                    {% endfor %}
                  </tbody>
                </table>
            </div>
        {% else %}
            <p style="text-align: center; margin-top: 20px;">No AO records found. Add one above!</p>
        {% endif %}
    </div>
</body>
</html>
