diff --git a/index.html b/index.html index 638c75b..f8cb439 100644 --- a/index.html +++ b/index.html @@ -430,7 +430,7 @@ }, 300); } - // ========================================== + // ========================================== // CÁLCULO DE ETA (TIEMPO ESTIMADO) INTELIGENTE // ========================================== async function calculateClientETA(serviceId, destAddress) { @@ -470,38 +470,52 @@ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); const km = R * c; - // Tiempo basado directamente en la distancia (sin restar) + // Tiempo total estimado basado en la distancia const totalMins = Math.round((km/35)*60) + 5; - let remainingMins = totalMins; - // Porcentaje visual para la barra animada - let progressPercent = 5; + // Extraemos la hora exacta en la que el técnico pulsó el botón + let startedAt = new Date().getTime(); if (data.location.updated_at) { - const startedAt = new Date(data.location.updated_at).getTime(); - if (!isNaN(startedAt)) { - const diffMins = Math.floor((new Date().getTime() - startedAt) / 60000); - progressPercent = (diffMins / totalMins) * 100; - } + const parsed = new Date(data.location.updated_at).getTime(); + if (!isNaN(parsed)) startedAt = parsed; } - - if (progressPercent > 95) progressPercent = 95; - if (progressPercent < 5) progressPercent = 5; - container.innerHTML = ` -
- Llegada en aprox. ${remainingMins} min -
-+ Llegada en aprox. ${remainingMins} min +
+Saliendo
-A ${km.toFixed(1)} km
-Saliendo
+A ${km.toFixed(1)} km
+El técnico está en camino hacia tu domicilio.
`; }