// js/flights.js
const FLIGHTS_DATA = <?= json_encode($flight_data['flights'], JSON_UNESCAPED_UNICODE) ?>;

document.addEventListener('DOMContentLoaded', () => {
    const map = L.map('israel-map').setView([31.5, 34.75], 6);
    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; OpenStreetMap'
    }).addTo(map);

    FLIGHTS_DATA.forEach(f => {
        if (f.latitude && f.longitude) {
            const statusColor = {
                'на земле': '#6b7280',
                'набор высоты': '#f59e0b',
                'снижение': '#8b5cf6',
                'крейсерский полет': '#10b981'
            }[f.status] || '#6b7280';

            const icon = L.divIcon({
                className: 'flight-marker',
                html: `<div style="background:${statusColor};width:12px;height:12px;border-radius:50%;border:2px solid white;box-shadow:0 0 8px rgba(0,0,0,0.5);"></div>`,
                iconSize: [16, 16],
                iconAnchor: [8, 8]
            });

            L.marker([f.latitude, f.longitude], { icon })
                .addTo(map)
                .bindPopup(`<b>${f.callsign}</b><br>${f.purpose}<br><small>Статус: ${f.status} | Высота: ${f.altitude} ft</small>`);
        }
    });
});