window.MicRating = function MicRating({ initial = 0, imageId, userCallsign, onRate, displayOnly = false }) { const [rating, setRating] = React.useState(initial); const [clickedIndex, setClickedIndex] = React.useState(null); const labels = [ "No Signal", "Very Weak", "Weak but Audible", "Clear Enough", "Strong Signal", "Excellent — 5 by 9!" ]; const handleRate = (value) => { if (displayOnly) return; setClickedIndex(value); fetch('/gallery/rate-image.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ image_id: imageId, rating: value, user_callsign: userCallsign }) }).then(res => res.json()) .then(data => { if (data.success) { Swal.fire({ toast: true, position: 'top-end', icon: 'success', title: 'Thanks for your rating!', showConfirmButton: false, timer: 1500 }); setTimeout(() => { setClickedIndex(null); setRating(value); if (onRate) onRate(value); }, 500); } else { Swal.fire('Error', data.message || 'Failed to rate image.', 'error'); setClickedIndex(null); } }); }; return (