'use client' import { useEffect, useState, useMemo, useCallback } from 'react' import { useSearchParams } from 'next/navigation' import { useStore } from '@/lib/store' import { api } from '@/lib/api' import { CommandCenterLayout } from '@/components/CommandCenterLayout' import { PremiumTable, StatCard, PageContainer, Badge, SectionHeader, SearchInput, ActionButton } from '@/components/PremiumTable' import { Toast, useToast } from '@/components/Toast' import { Eye, Briefcase, TrendingUp, Gavel, Clock, ExternalLink, Sparkles, ChevronRight, Plus, Zap, Crown, Activity, Loader2, Search, } from 'lucide-react' import clsx from 'clsx' import Link from 'next/link' interface HotAuction { domain: string current_bid: number time_remaining: string platform: string affiliate_url?: string } interface TrendingTld { tld: string current_price: number price_change: number reason: string } export default function DashboardPage() { const searchParams = useSearchParams() const { isAuthenticated, isLoading, user, domains, subscription } = useStore() const { toast, showToast, hideToast } = useToast() const [hotAuctions, setHotAuctions] = useState([]) const [trendingTlds, setTrendingTlds] = useState([]) const [loadingAuctions, setLoadingAuctions] = useState(true) const [loadingTlds, setLoadingTlds] = useState(true) const [quickDomain, setQuickDomain] = useState('') const [addingDomain, setAddingDomain] = useState(false) // Check for upgrade success useEffect(() => { if (searchParams.get('upgraded') === 'true') { showToast('Welcome to your upgraded plan! 🎉', 'success') window.history.replaceState({}, '', '/command/dashboard') } }, [searchParams]) const loadDashboardData = useCallback(async () => { try { const [auctions, trending] = await Promise.all([ api.getEndingSoonAuctions(5).catch(() => []), api.getTrendingTlds().catch(() => ({ trending: [] })) ]) setHotAuctions(auctions.slice(0, 5)) setTrendingTlds(trending.trending?.slice(0, 4) || []) } catch (error) { console.error('Failed to load dashboard data:', error) } finally { setLoadingAuctions(false) setLoadingTlds(false) } }, []) // Load dashboard data useEffect(() => { if (isAuthenticated) { loadDashboardData() } }, [isAuthenticated, loadDashboardData]) const handleQuickAdd = useCallback(async (e: React.FormEvent) => { e.preventDefault() if (!quickDomain.trim()) return setAddingDomain(true) try { const store = useStore.getState() await store.addDomain(quickDomain.trim()) setQuickDomain('') showToast(`Added ${quickDomain.trim()} to watchlist`, 'success') } catch (err: any) { showToast(err.message || 'Failed to add domain', 'error') } finally { setAddingDomain(false) } }, [quickDomain, showToast]) // Memoized computed values const { availableDomains, totalDomains, tierName, TierIcon, greeting, subtitle } = useMemo(() => { const availableDomains = domains?.filter(d => d.is_available) || [] const totalDomains = domains?.length || 0 const tierName = subscription?.tier_name || subscription?.tier || 'Scout' const TierIcon = tierName === 'Tycoon' ? Crown : tierName === 'Trader' ? TrendingUp : Zap const hour = new Date().getHours() const greeting = hour < 12 ? 'Good morning' : hour < 18 ? 'Good afternoon' : 'Good evening' let subtitle = '' if (availableDomains.length > 0) { subtitle = `${availableDomains.length} domain${availableDomains.length !== 1 ? 's' : ''} ready to pounce!` } else if (totalDomains > 0) { subtitle = `Monitoring ${totalDomains} domain${totalDomains !== 1 ? 's' : ''} for you` } else { subtitle = 'Start tracking domains to find opportunities' } return { availableDomains, totalDomains, tierName, TierIcon, greeting, subtitle } }, [domains, subscription]) if (isLoading || !isAuthenticated) { return (
) } return ( {toast && } {/* Quick Add */}

Quick Add to Watchlist

setQuickDomain(e.target.value)} placeholder="Enter domain to track (e.g., dream.com)" className="w-full h-11 pl-11 pr-4 bg-background/80 backdrop-blur-sm border border-border/50 rounded-xl text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent/30" />
{/* Stats Overview */}
0} />
{/* Activity Feed + Market Pulse */}
{/* Activity Feed */}
View all → } />
{availableDomains.length > 0 ? (
{availableDomains.slice(0, 4).map((domain) => (

{domain.name}

Available for registration!

Register
))} {availableDomains.length > 4 && (

+{availableDomains.length - 4} more available

)}
) : totalDomains > 0 ? (

All domains are still registered

We're monitoring {totalDomains} domains for you

) : (

No domains tracked yet

Add a domain above to start monitoring

)}
{/* Market Pulse */}
View all → } />
{loadingAuctions ? (
{[...Array(4)].map((_, i) => (
))}
) : hotAuctions.length > 0 ? ( ) : (

No auctions ending soon

)}
{/* Trending TLDs */}
View all → } />
{loadingTlds ? (
{[...Array(4)].map((_, i) => (
))}
) : trendingTlds.length > 0 ? (
{trendingTlds.map((tld) => (
.{tld.tld} 0 ? "text-orange-400 bg-orange-400/10 border-orange-400/20" : "text-accent bg-accent/10 border-accent/20" )}> {(tld.price_change || 0) > 0 ? '+' : ''}{(tld.price_change || 0).toFixed(1)}%

{tld.reason}

))}
) : (

No trending TLDs available

)}
) }