import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { useState, useEffect } from "react";
import "./style.scss";
const ChatLoadingWidget = () => {
    const [progress, setProgress] = useState(20);
    const [counter, setCounter] = useState(1);
    useEffect(() => {
        const updateProgress = () => {
            if (progress < 90) {
                const delay = Math.floor(Math.random() * 4 + 1) * 1000;
                const delayTimeout = setTimeout(() => {
                    setProgress((prevProgress) => Math.min(prevProgress + 1, 90));
                }, delay);
                return () => clearTimeout(delayTimeout);
            }
        };
        updateProgress();
    }, [progress]);
    useEffect(() => {
        const updateCounter = () => {
            const delayTimeout = setTimeout(() => {
                if (counter === 3) {
                    setCounter(1);
                }
                else {
                    setCounter(counter + 1);
                }
            }, 1000);
            return () => clearTimeout(delayTimeout);
        };
        updateCounter();
    }, [counter]);
    const renderDots = (count) => {
        const bulletCharacter = String.fromCharCode(0x2022);
        return bulletCharacter.repeat(count);
    };
    return (_jsx("div", { className: "chatLoadingWidet--Generic", children: _jsxs("p", { children: ["Searching for results -", " ", _jsxs("h2", { children: [progress, "% done ", renderDots(counter)] })] }) }));
};
export default ChatLoadingWidget;
