import { useActiveTradeEvents } from '../crm/hooks'; import { useEventCountdown, type EventCountdown } from '../hooks/useEventCountdown'; import type { TradeEvent } from '../crm/types'; import styles from './EventCountdownTiles.module.css'; // ============================================================ // Helpers // ============================================================ function formatDateRange(start: string, end: string): string { const s = new Date(start).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', }); const e = new Date(end).toLocaleDateString('de-DE', { day: '2-digit', month: '2-digit', year: 'numeric', }); return `${s} โ€“ ${e}`; } /** Hide events that ended more than 24h ago */ function isStillRelevant(event: TradeEvent): boolean { const endDay = new Date(event.endDate); endDay.setHours(23, 59, 59, 999); const cutoff = new Date(endDay.getTime() + 24 * 60 * 60 * 1000); return new Date() < cutoff; } // ============================================================ // Single Tile // ============================================================ function CountdownTile({ event }: { event: TradeEvent }) { const countdown: EventCountdown = useEventCountdown(event); const borderColor = countdown.status === 'upcoming' ? '#3b82f6' : countdown.status === 'ongoing' ? '#22c55e' : '#9ca3af'; return (

{event.name}

{countdown.status === 'upcoming' ? 'Bevorstehend' : countdown.status === 'ongoing' ? 'Laeuft' : 'Beendet'}
{/* Countdown / Progress */}
{countdown.status === 'upcoming' && ( {countdown.label} )} {countdown.status === 'ongoing' && ( <> {countdown.label} โ€” laeuft!
)} {countdown.status === 'ended' && ( Beendet )}
{/* Meta Info */}
{formatDateRange(event.startDate, event.endDate)}
{event.location && (
{event.location} {event.boothInfo && ` ยท ${event.boothInfo}`}
)} {!event.location && event.boothInfo && (
{event.boothInfo}
)}
{event.websiteUrl && ( Website )}
); } // ============================================================ // EventCountdownTiles โ€” Grid // ============================================================ export function EventCountdownTiles() { const { data, isLoading } = useActiveTradeEvents(); const events = (data?.data ?? []).filter(isStillRelevant); if (isLoading || events.length === 0) return null; return (
{events.map((ev) => ( ))}
); }