import React, { useState, useEffect } from 'react'; import { useCarDashboardOptimizer } from '../hooks/useCarDashboardOptimizer'; import './CarDashboardOptimizer.css'; export const CarDashboardOptimizer: React.FC = () => { const { status, settings, isCarDashboard, isLoading, error, enableInstantStartup, startAggressiveCaching, initiateHandoffToPhone, updateSettings, getCacheStatistics } = useCarDashboardOptimizer(); const [cacheStats, setCacheStats] = useState(null); const [isEnablingStartup, setIsEnablingStartup] = useState(false); const [isStartingCaching, setIsStartingCaching] = useState(false); const [isInitiatingHandoff, setIsInitiatingHandoff] = useState(false); // Load cache statistics useEffect(() => { const loadStats = async () => { try { const stats = await getCacheStatistics(); setCacheStats(stats); } catch (err) { console.error('Failed to load cache statistics:', err); } }; if (!isLoading && !error) { loadStats(); const interval = setInterval(loadStats, 5000); return () => clearInterval(interval); } }, [isLoading, error, getCacheStatistics]); const handleEnableInstantStartup = async () => { setIsEnablingStartup(true); try { await enableInstantStartup(); } catch (err) { console.error('Failed to enable instant startup:', err); } finally { setIsEnablingStartup(false); } }; const handleStartAggressiveCaching = async () => { setIsStartingCaching(true); try { await startAggressiveCaching(); } catch (err) { console.error('Failed to start aggressive caching:', err); } finally { setIsStartingCaching(false); } }; const handleInitiateHandoff = async () => { setIsInitiatingHandoff(true); try { await initiateHandoffToPhone(); } catch (err) { console.error('Failed to initiate handoff:', err); } finally { setIsInitiatingHandoff(false); } }; const handleSettingsChange = async (key: string, value: any) => { try { await updateSettings({ [key]: value }); } catch (err) { console.error('Failed to update settings:', err); } }; if (isLoading) { return (

Initializing car dashboard optimizer...

); } if (error) { return (

⚠️ Car Dashboard Optimizer Error

{error}

); } if (!isCarDashboard) { return (

📱 Mobile/Desktop Mode

Car dashboard optimizations are not active on this device.

{status && (

Cache Size: {Math.round((cacheStats?.cacheSize || 0) / (1024 * 1024))} MB

Cached Songs: {cacheStats?.totalCachedSongs || 0}

)}
); } return (

🚗 Car Dashboard Mode

🚗 Optimized for Car Use
{/* Status Overview */}
{status?.instantStartupReady ? '🚀' : '⏳'}

Instant Startup

{status?.instantStartupReady ? 'Ready' : 'Preparing...'}

{status?.priorityCacheComplete ? '💾' : '📥'}

Priority Cache

{status?.cachedSongCount || 0} / {settings?.prioritySongCount || 0} songs

{status?.handoffInProgress ? '🔄' : '🤝'}

Device Handoff

{status?.handoffInProgress ? 'In Progress' : 'Ready'}

{/* Cache Statistics */} {cacheStats && (

📊 Cache Statistics

Total Songs: {cacheStats.totalCachedSongs.toLocaleString()}
Cache Size: {(cacheStats.cacheSize / (1024 * 1024 * 1024)).toFixed(1)} GB
Priority Songs: {cacheStats.prioritySongsCount.toLocaleString()}
Storage Limit: {((settings?.maxCacheSize || 0) / (1024 * 1024 * 1024)).toFixed(0)} GB
)} {/* Action Buttons */}
{/* Settings */}

⚙️ Car Dashboard Settings

Eliminate all loading delays

Cache complete albums when playing any track

Cache all songs in current queue

Number of priority songs to cache

Maximum storage for car dashboard cache

{/* Progress Indicators */} {(status?.handoffInProgress || isStartingCaching || isEnablingStartup) && (

🔄 Operations in Progress

{status?.handoffInProgress && (
Device handoff in progress...
)} {isStartingCaching && (
Aggressive caching starting...
)} {isEnablingStartup && (
Enabling instant startup...
)}
)}
); };