'use client'; import { useState } from 'react'; import Image from 'next/image'; import Link from 'next/link'; import { User, Trophy, Star, Calendar, Users, Flag, Award, TrendingUp, UserPlus, ExternalLink, Target, Zap, Clock, Medal, Crown, ChevronRight, Globe, Twitter, Youtube, Twitch, MessageCircle, ArrowLeft, BarChart3, Shield, Percent, Activity, } from 'lucide-react'; import Button from '@/components/ui/Button'; import Card from '@/components/ui/Card'; import Breadcrumbs from '@/components/layout/Breadcrumbs'; import { CircularProgress } from '@/components/drivers/CircularProgress'; import { HorizontalBarChart } from '@/components/drivers/HorizontalBarChart'; import { mediaConfig } from '@/lib/config/mediaConfig'; import type { DriverProfileViewModel } from '@/lib/view-models/DriverProfileViewModel'; type ProfileTab = 'overview' | 'stats'; interface Team { id: string; name: string; } interface SocialHandle { platform: 'twitter' | 'youtube' | 'twitch' | 'discord'; handle: string; url: string; } interface Achievement { id: string; title: string; description: string; icon: 'trophy' | 'medal' | 'star' | 'crown' | 'target' | 'zap'; rarity: 'common' | 'rare' | 'epic' | 'legendary'; earnedAt: Date; } interface DriverExtendedProfile { socialHandles: SocialHandle[]; achievements: Achievement[]; racingStyle: string; favoriteTrack: string; favoriteCar: string; timezone: string; availableHours: string; lookingForTeam: boolean; openToRequests: boolean; } interface TeamMembershipInfo { team: Team; role: string; joinedAt: Date; } interface DriverProfileTemplateProps { driverProfile: DriverProfileViewModel; allTeamMemberships: TeamMembershipInfo[]; isLoading?: boolean; error?: string | null; onBackClick: () => void; onAddFriend: () => void; friendRequestSent: boolean; activeTab: ProfileTab; setActiveTab: (tab: ProfileTab) => void; isSponsorMode?: boolean; sponsorInsights?: React.ReactNode; } // Helper functions function getCountryFlag(countryCode: string): string { const code = countryCode.toUpperCase(); if (code.length === 2) { const codePoints = [...code].map(char => 127397 + char.charCodeAt(0)); return String.fromCodePoint(...codePoints); } return '🏁'; } function getRarityColor(rarity: Achievement['rarity']) { switch (rarity) { case 'common': return 'text-gray-400 bg-gray-400/10 border-gray-400/30'; case 'rare': return 'text-primary-blue bg-primary-blue/10 border-primary-blue/30'; case 'epic': return 'text-purple-400 bg-purple-400/10 border-purple-400/30'; case 'legendary': return 'text-yellow-400 bg-yellow-400/10 border-yellow-400/30'; } } function getAchievementIcon(icon: Achievement['icon']) { switch (icon) { case 'trophy': return Trophy; case 'medal': return Medal; case 'star': return Star; case 'crown': return Crown; case 'target': return Target; case 'zap': return Zap; } } function getSocialIcon(platform: SocialHandle['platform']) { switch (platform) { case 'twitter': return Twitter; case 'youtube': return Youtube; case 'twitch': return Twitch; case 'discord': return MessageCircle; } } function getSocialColor(platform: SocialHandle['platform']) { switch (platform) { case 'twitter': return 'hover:text-sky-400 hover:bg-sky-400/10'; case 'youtube': return 'hover:text-red-500 hover:bg-red-500/10'; case 'twitch': return 'hover:text-purple-400 hover:bg-purple-400/10'; case 'discord': return 'hover:text-indigo-400 hover:bg-indigo-400/10'; } } export function DriverProfileTemplate({ driverProfile, allTeamMemberships, isLoading = false, error = null, onBackClick, onAddFriend, friendRequestSent, activeTab, setActiveTab, isSponsorMode = false, sponsorInsights = null, }: DriverProfileTemplateProps) { if (isLoading) { return (

Loading driver profile...

); } if (error || !driverProfile?.currentDriver) { return (
{error || 'Driver not found'}
); } const extendedProfile: DriverExtendedProfile = driverProfile.extendedProfile ? { socialHandles: driverProfile.extendedProfile.socialHandles, achievements: driverProfile.extendedProfile.achievements.map((achievement) => ({ id: achievement.id, title: achievement.title, description: achievement.description, icon: achievement.icon, rarity: achievement.rarity, earnedAt: new Date(achievement.earnedAt), })), racingStyle: driverProfile.extendedProfile.racingStyle, favoriteTrack: driverProfile.extendedProfile.favoriteTrack, favoriteCar: driverProfile.extendedProfile.favoriteCar, timezone: driverProfile.extendedProfile.timezone, availableHours: driverProfile.extendedProfile.availableHours, lookingForTeam: driverProfile.extendedProfile.lookingForTeam, openToRequests: driverProfile.extendedProfile.openToRequests, } : { socialHandles: [], achievements: [], racingStyle: 'Unknown', favoriteTrack: 'Unknown', favoriteCar: 'Unknown', timezone: 'UTC', availableHours: 'Flexible', lookingForTeam: false, openToRequests: false, }; const stats = driverProfile?.stats || null; const globalRank = driverProfile?.currentDriver?.globalRank || 1; const driver = driverProfile.currentDriver; return (
{/* Back Navigation */} {/* Breadcrumb */} {/* Sponsor Insights Card */} {isSponsorMode && sponsorInsights} {/* Hero Header Section */}
{/* Background Pattern */}
{/* Avatar */}
{driver.name}
{/* Driver Info */}

{driver.name}

{getCountryFlag(driver.country)}
{/* Rating and Rank */}
{stats && ( <>
{stats.rating} Rating
#{globalRank} Global
)}
{/* Meta info */}
iRacing: {driver.iracingId} Joined{' '} {new Date(driver.joinedAt).toLocaleDateString('en-US', { month: 'short', year: 'numeric', })} {extendedProfile.timezone}
{/* Action Buttons */}
{/* Social Handles */} {extendedProfile.socialHandles.length > 0 && (
Connect: {extendedProfile.socialHandles.map((social: SocialHandle) => { const Icon = getSocialIcon(social.platform); return ( {social.handle} ); })}
)}
{/* Bio Section */} {driver.bio && (

About

{driver.bio}

)} {/* Team Memberships */} {allTeamMemberships.length > 0 && (

Team Memberships ({allTeamMemberships.length})

{allTeamMemberships.map((membership) => (

{membership.team.name}

{membership.role} Since {membership.joinedAt.toLocaleDateString('en-US', { month: 'short', year: 'numeric' })}
))}
)} {/* Performance Overview with Diagrams */} {stats && (

Performance Overview

{/* Circular Progress Charts */}
{/* Bar chart and key metrics */}

Results Breakdown

Best Finish

P{stats.bestFinish}

Avg Finish

P{(stats.avgFinish ?? 0).toFixed(1)}

)} {/* Tab Navigation */}
{/* Tab Content */} {activeTab === 'overview' && ( <> {/* Stats and Profile Grid */}
{/* Career Stats */}

Career Statistics

{stats ? (
{stats.totalRaces}
Races
{stats.wins}
Wins
{stats.podiums}
Podiums
{stats.consistency}%
Consistency
) : (

No race statistics available yet.

)}
{/* Racing Preferences */}

Racing Profile

Racing Style

{extendedProfile.racingStyle}

Favorite Track

{extendedProfile.favoriteTrack}

Favorite Car

{extendedProfile.favoriteCar}

Available

{extendedProfile.availableHours}

{/* Status badges */}
{extendedProfile.lookingForTeam && (
Looking for Team
)} {extendedProfile.openToRequests && (
Open to Friend Requests
)}
{/* Achievements */}

Achievements {extendedProfile.achievements.length} earned

{extendedProfile.achievements.map((achievement: Achievement) => { const Icon = getAchievementIcon(achievement.icon); const rarityClasses = getRarityColor(achievement.rarity); return (

{achievement.title}

{achievement.description}

{achievement.earnedAt.toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', })}

); })}
{/* Friends Preview */} {driverProfile.socialSummary.friends.length > 0 && (

Friends ({driverProfile.socialSummary.friends.length})

{driverProfile.socialSummary.friends.slice(0, 8).map((friend) => (
{friend.name}
{friend.name} {getCountryFlag(friend.country)} ))} {driverProfile.socialSummary.friends.length > 8 && (
+{driverProfile.socialSummary.friends.length - 8} more
)}
)} )} {activeTab === 'stats' && stats && (
{/* Detailed Performance Metrics */}

Detailed Performance Metrics

{/* Performance Bars */}

Results Breakdown

{/* Key Metrics */}
Win Rate

{((stats.wins / stats.totalRaces) * 100).toFixed(1)}%

Podium Rate

{((stats.podiums / stats.totalRaces) * 100).toFixed(1)}%

Consistency

{stats.consistency}%

Finish Rate

{(((stats.totalRaces - stats.dnfs) / stats.totalRaces) * 100).toFixed(1)}%

{/* Position Statistics */}

Position Statistics

P{stats.bestFinish}
Best Finish
P{(stats.avgFinish ?? 0).toFixed(1)}
Avg Finish
P{stats.worstFinish}
Worst Finish
{stats.dnfs}
DNFs
{/* Global Rankings */}

Global Rankings

#{globalRank}
Global Rank
{stats.rating}
Rating
Top {stats.percentile}%
Percentile
)} {activeTab === 'stats' && !stats && (

No statistics available yet

This driver hasn't completed any races yet

)}
); }