'use client' import { useState, useEffect, useCallback } from 'react' import { useParams, useRouter } from 'next/navigation' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Separator } from '@/components/ui/separator' import { ArrowLeft, User, Mail, Calendar, Phone, MapPin, DollarSign, Users, TrendingUp, Award } from 'lucide-react' import { motion } from 'framer-motion' import Link from 'next/link' interface UserProfile { id: string name: string email: string phone?: string address?: string joinedAt: string role: string referralCode: string isActive: boolean stats: { directReferrals: number totalTeam: number personalVolume: number teamVolume: number totalEarnings: number walletBalance: number } recentCommissions: { id: string amount: number level: number type: string status: string createdAt: string }[] } export default function ProfilePage() { const params = useParams() const router = useRouter() const [profile, setProfile] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const fetchProfile = useCallback(async (userId: string) => { try { const response = await fetch(`/api/dashboard/profile/${userId}`) if (!response.ok) { if (response.status === 401) { router.push('/auth/signin') return } throw new Error('Profile not found') } const data = await response.json() setProfile(data) } catch (error) { console.error('Error fetching profile:', error) setError('Failed to load profile') } finally { setLoading(false) } }, [router]) useEffect(() => { if (params.id) { fetchProfile(params.id as string) } }, [params.id, fetchProfile]) if (loading) { return (
) } if (error || !profile) { return (

Profile not found

{error}

) } return (
{/* Header */}

{profile.name}

{profile.email}

{profile.isActive ? 'Active' : 'Inactive'} {profile.role}

Member Since

{new Date(profile.joinedAt).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' })}

{/* Contact Info */} Contact Information

Email

{profile.email}

{profile.phone && (

Phone

{profile.phone}

)}

Referral Code

{profile.referralCode}

{profile.address && (

Address

{profile.address}

)}
{/* Stats */}

Wallet Balance

₹{profile.stats.walletBalance.toFixed(2)}

Direct Referrals

{profile.stats.directReferrals}

Total Team

{profile.stats.totalTeam}

Personal Volume

₹{profile.stats.personalVolume.toFixed(0)}

Team Volume

₹{profile.stats.teamVolume.toFixed(0)}

Total Earnings

₹{profile.stats.totalEarnings.toFixed(2)}

{/* Recent Commissions */} Recent Commissions {profile.recentCommissions.length > 0 ? (
{profile.recentCommissions.map((commission) => (

Level {commission.level} {commission.type}

{new Date(commission.createdAt).toLocaleDateString()}

+₹{commission.amount.toFixed(2)}

{commission.status}
))}
) : (

No commissions yet

)}
) }