'use client';
import { useState, useEffect } from 'react';
import { motion, useReducedMotion, AnimatePresence } from 'framer-motion';
import Card from '@/components/ui/Card';
import Button from '@/components/ui/Button';
import StatusBadge from '@/components/ui/StatusBadge';
import InfoBanner from '@/components/ui/InfoBanner';
import {
BarChart3,
Eye,
Users,
Trophy,
TrendingUp,
Calendar,
DollarSign,
Target,
ArrowUpRight,
ArrowDownRight,
ExternalLink,
Loader2,
Car,
Flag,
Megaphone,
ChevronRight,
Plus,
Bell,
Settings,
CreditCard,
FileText,
RefreshCw
} from 'lucide-react';
import Link from 'next/link';
import { SponsorService } from '@/lib/services/sponsors/SponsorService';
import { SponsorDashboardViewModel } from '@/lib/view-models/SponsorDashboardViewModel';
import { ServiceFactory } from '@/lib/services/ServiceFactory';
// Metric Card Component
function MetricCard({
title,
value,
change,
icon: Icon,
suffix = '',
prefix = '',
delay = 0,
}: {
title: string;
value: number | string;
change?: number;
icon: typeof Eye;
suffix?: string;
prefix?: string;
delay?: number;
}) {
const shouldReduceMotion = useReducedMotion();
const isPositive = change && change > 0;
const isNegative = change && change < 0;
return (
{change !== undefined && (
{isPositive ?
: isNegative ?
: null}
{Math.abs(change)}%
)}
{prefix}{typeof value === 'number' ? value.toLocaleString() : value}{suffix}
{title}
);
}
// Sponsorship Category Card
function SponsorshipCategoryCard({
icon: Icon,
title,
count,
impressions,
color,
href
}: {
icon: typeof Trophy;
title: string;
count: number;
impressions: number;
color: string;
href: string;
}) {
return (
{impressions.toLocaleString()}
impressions
);
}
// Activity Item
function ActivityItem({ activity }: { activity: any }) {
return (
{activity.message}
{activity.time}
{activity.formattedImpressions && (
<>
•
{activity.formattedImpressions} views
>
)}
);
}
// Renewal Alert
function RenewalAlert({ renewal }: { renewal: any }) {
const typeIcons = {
league: Trophy,
team: Users,
driver: Car,
race: Flag,
platform: Megaphone,
};
const Icon = typeIcons[renewal.type] || Trophy;
return (
{renewal.name}
Renews {renewal.formattedRenewDate}
{renewal.formattedPrice}
);
}
export default function SponsorDashboardPage() {
const shouldReduceMotion = useReducedMotion();
const [timeRange, setTimeRange] = useState<'7d' | '30d' | '90d' | 'all'>('30d');
const [loading, setLoading] = useState(true);
const [data, setData] = useState(null);
const [error, setError] = useState(null);
useEffect(() => {
const loadDashboard = async () => {
try {
const sponsorService = ServiceFactory.getSponsorService();
const dashboardData = await sponsorService.getSponsorDashboard('demo-sponsor-1');
if (dashboardData) {
setData(dashboardData);
} else {
setError('Failed to load dashboard data');
}
} catch (err) {
console.error('Error loading dashboard:', err);
setError('Failed to load dashboard data');
} finally {
setLoading(false);
}
};
loadDashboard();
}, []);
if (loading) {
return (
);
}
if (error || !data) {
return (
{error || 'No dashboard data available'}
);
}
const categoryData = data.categoryData;
if (loading) {
return (
);
}
return (
{/* Header */}
Sponsor Dashboard
Welcome back, {data.sponsorName}
{/* Time Range Selector */}
{(['7d', '30d', '90d', 'all'] as const).map((range) => (
))}
{/* Quick Actions */}
{/* Key Metrics */}
{/* Sponsorship Categories */}
Your Sponsorships
{/* Main Content Grid */}
{/* Left Column - Sponsored Entities */}
{/* Top Performing Sponsorships */}
{/* Leagues */}
{data.sponsorships.leagues.map((league) => (
{league.tier === 'main' ? 'Main' : 'Secondary'}
{league.entityName}
{league.details}
{league.formattedImpressions}
impressions
))}
{/* Teams */}
{data.sponsorships.teams.map((team) => (
Team
{team.entityName}
{team.details}
{team.formattedImpressions}
impressions
))}
{/* Drivers */}
{data.sponsorships.drivers.slice(0, 2).map((driver) => (
Driver
{driver.entityName}
{driver.details}
{driver.formattedImpressions}
impressions
))}
{/* Upcoming Events */}
Upcoming Sponsored Events
{data.sponsorships.races.length > 0 ? (
{data.sponsorships.races.map((race) => (
{race.entityName}
{race.details}
{race.status}
))}
) : (
No upcoming sponsored events
)}
{/* Right Column - Activity & Quick Actions */}
{/* Quick Actions */}
Quick Actions
{/* Renewal Alerts */}
{data.upcomingRenewals.length > 0 && (
Upcoming Renewals
{data.upcomingRenewals.map((renewal) => (
))}
)}
{/* Recent Activity */}
Recent Activity
{data.recentActivity.map((activity) => (
))}
{/* Investment Summary */}
Investment Summary
Active Sponsorships
{data.activeSponsorships}
Total Investment
{data.formattedTotalInvestment}
Cost per 1K Views
{data.costPerThousandViews}
Next Invoice
Jan 1, 2026
);
}