'use client'; import { useState } from 'react'; import Link from 'next/link'; import { useParams } from 'next/navigation'; import { investors as initialInvestors, bikes as initialBikes, transactions as initialTransactions } from '@/data/mockData'; import type { Investor } from '@/data/mockData'; import { ArrowLeft, Wallet, TrendingUp, Banknote, Calendar, Phone, Mail, MapPin, Edit, Trash2, Plus, X, Bike, User, FileText, CreditCard, DollarSign, Clock, ChevronDown, ExternalLink, Download, Upload, AlertTriangle, Shield, Star, CheckCircle, XCircle, Search, Filter } from 'lucide-react'; const statusColors: Record = { active: 'bg-green-100 text-green-700', pending: 'bg-amber-100 text-amber-700', inactive: 'bg-slate-100 text-slate-500', suspended: 'bg-red-100 text-red-700', }; const planColors: Record = { silver: 'bg-slate-200 text-slate-700', gold: 'bg-yellow-100 text-yellow-700', platinum: 'bg-purple-100 text-purple-700', diamond: 'bg-blue-100 text-blue-700', }; const kycColors: Record = { verified: 'bg-green-100 text-green-700', pending: 'bg-amber-100 text-amber-700', rejected: 'bg-red-100 text-red-700', not_submitted: 'bg-slate-100 text-slate-500', }; const bikeStatusColors: Record = { available: 'bg-blue-100 text-blue-700', rented: 'bg-green-100 text-green-700', maintenance: 'bg-amber-100 text-amber-700', retired: 'bg-slate-100 text-slate-500', }; export default function InvestorDetailPage() { const params = useParams(); const investorId = params.id as string; const [investors] = useState(initialInvestors); const investor = investors.find(i => i.id === investorId); const assignedBikes = initialBikes.filter(b => b.investorId === investorId); const investorTransactions = initialTransactions.filter(t => t.userId === investor?.userId); const [activeTab, setActiveTab] = useState('overview'); const [showEditModal, setShowEditModal] = useState(false); const [showAssignBikeModal, setShowAssignBikeModal] = useState(false); const [selectedBikeId, setSelectedBikeId] = useState(''); const [showCreateInvestmentModal, setShowCreateInvestmentModal] = useState(false); const [newInvestment, setNewInvestment] = useState({ planName: '', planType: 'gold' as 'silver' | 'gold' | 'platinum' | 'diamond', selectedBikeIds: [] as string[], totalInvestment: 0, monthlyReturn: 0, expectedRoi: 15, startDate: new Date().toISOString().split('T')[0], endDate: '', paymentMethod: 'bank' as 'bank' | 'mobile' | 'cash' | 'cheque', transactionReference: '', notes: '' }); if (!investor) { return (

Investor Not Found

The investor you're looking for doesn't exist.

Back to Investors
); } const availableBikesForAssignment = initialBikes.filter(b => !b.investorId && b.status === 'available'); const handleAssignBike = () => { alert('Bike assignment functionality - would update bike investorId here'); setShowAssignBikeModal(false); setSelectedBikeId(''); }; const handleCreateInvestment = () => { const invId = `ip${Date.now()}`; const transactionId = `INV/${new Date().getFullYear()}/${String(Math.floor(Math.random() * 1000)).padStart(3, '0')}`; console.log('Creating Investment:', { id: invId, investorId: investor.id, ...newInvestment, actualEarnings: 0, status: 'active' as const, transactionId: transactionId, createdAt: new Date().toISOString() }); console.log('Accounting Entry:', { entryId: `AC-${Date.now()}`, type: 'investment_created', investorId: investor.id, investmentId: invId, amount: newInvestment.totalInvestment, debitAccount: 'Investment Asset - Investor', creditAccount: newInvestment.paymentMethod === 'bank' ? 'Bank Account' : 'Cash Account', transactionRef: transactionId, createdAt: new Date().toISOString() }); alert(`Investment created successfully!\n\nInvestment ID: ${invId}\nTransaction Ref: ${transactionId}\nAmount: ৳${newInvestment.totalInvestment.toLocaleString()}\n\nAccounting entries have been logged.`); setShowCreateInvestmentModal(false); setNewInvestment({ planName: '', planType: 'gold', selectedBikeIds: [], totalInvestment: 0, monthlyReturn: 0, expectedRoi: 15, startDate: new Date().toISOString().split('T')[0], endDate: '', paymentMethod: 'bank', transactionReference: '', notes: '' }); }; return (

{investor.name}

{investor.id} • {investor.email}

{investor.status} {investor.investments && investor.investments.length > 0 && ( {investor.investments.length} Investment{investor.investments.length > 1 ? 's' : ''} )} KYC {investor.kycStatus} Risk: {investor.riskLevel}

৳{investor.totalInvested.toLocaleString()}

Total Invested

৳{investor.totalEarnings.toLocaleString()}

Total Earnings

{investor.activeBikes}

Active Bikes

{investor.roi}%

ROI

{activeTab === 'overview' && (

Personal Information

Full Name

{investor.name}

Phone

{investor.phone}

Email

{investor.email}

Address

{investor.address}

{investor.dateOfBirth && (

Date of Birth

{investor.dateOfBirth}

)} {investor.nidNumber && (

NID Number

{investor.nidNumber}

)}

Emergency Contact

{investor.emergencyContactName && (

Contact

{investor.emergencyContactName}

{investor.emergencyContactRelation} • {investor.emergencyContactPhone}

)}

Investment Details

Total Investments

{investor.investments?.length || 0} active investments

Overall Status

{investor.status}

{investor.referralCode && (

Referral Code

{investor.referralCode}

Referrals: {investor.totalReferrals} • Earnings: ৳{investor.referralEarnings}

)}
{investor.notes && (

Notes

{investor.notes}

)}
)} {activeTab === 'bikes' && (

Assigned Bikes

{assignedBikes.map(bike => (

{bike.model}

{bike.brand}

{bike.status}
Plate {bike.plateNumber}
Location {bike.location}
Battery 50 ? 'text-green-600' : bike.batteryLevel > 20 ? 'text-amber-600' : 'text-red-600'}`}>{bike.batteryLevel}%
Purchase Price ৳{bike.purchasePrice?.toLocaleString() || 0}
Total Earnings ৳{bike.totalEarnings?.toLocaleString() || 0}
))} {assignedBikes.length === 0 && (

No bikes assigned yet

)}
)} {activeTab === 'investments' && (

Investment Plans

{investor.investments?.map((inv) => (

{inv.planName}

{inv.planType} Plan

{inv.status}

Investment

৳{inv.totalInvestment.toLocaleString()}

Monthly Return

৳{inv.monthlyReturn.toLocaleString()}

Expected ROI

{inv.expectedRoi}%

Actual Earned

৳{inv.actualEarnings.toLocaleString()}

{inv.startDate} to {inv.endDate || 'Ongoing'} {inv.paymentMethod}
))} {(!investor.investments || investor.investments.length === 0) && (

No investments yet

)}
)} {activeTab === 'financial' && (

Bank Details

{investor.bankName && (

Bank

{investor.bankName}

{investor.bankBranch}

)} {investor.bankAccountNumber && (

Account

{investor.bankAccountName}

{investor.bankAccountNumber}

)}

Mobile Banking

{investor.mobileBanking && (

{investor.mobileBanking} (Primary)

{investor.mobileBankingNumber}

)} {investor.additionalMobileBanking?.map((mb, idx) => (

{mb.provider}

{mb.number}

{mb.verified && ( Verified )}
))}

Tax Information

{investor.tinNumber && (

TIN

{investor.tinNumber}

)} {investor.passportNumber && (

Passport

{investor.passportNumber}

)}

Investment Summary

Total Invested

৳{investor.totalInvested.toLocaleString()}

Total Earnings

৳{investor.totalEarnings.toLocaleString()}

Pending Earnings

৳{investor.pendingEarnings.toLocaleString()}

Total Withdrawn

৳{investor.totalWithdrawn.toLocaleString()}

)} {activeTab === 'transactions' && (

Transactions

{investorTransactions.map(tx => (

{tx.description}

{tx.createdAt}

{tx.type === 'earning' ? '+' : tx.type === 'withdrawal' ? '-' : '+'}৳{tx.amount.toLocaleString()}

{tx.status}
))} {investorTransactions.length === 0 && (

No transactions yet

)}
)} {activeTab === 'documents' && (

Uploaded Documents

{investor.kycDocuments?.map((doc, idx) => (

{doc.type.replace('_', ' ')}

{doc.number || 'No number'}

{doc.verified ? ( Verified ) : ( Pending )}
))} {(!investor.kycDocuments || investor.kycDocuments.length === 0) && (

No documents uploaded

)}

Drag and drop files here, or click to browse

)}
{showAssignBikeModal && (

Assign Bike to Investor

)} {showCreateInvestmentModal && (

Create New Investment

setNewInvestment({ ...newInvestment, planName: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" placeholder="e.g., Gold EV Fleet 2024" />
{availableBikesForAssignment.map(bike => ( ))}
setNewInvestment({ ...newInvestment, totalInvestment: Number(e.target.value), monthlyReturn: Math.round(Number(e.target.value) * newInvestment.expectedRoi / 100 / 12) })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" placeholder="0" />
setNewInvestment({ ...newInvestment, monthlyReturn: Number(e.target.value) })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" placeholder="0" />
setNewInvestment({ ...newInvestment, expectedRoi: Number(e.target.value) })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" placeholder="15" />
setNewInvestment({ ...newInvestment, startDate: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setNewInvestment({ ...newInvestment, endDate: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setNewInvestment({ ...newInvestment, transactionReference: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" placeholder="Auto-generated if empty" />