import React, { useState, useEffect } from 'react'; import { TrendingEvent, trendingAnalyticsService } from '../lib/analytics'; import { geolocationService, LocationData } from '../lib/geolocation'; interface WhatsHotEventsProps { userLocation?: LocationData | null; radius?: number; limit?: number; onEventClick?: (event: TrendingEvent) => void; className?: string; } const WhatsHotEvents: React.FC = ({ userLocation, radius = 50, limit = 8, onEventClick, className = '' }) => { const [trendingEvents, setTrendingEvents] = useState([]); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { loadTrendingEvents(); }, [userLocation, radius, limit]); const loadTrendingEvents = async () => { setIsLoading(true); setError(null); try { let lat = userLocation?.latitude; let lng = userLocation?.longitude; // If no user location provided, try to get IP location if (!lat || !lng) { const ipLocation = await geolocationService.getLocationFromIP(); if (ipLocation) { lat = ipLocation.latitude; lng = ipLocation.longitude; } } const trending = await trendingAnalyticsService.getTrendingEvents( lat, lng, radius, limit ); setTrendingEvents(trending); } catch (err) { console.error('Trending events loading error:', err); setError('Failed to load trending events'); } finally { setIsLoading(false); } }; const handleEventClick = (event: TrendingEvent) => { // Track the click event trendingAnalyticsService.trackEvent({ eventId: event.eventId, metricType: 'page_view', sessionId: sessionStorage.getItem('sessionId') || 'anonymous', locationData: userLocation ? { latitude: userLocation.latitude, longitude: userLocation.longitude, city: userLocation.city, state: userLocation.state } : undefined }); if (onEventClick) { onEventClick(event); } else { // Navigate to event page window.location.href = `/e/${event.slug}`; } }; const formatEventTime = (startTime: string) => { const date = new Date(startTime); const now = new Date(); const diffTime = date.getTime() - now.getTime(); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); if (diffDays === 0) { return 'Today'; } else if (diffDays === 1) { return 'Tomorrow'; } else if (diffDays <= 7) { return `${diffDays} days`; } else { return date.toLocaleDateString('en-US', { month: 'short', day: 'numeric' }); } }; const getPopularityBadge = (score: number) => { if (score >= 100) return { text: 'Super Hot', color: 'var(--error-color)' }; if (score >= 50) return { text: 'Hot', color: 'var(--warning-color)' }; if (score >= 25) return { text: 'Trending', color: 'var(--premium-gold)' }; return { text: 'Popular', color: 'var(--glass-text-accent)' }; }; if (isLoading) { return (
Loading hot events...
); } if (error) { return (

Unable to load events

{error}

); } if (trendingEvents.length === 0) { return (

No trending events found

Try expanding your search radius or check back later

); } return (
{/* Header */}
🔥

What's Hot

{userLocation && ( Within {radius} miles )}
{/* Events Grid */}
{trendingEvents.map((event, _index) => { const popularityBadge = getPopularityBadge(event.popularityScore); return (
handleEventClick(event)} className="group cursor-pointer rounded-lg p-4 transition-colors duration-200 border relative overflow-hidden backdrop-blur-lg" style={{ background: 'var(--ui-bg-secondary)', borderColor: 'var(--ui-border-primary)' }} onMouseEnter={(e) => { e.target.style.background = 'var(--ui-bg-elevated)'; e.target.style.borderColor = 'var(--ui-border-secondary)'; }} onMouseLeave={(e) => { e.target.style.background = 'var(--ui-bg-secondary)'; e.target.style.borderColor = 'var(--ui-border-primary)'; }} > {/* Popularity Badge */}
{popularityBadge.text}
{/* Event Image */} {event.imageUrl && (
{event.title}
)} {/* Event Content */}

{event.title}

{event.venue}
{event.distanceMiles && (
{event.distanceMiles.toFixed(1)} miles away
)}
{formatEventTime(event.startTime)}
{/* Event Stats */}
{event.viewCount || 0}
{event.ticketsSold}
{event.isFeature && (
Featured
)}
); })}
{/* View More Button */}
); }; export default WhatsHotEvents;