'use client' import { useEffect, useState } from 'react' import { useStore } from '@/lib/store' import { api } from '@/lib/api' import { CommandCenterLayout } from '@/components/CommandCenterLayout' import { PremiumTable, Badge, StatCard, PageContainer } from '@/components/PremiumTable' import { Search, TrendingUp, TrendingDown, Minus, ChevronRight, Globe, ArrowUpDown, DollarSign, BarChart3, RefreshCw, Bell, } from 'lucide-react' import clsx from 'clsx' import Link from 'next/link' interface TLDData { tld: string min_price: number avg_price: number max_price: number cheapest_registrar: string cheapest_registrar_url?: string price_change_7d?: number popularity_rank?: number } export default function IntelligencePage() { const { subscription } = useStore() const [tldData, setTldData] = useState([]) const [loading, setLoading] = useState(true) const [refreshing, setRefreshing] = useState(false) const [searchQuery, setSearchQuery] = useState('') const [sortBy, setSortBy] = useState<'popularity' | 'price_asc' | 'price_desc' | 'change'>('popularity') const [page, setPage] = useState(0) const [total, setTotal] = useState(0) useEffect(() => { loadTLDData() }, [page, sortBy]) const loadTLDData = async () => { setLoading(true) try { const response = await api.getTldPrices({ limit: 50, offset: page * 50, sort_by: sortBy, }) setTldData(response.tlds || []) setTotal(response.total || 0) } catch (error) { console.error('Failed to load TLD data:', error) } finally { setLoading(false) } } const handleRefresh = async () => { setRefreshing(true) await loadTLDData() setRefreshing(false) } // Filter by search const filteredData = tldData.filter(tld => tld.tld.toLowerCase().includes(searchQuery.toLowerCase()) ) const getTrendIcon = (change: number | undefined) => { if (!change) return if (change > 0) return return } // Calculate stats const lowestPrice = tldData.reduce((min, tld) => Math.min(min, tld.min_price), Infinity) const hottestTld = tldData.find(tld => (tld.price_change_7d || 0) > 0)?.tld || 'N/A' return ( Refresh } > {/* Stats Overview */}
{/* Filters */}
setSearchQuery(e.target.value)} placeholder="Search TLDs..." className="w-full h-11 pl-11 pr-4 bg-background-secondary/50 border border-border/50 rounded-xl text-sm text-foreground placeholder:text-foreground-subtle focus:outline-none focus:border-accent/50 transition-all" />
{/* TLD Table */} tld.tld} loading={loading} onRowClick={(tld) => window.location.href = `/tld-pricing/${tld.tld}`} emptyIcon={} emptyTitle="No TLDs found" emptyDescription={searchQuery ? `No TLDs matching "${searchQuery}"` : "Check back later for TLD data"} columns={[ { key: 'tld', header: 'TLD', render: (tld) => ( .{tld.tld} ), }, { key: 'min_price', header: 'Min Price', render: (tld) => ( ${tld.min_price.toFixed(2)} ), }, { key: 'avg_price', header: 'Avg Price', hideOnMobile: true, render: (tld) => ( ${tld.avg_price.toFixed(2)} ), }, { key: 'change', header: '7d Change', render: (tld) => (
{getTrendIcon(tld.price_change_7d)} 0 ? "text-orange-400" : (tld.price_change_7d || 0) < 0 ? "text-accent" : "text-foreground-muted" )}> {(tld.price_change_7d || 0) > 0 ? '+' : ''}{(tld.price_change_7d || 0).toFixed(1)}%
), }, { key: 'registrar', header: 'Cheapest At', hideOnMobile: true, render: (tld) => ( {tld.cheapest_registrar} ), }, { key: 'actions', header: '', align: 'right', render: (tld) => (
e.stopPropagation()} >
), }, ]} /> {/* Pagination */} {total > 50 && (
Page {page + 1} of {Math.ceil(total / 50)}
)}
) }