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 (
{[1, 2, 3, 4, 5].map(i => (
{ if (displayOnly) return; e.stopPropagation(); handleRate(i); }} onMouseEnter={(e) => { if (displayOnly) return; const tooltip = e.currentTarget.querySelector(".tooltip"); if (tooltip) tooltip.style.opacity = "1"; }} onMouseLeave={(e) => { if (displayOnly) return; const tooltip = e.currentTarget.querySelector(".tooltip"); if (tooltip) tooltip.style.opacity = "0"; }} > {/* Base mic icon (gray) */} {/* Overlay mic for fill */} {/* Tooltip */} {!displayOnly && (
{labels[i - 1]}
)}
))}
); };