<div class="ejected-header">
    <i class="fa-solid fa-parachute-box"></i>
    <h2>Ejected Pilots</h2>
</div>
<table class="modal-table ejected">
    <thead>
        <tr>
            <th>#</th>
            <th>Pilot</th>
            <th>Latitude</th>
            <th>Longitude</th>
            <th>Altitude</th>
            <th>Credits</th>
        </tr>
    </thead>
    <tbody>
        {% for pilot in ejected_pilots %}
        <tr>
            <td class="n">{{ loop.index }}</td>
            <td><i class="fa-solid fa-parachute-box" style="color: {% if pilot.lost_credits > 0 %}#28a745{% else %}#e67e22{% endif %};"></i> {{ pilot.player_name }}</td>
            <td class="coords" data-lat="{{ pilot.latitude }}">{{ "%.6f"|format(pilot.latitude) }}</td>
            <td class="coords" data-lon="{{ pilot.longitude }}">{{ "%.6f"|format(pilot.longitude) }}</td>
            <td class="n">{{ pilot.altitude | int }}m</td>
            <td class="n">{{ pilot.lost_credits | int }}</td>
        </tr>
        {% else %}
        <tr>
            <td colspan="6" style="text-align: center; color: #5a6270;">No ejected pilots</td>
        </tr>
        {% endfor %}
    </tbody>
</table>

<script>
    // Update coordinates based on user preference
    (function() {
        if (typeof formatCoord === 'function') {
            document.querySelectorAll('td[data-lat]').forEach(function(td) {
                var lat = parseFloat(td.dataset.lat);
                td.textContent = formatCoord(lat, true);
            });
            document.querySelectorAll('td[data-lon]').forEach(function(td) {
                var lon = parseFloat(td.dataset.lon);
                td.textContent = formatCoord(lon, false);
            });
        }
    })();
</script>
