'use client'; import { useState } from 'react'; import Link from 'next/link'; import { useParams, useRouter } from 'next/navigation'; import { investors as initialInvestors, bikes as initialBikes, transactions as initialTransactions } from '@/data/mockData'; import type { Investor } from '@/data/mockData'; import toast from 'react-hot-toast'; 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, BookOpen, ArrowRight, Printer, UserCircle, Home, Briefcase, CreditCardIcon, Heart, PhoneCall, PhoneOutgoing, MessageSquare, Save, ShieldCheck, Building2, Users, Check, AlertOctagon, Activity, Award, Camera } 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', }; function SectionCard({ title, icon: Icon, children, headerBg = 'bg-slate-50', headerBorder = 'border-slate-100', editKey, editingSection, setEditingSection, onEdit, editForm, setEditForm }: { title: string; icon: any; children: React.ReactNode; headerBg?: string; headerBorder?: string; editKey?: string; editingSection?: string | null; setEditingSection?: (s: string | null) => void; onEdit?: () => void; editForm?: any; setEditForm?: any }) { return (

{title}

{editKey && setEditingSection ? ( editingSection !== editKey ? ( ) : (
) ) : null}
{children}
); } export default function InvestorDetailPage() { const params = useParams(); const router = useRouter(); 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); // Investor transactions are filtered below 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 [showInvoiceModal, setShowInvoiceModal] = useState(false); const [showJournalModal, setShowJournalModal] = useState(false); const [selectedInvoice, setSelectedInvoice] = useState(null); const [investorJournals, setInvestorJournals] = useState([]); const [showBankModal, setShowBankModal] = useState(false); const [editingSection, setEditingSection] = useState(null); const [editForm, setEditForm] = useState({}); const [showMobileBankingModal, setShowMobileBankingModal] = useState(false); const [showTaxModal, setShowTaxModal] = useState(false); const [showDocModal, setShowDocModal] = useState(false); const [editingBank, setEditingBank] = useState({ bankName: '', bankAccountName: '', bankAccountNumber: '', bankBranch: '', bankRouting: '' }); const [editingMobileBanking, setEditingMobileBanking] = useState({ provider: '', number: '', isPrimary: false }); const [editingTax, setEditingTax] = useState({ tinNumber: '', passportNumber: '' }); const [newDoc, setNewDoc] = useState({ type: 'nid', number: '', url: '' }); const [editingMobileIndex, setEditingMobileIndex] = useState(null); const investorTransactions = initialTransactions.filter(t => t.investorId === investorId); 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 = `INV-${Date.now()}`; const year = new Date().getFullYear(); const transactionRef = newInvestment.transactionReference || `INV/${year}/${String(investor.investments.length + 1).padStart(4, '0')}`; const getDebitAccount = (method: string) => { switch (method) { case 'bank': return { code: '1200', name: 'Bank - City Bank' }; case 'cash': return { code: '1100', name: 'Cash in Hand' }; case 'mobile': return { code: '1300', name: 'bKash Business' }; case 'cheque': return { code: '1410', name: 'Cheque Receivable' }; default: return { code: '1200', name: 'Bank - City Bank' }; } }; const debitAccount = getDebitAccount(newInvestment.paymentMethod); const journalEntry = { entryId: `JE-${Date.now()}`, date: newInvestment.startDate, reference: transactionRef, description: `${investor.name} - ${newInvestment.planName}`, entries: [ { accountCode: debitAccount.code, accountName: debitAccount.name, debit: newInvestment.totalInvestment, credit: 0 }, { accountCode: '2200', accountName: 'Investor Liabilities', debit: 0, credit: newInvestment.totalInvestment }, ], isAuto: true, sourceType: 'investor_funding', createdAt: new Date().toISOString(), type: 'investment', amount: newInvestment.totalInvestment, paymentMethod: newInvestment.paymentMethod }; setInvestorJournals([journalEntry, ...investorJournals]); console.log('Creating Investment:', { id: invId, investorId: investor.id, ...newInvestment, actualEarnings: 0, status: 'active' as const, transactionId: transactionRef, createdAt: new Date().toISOString() }); alert(`Investment created successfully! Investor: ${investor.name} Investment ID: ${invId} Transaction Ref: ${transactionRef} Amount: ৳${newInvestment.totalInvestment.toLocaleString()} Accounting Entry Created (Auto-Journal): ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Date: ${newInvestment.startDate} Ref: ${transactionRef} Description: ${investor.name} - ${newInvestment.planName} Debit (Dr): ${debitAccount.name} ৳${newInvestment.totalInvestment.toLocaleString()} Credit (Cr): Investor Liability ৳${newInvestment.totalInvestment.toLocaleString()} ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`); 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 (
{/* Profile Card Header */}
{/* Profile Image */}
{investor.name.charAt(0)}
{/* Profile Info */}

{investor.name}

{investor.id} • {investor.email}

{investor.referralCode && ( Ref: {investor.referralCode} )} {investor.totalReferrals > 0 && ( Referrals: {investor.totalReferrals} )}
{investor.status} {investor.investments && investor.investments.length > 0 && ( {investor.investments.length} Investment{investor.investments.length > 1 ? 's' : ''} )} KYC {investor.kycStatus} Risk: {investor.riskLevel}
{/* Stats Row */}

Total Invested

৳{investor.totalInvested.toLocaleString()}

Total Earnings

৳{investor.totalEarnings.toLocaleString()}

ROI

{investor.roi}%

Active Bikes

{investor.activeBikes}

Pending Earning

৳{investor.pendingEarnings.toLocaleString()}

Withdrawn

৳{investor.totalWithdrawn.toLocaleString()}

{activeTab === 'overview' && (
setEditForm({ fullName: investor.name, phone: investor.phone, phoneAlt: investor.phoneAlt || '', email: investor.email, nidNumber: investor.nidNumber || '', tinNumber: investor.tinNumber || '', dateOfBirth: investor.dateOfBirth || '', gender: investor.gender || '', occupation: investor.occupation || '', bloodGroup: (investor as any).bloodGroup || '', maritalStatus: (investor as any).maritalStatus || '', religion: (investor as any).religion || '', nationality: (investor as any).nationality || 'Bangladeshi' })} editForm={editForm} setEditForm={setEditForm}> {editingSection === 'personal' ? (
setEditForm({ ...editForm, fullName: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, phone: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, phoneAlt: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, email: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nidNumber: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, tinNumber: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, dateOfBirth: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, occupation: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nationality: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
) : (

Full Name

{investor.name}

Phone

{investor.phone}

Alternate Phone

{investor.phoneAlt || '-'}

Email

{investor.email}

NID Number

{investor.nidNumber || '-'}

TIN Number

{investor.tinNumber || '-'}

Date of Birth

{investor.dateOfBirth || '-'}

Gender

{investor.gender || '-'}

Occupation

{investor.occupation || '-'}

Blood Group

{(investor as any).bloodGroup || '-'}

Marital Status

{(investor as any).maritalStatus || '-'}

Religion

{(investor as any).religion || '-'}

Nationality

{(investor as any).nationality || 'Bangladeshi'}

)}
setEditForm({ nomineeName: (investor as any).nomineeName || '', nomineeRelation: (investor as any).nomineeRelation || '', nomineeNid: (investor as any).nomineeNid || '', nomineePhone: (investor as any).nomineePhone || '', nomineeEmail: (investor as any).nomineeEmail || '', nomineeAddress: (investor as any).nomineeAddress || '', nomineeShare: (investor as any).nomineeShare || '' })} editForm={editForm} setEditForm={setEditForm}> {editingSection === 'nominee' ? (
setEditForm({ ...editForm, nomineeName: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nomineeNid: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nomineePhone: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nomineeEmail: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nomineeShare: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, nomineeAddress: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
) : (

Nominee Name

{(investor as any).nomineeName || '-'}

Relationship

{(investor as any).nomineeRelation || '-'}

NID Number

{(investor as any).nomineeNid || '-'}

Phone

{(investor as any).nomineePhone || '-'}

Email

{(investor as any).nomineeEmail || '-'}

Share %

{(investor as any).nomineeShare || '-'}

Address

{(investor as any).nomineeAddress || '-'}

)}
setEditForm({ emergencyName: investor.emergencyContactName || '', emergencyRelation: investor.emergencyContactRelation || '', emergencyPhone: investor.emergencyContactPhone || '', emergencyEmail: (investor as any).emergencyEmail || '', emergencyAddress: (investor as any).emergencyAddress || '' })} editForm={editForm} setEditForm={setEditForm}> {editingSection === 'emergency' ? (
setEditForm({ ...editForm, emergencyName: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, emergencyPhone: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, emergencyEmail: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, emergencyAddress: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
) : (

Contact Name

{investor.emergencyContactName || '-'}

Relationship

{investor.emergencyContactRelation || '-'}

Phone

{investor.emergencyContactPhone || '-'}

Email

{(investor as any).emergencyEmail || '-'}

Address

{(investor as any).emergencyAddress || '-'}

)}
setEditForm({ companyName: (investor as any).companyName || '', monthlyIncome: (investor as any).monthlyIncome || '', investmentSource: (investor as any).investmentSource || '', profession: investor.occupation || '' })} editForm={editForm} setEditForm={setEditForm}> {editingSection === 'investmentInfo' ? (
setEditForm({ ...editForm, companyName: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, monthlyIncome: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, investmentSource: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" placeholder="e.g., Savings, Business profit, Inheritance" />
setEditForm({ ...editForm, profession: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
) : (

Company / Business Name

{(investor as any).companyName || '-'}

Monthly Income

{(investor as any).monthlyIncome || '-'}

Investment Source

{(investor as any).investmentSource || '-'}

Profession / Occupation

{investor.occupation || '-'}

)}
{ const parts = investor.address.split(',').map(s => s.trim()); setEditForm({ addressLine1: parts.slice(0, 2).join(', '), addressLine2: parts.slice(2, 4).join(', '), division: parts[4] || 'Dhaka', district: parts[5] || 'Dhaka', thana: parts[3] || '', zipCode: parts[6] || '', landmark: parts[7] || '' }); }} editForm={editForm} setEditForm={setEditForm}> {editingSection === 'presentAddress' ? (
setEditForm({ ...editForm, addressLine1: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, addressLine2: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, thana: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, zipCode: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, landmark: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
) : (

Address Line 1

{investor.address}

Landmark

-

Division

Dhaka

District

Dhaka

Thana

-

Zip Code

1205

)}
{ const parts = investor.address.split(',').map(s => s.trim()); setEditForm({ addressLine1: parts.slice(0, 2).join(', '), addressLine2: parts.slice(2, 4).join(', '), division: parts[4] || 'Dhaka', district: parts[5] || 'Dhaka', thana: parts[3] || '', zipCode: parts[6] || '', isSameAsPresent: true }); }} editForm={editForm} setEditForm={setEditForm}> {editingSection === 'permanentAddress' ? (
setEditForm({ ...editForm, isSameAsPresent: e.target.checked })} className="rounded text-investor" />
{!editForm.isSameAsPresent && (
setEditForm({ ...editForm, addressLine1: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, addressLine2: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, thana: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
setEditForm({ ...editForm, zipCode: e.target.value })} className="w-full px-3 py-2 border border-slate-200 rounded-lg text-sm" />
)}
) : (
Same as Present

Address Line 1

{investor.address}

Landmark

-

Division

Dhaka

District

Dhaka

Thana

-

Zip Code

1205

)}
{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}

Account

{investor.bankAccountName}

{investor.bankAccountNumber}

{investor.bankRouting &&

Routing: {investor.bankRouting}

}
) : (

No bank details added

)}

Mobile Banking

{investor.mobileBanking ? (

Primary

{investor.mobileBanking}

{investor.mobileBankingNumber}

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

{mb.provider}

{mb.number}

{mb.verified ? ( Verified ) : ( Pending )}
))} {(!investor.mobileBanking && (!investor.additionalMobileBanking || investor.additionalMobileBanking.length === 0)) && (

No mobile banking added

)}

Tax Information

{investor.tinNumber || investor.passportNumber ? ( <> {investor.tinNumber && (

TIN

{investor.tinNumber}

)} {investor.passportNumber && (

Passport

{investor.passportNumber}

)} ) : (

No tax info added

)}

Investment Summary

Total Invested

৳{investor.totalInvested.toLocaleString()}

Total Earnings

৳{investor.totalEarnings.toLocaleString()}

Pending Earnings

৳{investor.pendingEarnings.toLocaleString()}

Total Withdrawn

৳{investor.totalWithdrawn.toLocaleString()}

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

All Transactions

Pending Withdrawals

{investorTransactions.filter(t => t.type === 'withdrawal' && t.status === 'pending').map(tx => (

{tx.description}

Ref: {tx.referenceNumber || tx.id} • {tx.createdAt}

-৳{tx.amount.toLocaleString()}

Pending
))} {investorTransactions.filter(t => t.type === 'withdrawal' && t.status === 'pending').length === 0 && (

No pending withdrawals

)}

Transaction History

{investorTransactions.map(tx => (

{tx.description}

{tx.createdAt}

{tx.referenceNumber && ( )}

{tx.type === 'earning' || tx.type === 'bike_earning' || tx.type === 'investment_return' || tx.type === 'referral_bonus' ? '+' : tx.type === 'withdrawal' || tx.type === 'penalty' || tx.type === 'adjustment' ? '-' : '+'}৳{tx.amount.toLocaleString()}

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

No transactions yet

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

KYC Documents

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

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

{doc.number || 'No document number'} • Uploaded: {doc.uploadedAt || 'N/A'}

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

No documents uploaded yet

)}

KYC Status: {investor.kycStatus.toUpperCase()}

{investor.kycStatus === 'verified' ? 'All documents have been verified. Investor is fully verified.' : investor.kycStatus === 'pending' ? 'Documents are under review. Verification typically takes 24-48 hours.' : 'Please upload required documents for verification.'}

)}
{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" />