import { useState, useEffect } from 'react'; import { RefreshCcw, MapPin, Users, TrendingUp, Clock, CheckCircle, AlertCircle, ShoppingBag, Loader2 } from 'lucide-react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { User } from '@/lib/mock-data'; import { dealerService } from '@/services/dealer.service'; interface DealerDashboardProps { currentUser: User | null; onNavigate: (view: string) => void; } export function DealerDashboard({ currentUser, onNavigate }: DealerDashboardProps) { const [loading, setLoading] = useState(true); const [data, setData] = useState(null); useEffect(() => { const fetchDashboard = async () => { try { const dashboardData = await dealerService.getDashboardData(); setData(dashboardData); } catch (error) { console.error('Failed to fetch dashboard:', error); } finally { setLoading(false); } }; fetchDashboard(); }, []); if (loading) { return (

Loading your dashboard...

); } const dashboardData = data || {}; const profile = dashboardData.profile || {}; const statsSummary = dashboardData.stats || { constitutional: 0, relocation: 0, resignation: 0, total: 0 }; const recentRequests = dashboardData.recentRequests || []; const primaryOutlet = dashboardData.outlets?.[0] || {}; // Dealer stats const stats = [ { title: 'Constitutional Changes', value: statsSummary.constitutional, icon: RefreshCcw, color: 'bg-blue-500', change: 'Active Requests', onClick: () => onNavigate('dealer-constitutional') }, { title: 'Relocation Requests', value: statsSummary.relocation, icon: MapPin, color: 'bg-amber-500', change: 'Active Requests', onClick: () => onNavigate('dealer-relocation') }, { title: 'My Outlets', value: dashboardData.outlets?.length || 0, icon: ShoppingBag, color: 'bg-purple-500', change: 'Registered', onClick: () => {} }, { title: 'Total Requests', value: statsSummary.total, icon: TrendingUp, color: 'bg-green-500', change: 'All time', onClick: () => {} }, ]; // Recent requests by the dealer // Quick actions for dealer const quickActions = [ { title: 'Constitutional Change', description: 'Request change in business structure', icon: RefreshCcw, color: 'bg-blue-50 hover:bg-blue-100 border-blue-200', textColor: 'text-blue-700', onClick: () => onNavigate('dealer-constitutional') }, { title: 'Request Relocation', description: 'Move dealership to new location', icon: MapPin, color: 'bg-amber-50 hover:bg-amber-100 border-amber-200', textColor: 'text-amber-700', onClick: () => onNavigate('dealer-relocation') }, ]; return (
{/* Welcome Section */}

Welcome back, {profile.name || currentUser?.name}!

Dealer Code: {profile.dealerCode} • {profile.businessName}

{primaryOutlet.name} • {primaryOutlet.location}

Active Dealership
Operational
{/* Stats Grid */}
{stats.map((stat, index) => { const Icon = stat.icon; return ( {stat.title}
{stat.value}

{stat.change}

); })}
{/* Quick Actions */} Quick Actions Submit new requests and manage your dealership
{quickActions.map((action, index) => { const Icon = action.icon; return ( ); })}
{/* Recent Requests */} My Recent Requests Track the status of your submitted requests
{recentRequests.map((request: any) => (
{request.id} {request.type}

{request.title}

Submitted on {request.date}

{request.status}
))}
{/* Information Cards */}
Important Reminders

GST Filing Due

Due by Jan 15, 2026

Inventory Audit Scheduled

Jan 20, 2026

Compliance Report Submitted

Jan 2, 2026

Support & Help

Regional Manager

Rajesh Kumar - +91 98765 43210

Zonal Business Head

Priya Sharma - +91 98765 43211

Support Email

dealer.support@royalenfield.com

); }