'use client'; import { useState } from 'react'; import { useSearchParams } from 'next/navigation'; import { motion, useReducedMotion } from 'framer-motion'; import Link from 'next/link'; import { Card } from '@/ui/Card'; import { Button } from '@/ui/Button'; import { Box } from '@/ui/Box'; import { Stack } from '@/ui/Stack'; import { Text } from '@/ui/Text'; import { Heading } from '@/ui/Heading'; import { InfoBanner } from '@/ui/InfoBanner'; import { useSponsorSponsorships } from "@/hooks/sponsor/useSponsorSponsorships"; import { Megaphone, Trophy, Users, Eye, Calendar, ExternalLink, Plus, ChevronRight, Check, Clock, XCircle, Car, Flag, Search, TrendingUp, BarChart3, ArrowUpRight, ArrowDownRight, Send, ThumbsUp, ThumbsDown, RefreshCw, } from 'lucide-react'; // ============================================================================ // Types // ============================================================================ type SponsorshipType = 'all' | 'leagues' | 'teams' | 'drivers' | 'races' | 'platform'; type SponsorshipStatus = 'all' | 'active' | 'pending_approval' | 'approved' | 'rejected' | 'expired'; // ============================================================================ // Configuration // ============================================================================ const TYPE_CONFIG = { leagues: { icon: Trophy, color: 'text-primary-blue', bgColor: 'bg-primary-blue/10', label: 'League' }, teams: { icon: Users, color: 'text-purple-400', bgColor: 'bg-purple-400/10', label: 'Team' }, drivers: { icon: Car, color: 'text-performance-green', bgColor: 'bg-performance-green/10', label: 'Driver' }, races: { icon: Flag, color: 'text-warning-amber', bgColor: 'bg-warning-amber/10', label: 'Race' }, platform: { icon: Megaphone, color: 'text-racing-red', bgColor: 'bg-racing-red/10', label: 'Platform' }, all: { icon: BarChart3, color: 'text-gray-400', bgColor: 'bg-gray-400/10', label: 'All' }, }; const STATUS_CONFIG = { active: { icon: Check, color: 'text-performance-green', bgColor: 'bg-performance-green/10', borderColor: 'border-performance-green/30', label: 'Active' }, pending_approval: { icon: Clock, color: 'text-warning-amber', bgColor: 'bg-warning-amber/10', borderColor: 'border-warning-amber/30', label: 'Awaiting Approval' }, approved: { icon: ThumbsUp, color: 'text-primary-blue', bgColor: 'bg-primary-blue/10', borderColor: 'border-primary-blue/30', label: 'Approved' }, rejected: { icon: ThumbsDown, color: 'text-racing-red', bgColor: 'bg-racing-red/10', borderColor: 'border-racing-red/30', label: 'Declined' }, expired: { icon: XCircle, color: 'text-gray-400', bgColor: 'bg-gray-400/10', borderColor: 'border-gray-400/30', label: 'Expired' }, }; // ============================================================================ // Components // ============================================================================ function SponsorshipCard({ sponsorship }: { sponsorship: unknown }) { const shouldReduceMotion = useReducedMotion(); const s = sponsorship as any; // Temporary cast to avoid breaking logic const typeConfig = TYPE_CONFIG[s.type as keyof typeof TYPE_CONFIG]; const statusConfig = STATUS_CONFIG[s.status as keyof typeof STATUS_CONFIG]; const TypeIcon = typeConfig.icon; const StatusIcon = statusConfig.icon; const daysRemaining = Math.ceil((s.endDate.getTime() - Date.now()) / (1000 * 60 * 60 * 24)); const isExpiringSoon = daysRemaining > 0 && daysRemaining <= 30; const isPending = s.status === 'pending_approval'; const isRejected = s.status === 'rejected'; const isApproved = s.status === 'approved'; const getEntityLink = () => { switch (s.type) { case 'leagues': return `/leagues/${s.entityId}`; case 'teams': return `/teams/${s.entityId}`; case 'drivers': return `/drivers/${s.entityId}`; case 'races': return `/races/${s.entityId}`; default: return '#'; } }; return ( {/* Header */} {typeConfig.label} {s.tier && ( {s.tier === 'main' ? 'Main Sponsor' : 'Secondary'} )} {statusConfig.label} {/* Entity Name */} {s.entityName} {s.details && ( {s.details} )} {/* Application/Approval Info for non-active states */} {isPending && ( Application Pending Sent to {s.entityOwner} on{' '} {s.applicationDate?.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} {s.applicationMessage && ( "{s.applicationMessage}" )} )} {isApproved && ( Approved! Approved by {s.entityOwner} on{' '} {s.approvalDate?.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })} Starts {s.startDate.toLocaleDateString('en-US', { month: 'short', day: 'numeric' })} )} {isRejected && ( Application Declined {s.rejectionReason && ( Reason: {s.rejectionReason} )} Reapply )} {/* Metrics Grid - Only show for active sponsorships */} {s.status === 'active' && ( Impressions {s.formattedImpressions} {s.impressionsChange !== undefined && s.impressionsChange !== 0 && ( 0 ? 'text-performance-green' : 'text-racing-red'}> {s.impressionsChange > 0 ? : } {Math.abs(s.impressionsChange)}% )} {s.engagement && ( Engagement {s.engagement}% )} Period {s.startDate.toLocaleDateString('en-US', { month: 'short', year: 'numeric' })} - {s.endDate.toLocaleDateString('en-US', { month: 'short', year: 'numeric' })} Investment {s.formattedPrice} )} {/* Basic info for non-active */} {s.status !== 'active' && ( {s.periodDisplay} {s.formattedPrice} )} {/* Footer */} {s.status === 'active' && ( {daysRemaining > 0 ? `${daysRemaining} days remaining` : 'Ended'} )} {isPending && ( Waiting for response... )} {s.type !== 'platform' && ( View )} {isPending && ( Cancel Application )} {s.status === 'active' && ( Details )} ); } // ============================================================================ // Main Component // ============================================================================ export default function SponsorCampaignsPage() { const searchParams = useSearchParams(); const shouldReduceMotion = useReducedMotion(); const initialType = (searchParams.get('type') as SponsorshipType) || 'all'; const [typeFilter, setTypeFilter] = useState(initialType); const [statusFilter, setStatusFilter] = useState('all'); const [searchQuery, setSearchQuery] = useState(''); const { data: sponsorshipsData, isLoading, error, retry } = useSponsorSponsorships('demo-sponsor-1'); if (isLoading) { return ( Loading sponsorships... ); } if (error || !sponsorshipsData) { return ( {error?.getUserMessage() || 'No sponsorships data available'} {error && ( Retry )} ); } const data = sponsorshipsData; // Filter sponsorships const filteredSponsorships = data.sponsorships.filter((s: unknown) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const sponsorship = s as any; if (typeFilter !== 'all' && sponsorship.type !== typeFilter) return false; if (statusFilter !== 'all' && sponsorship.status !== statusFilter) return false; if (searchQuery && !sponsorship.entityName.toLowerCase().includes(searchQuery.toLowerCase())) return false; return true; }); // Calculate stats const stats = { total: data.sponsorships.length, // eslint-disable-next-line @typescript-eslint/no-explicit-any active: data.sponsorships.filter((s: any) => s.status === 'active').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any pending: data.sponsorships.filter((s: any) => s.status === 'pending_approval').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any approved: data.sponsorships.filter((s: any) => s.status === 'approved').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any rejected: data.sponsorships.filter((s: any) => s.status === 'rejected').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any totalInvestment: data.sponsorships.filter((s: any) => s.status === 'active').reduce((sum: number, s: any) => sum + s.price, 0), // eslint-disable-next-line @typescript-eslint/no-explicit-any totalImpressions: data.sponsorships.reduce((sum: number, s: any) => sum + s.impressions, 0), }; // Stats by type const statsByType = { // eslint-disable-next-line @typescript-eslint/no-explicit-any leagues: data.sponsorships.filter((s: any) => s.type === 'leagues').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any teams: data.sponsorships.filter((s: any) => s.type === 'teams').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any drivers: data.sponsorships.filter((s: any) => s.type === 'drivers').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any races: data.sponsorships.filter((s: any) => s.type === 'races').length, // eslint-disable-next-line @typescript-eslint/no-explicit-any platform: data.sponsorships.filter((s: any) => s.type === 'platform').length, }; return ( {/* Header */} }> My Sponsorships Manage applications and active sponsorship campaigns Find Opportunities {/* Info Banner about how sponsorships work */} {stats.pending > 0 && ( You have {stats.pending} pending application{stats.pending !== 1 ? 's' : ''} waiting for approval. League admins, team owners, and drivers review applications before accepting sponsorships. )} {/* Quick Stats */} {stats.total} Total {stats.active} Active 0 ? 'border-warning-amber/30' : ''}`}> {stats.pending} Pending {stats.approved} Approved ${stats.totalInvestment.toLocaleString()} Active Investment {(stats.totalImpressions / 1000).toFixed(0)}k Impressions {/* Filters */} {/* Search */} setSearchQuery(e.target.value)} className="w-full pl-10 pr-4 py-2.5 rounded-lg border border-charcoal-outline bg-iron-gray text-white placeholder-gray-500 focus:border-primary-blue focus:outline-none" /> {/* Type Filter */} {(['all', 'leagues', 'teams', 'drivers', 'races', 'platform'] as const).map((type) => { const config = TYPE_CONFIG[type]; const Icon = config.icon; const count = type === 'all' ? stats.total : statsByType[type]; return ( setTypeFilter(type)} className={`flex items-center gap-2 px-3 py-2 rounded-lg text-sm font-medium whitespace-nowrap transition-colors ${ typeFilter === type ? 'bg-primary-blue text-white' : 'bg-iron-gray/50 text-gray-400 hover:bg-iron-gray' } border-0 cursor-pointer`} > {config.label} {count} ); })} {/* Status Filter */} {(['all', 'active', 'pending_approval', 'approved', 'rejected'] as const).map((status) => { const config = status === 'all' ? { label: 'All', color: 'text-gray-400' } : STATUS_CONFIG[status]; const count = status === 'all' ? stats.total : data.sponsorships.filter((s: any) => s.status === status).length; return ( setStatusFilter(status)} className={`px-3 py-2 rounded-lg text-sm font-medium transition-colors whitespace-nowrap ${ statusFilter === status ? 'bg-iron-gray text-white border border-charcoal-outline' : 'text-gray-500 hover:text-gray-300' } border-0 cursor-pointer`} > {config.label} {count > 0 && status !== 'all' && ( {count} )} ); })} {/* Sponsorship List */} {filteredSponsorships.length === 0 ? ( No sponsorships found {searchQuery || typeFilter !== 'all' || statusFilter !== 'all' ? 'Try adjusting your filters to see more results.' : 'Start sponsoring leagues, teams, or drivers to grow your brand visibility.'} Browse Leagues Browse Teams Browse Drivers ) : ( {filteredSponsorships.map((sponsorship: any) => ( ))} )} ); }
Loading sponsorships...
{error?.getUserMessage() || 'No sponsorships data available'}