import { useState, useEffect } from "react";
import { Loader2, Bot, Clock, Wifi, Coffee } from "lucide-react";
interface LoadingState {
message: string;
icon: React.ReactNode;
duration: number; // en segundos
}
const loadingStates: LoadingState[] = [
{
message: "Asistente escribiendo...",
icon: ,
duration: 4
},
{
message: "Analizando tu consulta...",
icon: ,
duration: 4
},
{
message: "Preparando tu respuesta...",
icon: ,
duration: 4
},
{
message: "Casi listo...",
icon: ,
duration: 8
}
];
export const DynamicLoader = () => {
const [currentStateIndex, setCurrentStateIndex] = useState(0);
const [elapsedTime, setElapsedTime] = useState(0);
useEffect(() => {
const interval = setInterval(() => {
setElapsedTime(prev => {
const newTime = prev + 1;
// Calcular el tiempo acumulado hasta el estado actual
let accumulatedTime = 0;
for (let i = 0; i <= currentStateIndex; i++) {
accumulatedTime += loadingStates[i].duration;
}
// Si hemos superado el tiempo del estado actual, cambiar al siguiente
if (newTime >= accumulatedTime && currentStateIndex < loadingStates.length - 1) {
setCurrentStateIndex(prev => prev + 1);
}
return newTime;
});
}, 1000);
return () => clearInterval(interval);
}, [currentStateIndex]);
// Reset cuando el componente se monta
useEffect(() => {
setCurrentStateIndex(0);
setElapsedTime(0);
}, []);
const currentState = loadingStates[currentStateIndex] || loadingStates[0];
return (
{currentState.icon}
{currentState.message}
{elapsedTime > 10 && (
Tiempo transcurrido: {elapsedTime}s
)}
);
};