'use client'; import { useState, use } from 'react'; import Link from 'next/link'; import { Battery, ArrowLeft, X, BatteryCharging, Activity, Gauge, MapPin, Bike, User, History, Calendar, DollarSign, CheckCircle, Clock, ArrowRightLeft, Handshake, TrendingUp } from 'lucide-react'; interface BMSData { voltage: number; current: number; soc: number; temperature: number; cycles: number; health: number; timestamp: string; } interface OwnershipLog { id: string; batteryId: string; fromOwner: string; fromOwnerType: 'company' | 'biker' | 'hub' | 'swap-station'; toOwner: string; toOwnerType: 'company' | 'biker' | 'hub' | 'swap-station'; fromBikeId?: string; fromBikeModel?: string; toBikeId?: string; toBikeModel?: string; fromHubId?: string; fromHubName?: string; toHubId?: string; toHubName?: string; fromStationId?: string; fromStationName?: string; toStationId?: string; toStationName?: string; action: 'assigned' | 'rented' | 'swapped' | 'returned' | 'retired'; rentAmount?: number; notes?: string; timestamp: string; } interface Battery { id: string; serialNumber: string; brand: string; model: string; type: 'lithium-ion' | 'lifepo4' | 'lead-acid'; capacity: number; voltage: number; purchaseDate: string; purchasePrice: number; warrantyExpiry: string; status: 'available' | 'in-use' | 'maintenance' | 'retired' | 'charging'; currentSoc: number; health: number; cycleCount: number; assignedBikeId?: string; assignedBikeModel?: string; assignedBikePlate?: string; assignedBikerId?: string; assignedBikerName?: string; assignedBikerPhone?: string; currentHubId?: string; currentHubName?: string; currentStationId?: string; currentStationName?: string; lastMaintenance?: string; nextMaintenance?: string; bmsData?: BMSData; monthlyRent?: number; ownershipLogs: OwnershipLog[]; } const mockBattery: Battery = { id: 'BAT-001', serialNumber: 'SN-2024-00001', brand: 'EVE Energy', model: 'Li-Ion 60V50Ah', type: 'lithium-ion', capacity: 50, voltage: 60, purchaseDate: '2024-01-15', purchasePrice: 45000, warrantyExpiry: '2027-01-15', status: 'in-use', currentSoc: 78, health: 95, cycleCount: 156, assignedBikeId: 'EV001', assignedBikeModel: 'Etron ET50', assignedBikePlate: 'Dhaka Metro Cha-A-1234', assignedBikerId: 'BK-001', assignedBikerName: 'Rahim Ahmed', assignedBikerPhone: '01712345678', currentHubId: 'HUB-001', currentHubName: 'JAIBEN Head Office', monthlyRent: 1500, lastMaintenance: '2024-03-01', nextMaintenance: '2024-06-01', bmsData: { voltage: 67.2, current: -2.5, soc: 78, temperature: 32, cycles: 156, health: 95, timestamp: '2024-03-28 12:00:00' }, ownershipLogs: [ { id: 'OL-001', batteryId: 'BAT-001', fromOwner: 'JAIBEN Hub', fromOwnerType: 'hub', toOwner: 'Rahim Ahmed', toOwnerType: 'biker', toBikeId: 'EV001', toBikeModel: 'Etron ET50', toHubId: 'HUB-001', toHubName: 'JAIBEN Head Office', action: 'rented', rentAmount: 1500, timestamp: '2024-03-15 08:30:00' }, { id: 'OL-002', batteryId: 'BAT-001', fromOwner: 'Rahim Ahmed', fromOwnerType: 'biker', toOwner: 'JAIBEN Hub', toOwnerType: 'hub', fromBikeId: 'EV001', fromBikeModel: 'Etron ET50', fromHubId: 'HUB-001', fromHubName: 'JAIBEN Head Office', action: 'returned', timestamp: '2024-03-28 18:00:00', notes: 'Returned for charging' }, { id: 'OL-003', batteryId: 'BAT-001', fromOwner: 'JAIBEN Hub', fromOwnerType: 'hub', toOwner: 'Rahim Ahmed', toOwnerType: 'biker', toBikeId: 'EV001', toBikeModel: 'Etron ET50', toHubId: 'HUB-001', toHubName: 'JAIBEN Head Office', action: 'rented', rentAmount: 1500, timestamp: '2024-03-28 18:30:00' }, ] }; const statusColors: Record = { available: 'bg-green-100 text-green-700', 'in-use': 'bg-blue-100 text-blue-700', maintenance: 'bg-amber-100 text-amber-700', retired: 'bg-slate-100 text-slate-500', charging: 'bg-purple-100 text-purple-700', }; const typeLabels: Record = { 'lithium-ion': 'Lithium-Ion', 'lifepo4': 'LiFePO4', 'lead-acid': 'Lead Acid', }; export default function BatteryDetailPage({ params }: { params: Promise<{ id: string }> }) { const { id } = use(params); const battery = mockBattery; const [activeTab, setActiveTab] = useState<'info' | 'bms' | 'history' | 'rent'>('info'); return (

Battery Details

ID: {battery.id}

{battery.brand} {battery.model}

{battery.serialNumber}

{battery.status}

SOC

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

Health

80 ? 'text-green-600' : battery.health > 60 ? 'text-amber-600' : 'text-red-600'}`}>{battery.health}%

Cycles

{battery.cycleCount}

Price

৳{battery.purchasePrice.toLocaleString()}

{battery.bmsData && (
Live BMS Data Real-time

Voltage

{battery.bmsData.voltage}V

Current

{battery.bmsData.current}A

SOC

{battery.bmsData.soc}%

Temp

{battery.bmsData.temperature}°C

Cycles

{battery.bmsData.cycles}

Health

80 ? 'text-green-600' : 'text-amber-600'}`}>{battery.bmsData.health}%

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

Brand

{battery.brand}

Model

{battery.model}

Serial Number

{battery.serialNumber}

Type

{typeLabels[battery.type]}

Capacity

{battery.capacity} Ah

Voltage

{battery.voltage} V

Purchase Date

{battery.purchaseDate}

Warranty Expiry

{battery.warrantyExpiry}

Last Maintenance

{battery.lastMaintenance || 'N/A'}

Next Maintenance

{battery.nextMaintenance || 'N/A'}

Purchase Price

৳{battery.purchasePrice.toLocaleString()}

{battery.monthlyRent && (

Monthly Rent

৳{battery.monthlyRent}/month

)}
)} {activeTab === 'bms' && battery.bmsData && (

BMS Real-time Data

Updated: {battery.bmsData.timestamp}

Voltage

{battery.bmsData.voltage}V

Current

{battery.bmsData.current}A

SOC

{battery.bmsData.soc}%

Temperature

{battery.bmsData.temperature}°C

Cycles

{battery.bmsData.cycles}

Health

80 ? 'text-green-600' : 'text-amber-600'}`}>{battery.bmsData.health}%

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

Ownership History

{battery.ownershipLogs.length === 0 ? (
No history records
) : (
{battery.ownershipLogs.map((log, index) => (
{log.action} {log.timestamp}

From

{log.fromOwner}

To

{log.toOwner}

{log.rentAmount && (

Rent: ৳{log.rentAmount}/month

)} {log.notes && (

{log.notes}

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

Rent Information

{battery.monthlyRent ? (

Monthly Rent Amount

৳{battery.monthlyRent}

per month

Status

{battery.assignedBikerName ? 'Rented' : 'Not Rented'}

{battery.assignedBikerName ? `to ${battery.assignedBikerName}` : 'Available for rental'}

) : (
This battery is not set up for rental.
)}
)}
{battery.status === 'in-use' && (

Currently Rented to Biker

Active Rental

Biker

{battery.assignedBikerName}

{battery.assignedBikerPhone}

Bike

{battery.assignedBikeModel}

{battery.assignedBikePlate}

Hub/Station

{battery.currentHubName || battery.currentStationName || 'Not Assigned'}

Monthly Rent

৳{battery.monthlyRent}/month

)}
); }