'use client'; import { useState, useEffect, useCallback } from 'react'; import { Button } from '@/components/ui/Button'; import { getMobileDeStatus, pushToMobileDe, type MobileDeStatusResponse, } from '@/lib/vehicles'; interface MobileDeStatusProps { vehicleId: string; } const STATUS_STYLES: Record = { synced: 'bg-green-100 text-green-800', pending: 'bg-yellow-100 text-yellow-800', fehler: 'bg-red-100 text-red-800', deleted: 'bg-gray-100 text-gray-800', }; const STATUS_LABELS: Record = { synced: 'Synced', pending: 'Pending', fehler: 'Error', deleted: 'Deleted', }; export function MobileDeStatus({ vehicleId }: MobileDeStatusProps) { const [status, setStatus] = useState(null); const [loading, setLoading] = useState(true); const [pushing, setPushing] = useState(false); const [error, setError] = useState(null); const fetchStatus = useCallback(async () => { setLoading(true); setError(null); try { const data = await getMobileDeStatus(vehicleId); setStatus(data); } catch (err: unknown) { const apiErr = err as { error?: { message?: string } }; setError(apiErr?.error?.message || 'Failed to load mobile.de status'); } finally { setLoading(false); } }, [vehicleId]); useEffect(() => { fetchStatus(); }, [fetchStatus]); const handlePush = async () => { setPushing(true); setError(null); try { await pushToMobileDe(vehicleId); await fetchStatus(); } catch (err: unknown) { const apiErr = err as { error?: { message?: string } }; setError(apiErr?.error?.message || 'Failed to push to mobile.de'); } finally { setPushing(false); } }; const syncStatus = status?.sync_status || 'pending'; const statusStyle = STATUS_STYLES[syncStatus] || 'bg-gray-100 text-gray-800'; const statusLabel = STATUS_LABELS[syncStatus] || syncStatus; return (

mobile.de Status

{loading ? (
Loading status...
) : error ? (
{error}
) : status ? (
Sync Status: {statusLabel}
Synced
{status.synced ? 'Yes' : 'No'}
Ad ID
{status.ad_id || '—'}
Synced At
{status.synced_at ? new Date(status.synced_at).toLocaleString('de-DE') : '—'}
{status.error_log && (
Error: {status.error_log}
)}
) : null}
); }