import { useState } from 'react'; import { Link } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { Stethoscope, Plus, Search, Filter, CheckCircle2, XCircle, AlertTriangle, Loader2, AlertCircle, Truck, Calendar, Cpu, Gauge, Cog, Eye, } from 'lucide-react'; import { diagnosticsApi } from '../services/api/diagnostics'; import type { Diagnostic, DiagnosticResult, DiagnosticFilters } from '../services/api/diagnostics'; import type { DiagnosticType } from '../types'; const DIAGNOSTIC_TYPES: { value: DiagnosticType; label: string; icon: typeof Cpu }[] = [ { value: 'obd_scanner', label: 'Scanner OBD', icon: Cpu }, { value: 'injector_bench', label: 'Banco Inyectores', icon: Gauge }, { value: 'pump_bench', label: 'Banco Bomba', icon: Cog }, { value: 'measurements', label: 'Mediciones', icon: Stethoscope }, ]; const RESULT_CONFIG: Record = { pass: { label: 'Aprobado', color: 'bg-green-100 text-green-700', icon: CheckCircle2 }, fail: { label: 'Fallo', color: 'bg-red-100 text-red-700', icon: XCircle }, needs_attention: { label: 'Requiere Atencion', color: 'bg-yellow-100 text-yellow-700', icon: AlertTriangle }, }; export function DiagnosticsPage() { const [filters, setFilters] = useState({ page: 1, pageSize: 20 }); const [searchTerm, setSearchTerm] = useState(''); // Fetch diagnostics const { data, isLoading, error } = useQuery({ queryKey: ['diagnostics', filters], queryFn: () => diagnosticsApi.list(filters), }); const diagnostics = data?.data?.data || []; const handleSearch = () => { setFilters({ ...filters, search: searchTerm, page: 1 }); }; const handleTypeFilter = (type: DiagnosticType | undefined) => { setFilters({ ...filters, diagnostic_type: type, page: 1 }); }; return (
{/* Header */}

Diagnosticos

Pruebas y analisis de vehiculos

Nuevo Diagnostico
{/* Type Filters */}
{DIAGNOSTIC_TYPES.map((type) => { const Icon = type.icon; return ( ); })}
{/* Search & Filters */}
setSearchTerm(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && handleSearch()} className="w-full rounded-lg border border-gray-300 py-2 pl-10 pr-4 text-sm focus:border-diesel-500 focus:outline-none focus:ring-1 focus:ring-diesel-500" />
{/* Table */}
{isLoading ? (
) : error ? (

Error al cargar diagnosticos

) : diagnostics.length === 0 ? (

No hay diagnosticos registrados

Realizar primer diagnostico
) : ( {diagnostics.map((diagnostic: Diagnostic) => { const typeConfig = DIAGNOSTIC_TYPES.find(t => t.value === diagnostic.diagnostic_type); const TypeIcon = typeConfig?.icon || Stethoscope; const resultConfig = diagnostic.result ? RESULT_CONFIG[diagnostic.result] : null; const ResultIcon = resultConfig?.icon; return ( ); })}
Vehiculo Tipo Resultado Orden Fecha Acciones

{diagnostic.vehicle_info}

{diagnostic.customer_name}

{typeConfig?.label || diagnostic.diagnostic_type}
{resultConfig ? ( {ResultIcon && } {resultConfig.label} ) : ( Pendiente )} {diagnostic.order_number ? ( {diagnostic.order_number} ) : ( - )}
{new Date(diagnostic.performed_at).toLocaleDateString('es-MX', { day: '2-digit', month: 'short', year: 'numeric', })}
)} {/* Pagination */} {data?.data && diagnostics.length > 0 && (
Pagina {data.data.page} de {data.data.totalPages}
)}
); }