'use client'; import { useState, use } from 'react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { Bike, MapPin, Battery, User, Wrench, Eye, Edit, Trash2, X, ArrowLeft, PhoneCall, MessageCircle, Calendar, DollarSign, Clock, Navigation, Car, FileText, Shield, Zap, GaugeCircle, CheckCircle, AlertTriangle, Activity, Award, TrendingUp, Wallet, MoreHorizontal, Map, Navigation2, Satellite, FileCheck, FileX, Clock3, History, CreditCard, User2, Phone, Mail, MapPinned } from 'lucide-react'; interface GPSDevice { id: string; phone: string; imei: string; lastActive: string; signal: number; battery: number; } interface BikeDocument { type: 'registration' | 'insurance' | 'fitness' | 'permit' | 'other'; number: string; issueDate: string; expiryDate: string; verified: boolean; } interface RentalHistory { id: string; bikerId: string; bikerName: string; type: 'single' | 'shared' | 'rent-to-own'; status: 'active' | 'completed' | 'disputed'; startDate: string; endDate?: string; dailyRate: number; totalPaid: number; rideCount: number; } interface ActivityLog { id: string; action: string; details: string; date: string; by: string; } interface Bike { id: string; model: string; brand: string; image: string; plateNumber: string; status: 'available' | 'rented' | 'maintenance' | 'retired'; batteryLevel: number; location: string; assignedTo?: string; investorId?: string; investorName?: string; purchaseDate?: string; purchasePrice?: number; currentRent?: number; totalRides?: number; totalDistance?: number; totalEarnings?: number; lastService?: string; nextService?: string; insuranceExpiry?: string; registrationExpiry?: string; notes?: string; gpsDevice?: GPSDevice; documents?: BikeDocument[]; rentalHistory?: RentalHistory[]; activityLog?: ActivityLog[]; } const mockBikes: Bike[] = [ { id: 'EV001', model: 'Etron ET50', brand: 'Etron', image: '', plateNumber: 'Dhaka Metro Cha-A-1234', status: 'rented', batteryLevel: 78, location: 'Gulshan 1', assignedTo: 'Rahim Ahmed', investorId: 'inv1', investorName: 'Mr. Hasan (Investor)', purchaseDate: '2024-01-15', purchasePrice: 125000, currentRent: 350, totalRides: 156, totalDistance: 2340, totalEarnings: 54600, lastService: '2024-03-01', nextService: '2024-04-01', insuranceExpiry: '2025-01-15', registrationExpiry: '2026-01-15', gpsDevice: { id: 'GPS001', phone: '01712345601', imei: '861234567890123', lastActive: '2024-03-21 14:30', signal: 85, battery: 72 }, documents: [ { type: 'registration', number: 'REG-EV001-2024', issueDate: '2024-01-15', expiryDate: '2026-01-15', verified: true }, { type: 'insurance', number: 'INS-EV001-2024', issueDate: '2024-01-15', expiryDate: '2025-01-15', verified: true }, { type: 'fitness', number: 'FIT-EV001-2024', issueDate: '2024-01-15', expiryDate: '2025-01-15', verified: true }, { type: 'permit', number: 'PMT-EV001-2024', issueDate: '2024-01-15', expiryDate: '2026-01-15', verified: true }, ], rentalHistory: [ { id: 'R001', bikerId: 'B001', bikerName: 'Rahim Ahmed', type: 'single', status: 'active', startDate: '2024-03-01', dailyRate: 350, totalPaid: 7350, rideCount: 21 }, { id: 'R002', bikerId: 'B003', bikerName: 'Jamal Khan', type: 'rent-to-own', status: 'completed', startDate: '2024-02-01', endDate: '2024-02-28', dailyRate: 400, totalPaid: 11200, rideCount: 28 }, { id: 'R003', bikerId: 'B005', bikerName: 'Mahir Islam', type: 'shared', status: 'completed', startDate: '2024-01-15', endDate: '2024-01-31', dailyRate: 60, totalPaid: 2700, rideCount: 45 }, ], activityLog: [ { id: 'A001', action: 'Rental Started', details: 'Single rental by Rahim Ahmed', date: '2024-03-01 08:00', by: 'System' }, { id: 'A002', action: 'Service', details: 'Regular maintenance completed', date: '2024-03-01', by: 'Admin' }, { id: 'A003', action: 'GPS Update', details: 'New GPS device installed', date: '2024-02-15', by: 'Admin' }, { id: 'A004', action: 'Rental Completed', details: 'Rent-to-own by Jamal Khan', date: '2024-02-28 23:59', by: 'System' }, { id: 'A005', action: 'Insurance Renewed', details: 'Insurance renewed for 1 year', date: '2024-01-15', by: 'Admin' }, ] }, { id: 'EV002', model: 'Yadea DT3', brand: 'Yadea', image: '', plateNumber: 'Dhaka Metro Cha-A-5678', status: 'available', batteryLevel: 95, location: 'Banani', investorId: 'inv1', investorName: 'Mr. Hasan (Investor)', purchaseDate: '2024-02-01', purchasePrice: 118000, totalRides: 89, totalDistance: 1567, totalEarnings: 31150, lastService: '2024-03-15', nextService: '2024-04-15', insuranceExpiry: '2025-02-01', registrationExpiry: '2026-02-01', gpsDevice: { id: 'GPS002', phone: '01712345602', imei: '861234567890124', lastActive: '2024-03-21 15:00', signal: 92, battery: 88 }, documents: [ { type: 'registration', number: 'REG-EV002-2024', issueDate: '2024-02-01', expiryDate: '2026-02-01', verified: true }, { type: 'insurance', number: 'INS-EV002-2024', issueDate: '2024-02-01', expiryDate: '2025-02-01', verified: true }, { type: 'fitness', number: 'FIT-EV002-2024', issueDate: '2024-02-01', expiryDate: '2025-02-01', verified: true }, ], rentalHistory: [ { id: 'R004', bikerId: 'B002', bikerName: 'Karim Singh', type: 'single', status: 'completed', startDate: '2024-02-15', endDate: '2024-02-28', dailyRate: 350, totalPaid: 4900, rideCount: 14 }, ], activityLog: [ { id: 'A006', action: 'Service', details: 'Regular maintenance', date: '2024-03-15', by: 'Admin' }, { id: 'A007', action: 'Added to Fleet', details: 'Bike registered in system', date: '2024-02-01', by: 'Admin' }, ] }, { id: 'EV003', model: 'AIMA Lightning', brand: 'AIMA', image: '', plateNumber: 'Dhaka Metro Cha-A-9012', status: 'rented', batteryLevel: 62, location: 'Uttara', assignedTo: 'Karim Singh', investorId: 'inv1', investorName: 'Mr. Hasan (Investor)', purchaseDate: '2024-01-20', purchasePrice: 132000, currentRent: 400, totalRides: 203, totalDistance: 3890, totalEarnings: 71100, lastService: '2024-03-10', nextService: '2024-04-10', insuranceExpiry: '2025-01-20', registrationExpiry: '2026-01-20', gpsDevice: { id: 'GPS003', phone: '01712345603', imei: '861234567890125', lastActive: '2024-03-21 14:45', signal: 78, battery: 55 }, documents: [ { type: 'registration', number: 'REG-EV003-2024', issueDate: '2024-01-20', expiryDate: '2026-01-20', verified: true }, { type: 'insurance', number: 'INS-EV003-2024', issueDate: '2024-01-20', expiryDate: '2025-01-20', verified: true }, { type: 'fitness', number: 'FIT-EV003-2024', issueDate: '2024-01-20', expiryDate: '2025-01-20', verified: true }, ], rentalHistory: [], activityLog: [] }, { id: 'EV004', model: 'TVS iQube', brand: 'TVS', image: '', plateNumber: 'Dhaka Metro Cha-A-3456', status: 'maintenance', batteryLevel: 45, location: 'Workshop - Banani', investorId: 'inv2', investorName: 'Mrs. Rita (Investor)', purchaseDate: '2023-12-10', purchasePrice: 145000, totalRides: 312, totalDistance: 5670, totalEarnings: 98000, lastService: '2024-03-20', nextService: '2024-03-25', insuranceExpiry: '2024-12-10', registrationExpiry: '2025-12-10', notes: 'Motor issue - awaiting parts', gpsDevice: { id: 'GPS004', phone: '01712345604', imei: '861234567890126', lastActive: '2024-03-20 10:00', signal: 0, battery: 12 }, documents: [ { type: 'registration', number: 'REG-EV004-2023', issueDate: '2023-12-10', expiryDate: '2025-12-10', verified: true }, { type: 'insurance', number: 'INS-EV004-2023', issueDate: '2023-12-10', expiryDate: '2024-12-10', verified: true }, ], rentalHistory: [], activityLog: [] }, { id: 'EV005', model: 'Bajaj Chetak', brand: 'Bajaj', image: '', plateNumber: 'Dhaka Metro Cha-A-7890', status: 'available', batteryLevel: 100, location: 'Dhanmondi', investorId: 'inv2', investorName: 'Mrs. Rita (Investor)', purchaseDate: '2024-02-15', purchasePrice: 138000, totalRides: 67, totalDistance: 890, totalEarnings: 23450, lastService: '2024-03-18', nextService: '2024-04-18', insuranceExpiry: '2025-02-15', registrationExpiry: '2026-02-15', gpsDevice: { id: 'GPS005', phone: '01712345605', imei: '861234567890127', lastActive: '2024-03-21 15:30', signal: 95, battery: 92 }, documents: [ { type: 'registration', number: 'REG-EV005-2024', issueDate: '2024-02-15', expiryDate: '2026-02-15', verified: true }, { type: 'insurance', number: 'INS-EV005-2024', issueDate: '2024-02-15', expiryDate: '2025-02-15', verified: true }, ], rentalHistory: [], activityLog: [] }, ]; function getBikeById(id: string): Bike | undefined { return mockBikes.find(b => b.id === id); } const statusColors: Record = { available: 'bg-green-100 text-green-700', rented: 'bg-blue-100 text-blue-700', maintenance: 'bg-amber-100 text-amber-700', retired: 'bg-slate-100 text-slate-500', }; const docTypeLabels: Record = { registration: 'Registration Certificate', insurance: 'Insurance', fitness: 'Fitness Certificate', permit: 'Road Permit', other: 'Other', }; export default function FleetDetailPage({ params }: { params: Promise<{ id: string }> }) { const resolvedParams = use(params); const router = useRouter(); const bikeData = getBikeById(resolvedParams.id); const [activeTab, setActiveTab] = useState('overview'); if (!bikeData) { return (

Bike Not Found

The bike ID "{resolvedParams.id}" was not found.

Back to Fleet
); } const bike = bikeData; const tabs = [ { id: 'overview', label: 'Overview', icon: Bike }, { id: 'gps', label: 'GPS & Tracking', icon: Navigation2 }, { id: 'documents', label: 'Documents', icon: FileText }, { id: 'rental', label: 'Rental History', icon: History }, { id: 'activity', label: 'Activity Log', icon: Clock3 }, { id: 'investor', label: 'Investor Info', icon: User2 }, ]; return (

Bike Details

ID: {bike.id}

{tabs.map(tab => ( ))}
{activeTab === 'overview' && } {activeTab === 'gps' && } {activeTab === 'documents' && } {activeTab === 'rental' && } {activeTab === 'activity' && } {activeTab === 'investor' && }
); } function OverviewTab({ bike }: { bike: Bike }) { return (

{bike.model}

{bike.brand} • {bike.id}

{bike.status} {bike.location}

Plate Number

{bike.plateNumber}

Battery

50 ? 'text-green-600' : bike.batteryLevel > 20 ? 'text-amber-600' : 'text-red-600'}`}>{bike.batteryLevel}%

Current Renter

{bike.assignedTo || 'Available'}

Daily Rate

৳{bike.currentRent || 0}

Performance Metrics

Total Rides

{bike.totalRides || 0}

Distance

{(bike.totalDistance || 0).toLocaleString()} km

Total Earnings

৳{bike.totalEarnings?.toLocaleString() || 0}

Purchase Price

৳{bike.purchasePrice?.toLocaleString() || 0}

Maintenance

Last Service

{bike.lastService || 'N/A'}

Next Service

{bike.nextService || 'N/A'}

Insurance Expiry

{bike.insuranceExpiry || 'N/A'}

Registration Expiry

{bike.registrationExpiry || 'N/A'}

{bike.notes && (

Note

{bike.notes}

)}
); } function GPSTab({ bike }: { bike: Bike }) { const gps = bike.gpsDevice; if (!gps) { return (

No GPS Device

This bike doesn't have a GPS device installed.

); } return (

GPS Device

ID: {gps.id}

Phone Number

{gps.phone}

IMEI

{gps.imei}

Status

Last Active

{gps.lastActive}

Signal Strength

70 ? 'text-green-600' : gps.signal > 40 ? 'text-amber-600' : 'text-red-600'}`}> {gps.signal}%

GPS Battery

50 ? 'text-green-600' : gps.battery > 20 ? 'text-amber-600' : 'text-red-600'}`}> {gps.battery}%

Status

Active

Live Location

{bike.location}

); } function DocumentsTab({ bike }: { bike: Bike }) { const docs = bike.documents || []; return (

Bike Documents

{docs.length === 0 ? (

No documents uploaded.

) : (
{docs.map((doc, idx) => (

{docTypeLabels[doc.type]}

Number: {doc.number}

Issued: {doc.issueDate} • Expires: {doc.expiryDate}

{doc.verified ? : } {doc.verified ? 'Verified' : 'Pending'}
))}
)}

Add New Document

); } function RentalTab({ bike }: { bike: Bike }) { const history = bike.rentalHistory || []; const getRateDisplay = (type: string, rate: number) => { switch (type) { case 'single': return `৳${rate}/day`; case 'shared': return `৳${rate/2}+${rate/2} (2 person)`; case 'rent-to-own': return `৳${rate}/day`; default: return `৳${rate}`; } }; return (

Rental History

{history.length === 0 ? (

No rental history yet.

) : (
{history.map(rental => (

{rental.bikerName}

ID: {rental.id}

{rental.status}
{rental.type === 'single' ? 'Single (৳350/day)' : rental.type === 'shared' ? 'Shared (৳60/day)' : 'Rent-to-Own (৳450/day)'} {rental.startDate} {rental.endDate && `to ${rental.endDate}`}
{rental.rideCount} rides ৳{rental.totalPaid.toLocaleString()}
))}
)}

Rental Rates Info

1
Single
৳350/day
2
Shared (2 Person)
৳60/day (৳30+৳30)
3
Rent-to-Own
৳450/day
); } function ActivityTab({ bike }: { bike: Bike }) { const logs = bike.activityLog || []; return (

Activity Log

{logs.length === 0 ? (

No activity yet.

) : (
{logs.map(log => (

{log.action}

{log.details}

{log.date} by {log.by}

))}
)}
); } function InvestorTab({ bike }: { bike: Bike }) { return (

Investor Information

{!bike.investorId ? (

No investor assigned.

) : (

{bike.investorName || 'Investor'}

ID: {bike.investorId}

Purchase Date

{bike.purchaseDate || 'N/A'}

Purchase Price

৳{bike.purchasePrice?.toLocaleString() || 0}

Total Earnings

৳{bike.totalEarnings?.toLocaleString() || 0}

ROI

{bike.purchasePrice && bike.totalEarnings ? ((bike.totalEarnings / bike.purchasePrice) * 100).toFixed(1) : 0}%

)}

Payment Summary

Total Paid by Renters ৳{bike.totalEarnings?.toLocaleString() || 0}
Investor Share (80%) ৳{Math.round((bike.totalEarnings || 0) * 0.8).toLocaleString()}
Company Share (20%) ৳{Math.round((bike.totalEarnings || 0) * 0.2).toLocaleString()}
); }