'use client' import { useEffect, useState } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import { useStore } from '@/lib/store' import { api } from '@/lib/api' import { CommandCenterLayout } from '@/components/CommandCenterLayout' import { Toast, useToast } from '@/components/Toast' import { Eye, Briefcase, TrendingUp, Gavel, Clock, Bell, ArrowRight, ExternalLink, Sparkles, ChevronRight, Search, Plus, Zap, Crown, Activity, } 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 router = useRouter() const searchParams = useSearchParams() const { isAuthenticated, isLoading, checkAuth, 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) useEffect(() => { checkAuth() }, [checkAuth]) useEffect(() => { if (!isLoading && !isAuthenticated) { router.push('/login') } }, [isLoading, isAuthenticated, router]) // Check for upgrade success useEffect(() => { if (searchParams.get('upgraded') === 'true') { showToast('Welcome to your upgraded plan! 🎉', 'success') window.history.replaceState({}, '', '/dashboard') } }, [searchParams]) // Load dashboard data useEffect(() => { if (isAuthenticated) { loadDashboardData() } }, [isAuthenticated]) const loadDashboardData = 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) } } const handleQuickAdd = 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) } } if (isLoading || !isAuthenticated) { return (
) } // Calculate stats 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 return ( {toast && }
{/* Quick Add */}

Quick Add to Watchlist

setQuickDomain(e.target.value)} placeholder="Enter domain to track (e.g., dream.com)" className="flex-1 h-12 px-4 bg-background border border-border rounded-xl text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-accent focus:ring-1 focus:ring-accent" />
{/* Stats Overview */}

{totalDomains}

Domains Watched

0 ? "bg-accent/10 border-accent/20 hover:border-accent/40" : "bg-background-secondary/50 border-border hover:border-foreground/20" )} >
0 ? "bg-accent/20" : "bg-foreground/5" )}> 0 ? "text-accent" : "text-foreground-muted" )} />
{availableDomains.length > 0 && ( Action! )}

0 ? "text-accent" : "text-foreground" )}> {availableDomains.length}

Available Now

0

Portfolio Domains

{tierName}

{subscription?.domains_used || 0}/{subscription?.domain_limit || 5} slots used

{/* Activity Feed + Market Pulse */}
{/* Activity Feed */}

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 */}

Market Pulse

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

No auctions ending soon

)}
{/* Trending TLDs */}

Trending TLDs

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

{tld.reason}

))}
)}
) }