'use client' import { useEffect, useState, useRef } from 'react' import { TrendingUp, TrendingDown, AlertCircle, Sparkles, Gavel, Clock } from 'lucide-react' import clsx from 'clsx' export interface TickerItem { id: string type: 'tld_change' | 'domain_available' | 'auction_ending' | 'alert' message: string value?: string change?: number urgent?: boolean } interface TickerProps { items: TickerItem[] speed?: number // pixels per second } export function Ticker({ items, speed = 40 }: TickerProps) { const containerRef = useRef(null) const contentRef = useRef(null) const [animationDuration, setAnimationDuration] = useState(0) useEffect(() => { if (contentRef.current && containerRef.current) { const contentWidth = contentRef.current.scrollWidth const duration = contentWidth / speed setAnimationDuration(duration) } }, [items, speed]) if (items.length === 0) return null const getIcon = (type: TickerItem['type'], change?: number) => { switch (type) { case 'tld_change': return change && change > 0 ? : case 'domain_available': return case 'auction_ending': return case 'alert': return default: return null } } const getValueColor = (type: TickerItem['type'], change?: number) => { if (type === 'tld_change') { return change && change > 0 ? 'text-emerald-400' : 'text-red-400' } return 'text-white' } // Duplicate items for seamless loop const tickerItems = [...items, ...items, ...items] return (
{/* Fade edges */}
{tickerItems.map((item, idx) => (
{getIcon(item.type, item.change)} {item.message} {item.value && ( {item.value} )} {item.change !== undefined && ( 0 ? "bg-emerald-500/10 text-emerald-400" : "bg-red-500/10 text-red-400" )}> {item.change > 0 ? '+' : ''}{item.change.toFixed(1)}% )}
))}
) } // Hook to generate ticker items from various data sources export function useTickerItems( trendingTlds: Array<{ tld: string; price_change: number; current_price: number }>, availableDomains: Array<{ name: string }>, hotAuctions: Array<{ domain: string; time_remaining: string }> ): TickerItem[] { const items: TickerItem[] = [] // Add TLD changes trendingTlds.forEach((tld) => { items.push({ id: `tld-${tld.tld}`, type: 'tld_change', message: `.${tld.tld}`, value: `$${tld.current_price.toFixed(2)}`, change: tld.price_change, }) }) // Add available domains availableDomains.slice(0, 3).forEach((domain) => { items.push({ id: `available-${domain.name}`, type: 'domain_available', message: `${domain.name} available!`, urgent: true, }) }) // Add ending auctions hotAuctions.slice(0, 3).forEach((auction) => { items.push({ id: `auction-${auction.domain}`, type: 'auction_ending', message: `${auction.domain}`, value: auction.time_remaining, }) }) return items }