import React from "react";
const Loading = ({ text = "Loading...", type = "spiral-dots", }) => {
    const [animationIndex, setAnimationIndex] = React.useState(0);
    const [intervalId, setIntervalId] = React.useState(null);
    const animationLists = {
        bar: ["|", "/", "-", "\\"],
        bubbles: ["⣾", "⣽", "⣻", "⢿", "⡿", "⣟", "⣯", "⣷"],
        breathe: ["  ()  ", " (  ) ", "(    )", " (  ) "],
        metro: [
            "[    ]",
            "[=   ]",
            "[==  ]",
            "[=== ]",
            "[ ===]",
            "[  ==]",
            "[   =]",
        ],
        "modern-metro": [
            "[▱▱▱▱▱▱▱]",
            "[▰▱▱▱▱▱▱]",
            "[▰▰▱▱▱▱▱]",
            "[▰▰▰▱▱▱▱]",
            "[▰▰▰▰▱▱▱]",
            "[▰▰▰▰▰▱▱]",
            "[▰▰▰▰▰▰▱]",
            "[▰▰▰▰▰▰▰]",
            "[▱▰▰▰▰▰▰]",
            "[▱▱▰▰▰▰▰]",
            "[▱▱▱▰▰▰▰]",
            "[▱▱▱▱▰▰▰]",
            "[▱▱▱▱▱▰▰]",
            "[▱▱▱▱▱▱▰]",
        ],
        vertical: ["▁", "▃", "▄", "▅", "▆", "▇", "▆", "▅", "▄", "▃"],
        horizontal: ["▏", "▎", "▍", "▌", "▋", "▊", "▉", "▊", "▋", "▌", "▍"],
        "semi-circle": ["◐", "◓", "◑", "◒"],
        arrow: ["▹▹▹▹▹", "▸▹▹▹▹", "▹▸▹▹▹", "▹▹▸▹▹", "▹▹▹▸▹", "▹▹▹▹▸"],
        clock: [
            "🕛",
            "🕐",
            "🕑",
            "🕒",
            "🕓",
            "🕔",
            "🕕",
            "🕖",
            "🕗",
            "🕘",
            "🕙",
            "🕚",
        ],
        bounce: [
            "(●     )",
            "( ●    )",
            "(  ●   )",
            "(   ●  )",
            "(    ● )",
            "(     ●)",
            "(    ● )",
            "(   ●  )",
            "(  ●   )",
            "( ●    )",
        ],
        firework: ["⢀", "⠠", "⠐", "⠈", "*", "*", " "],
    };
    React.useEffect(() => {
        const interval = setInterval(() => {
            setAnimationIndex((prev) => {
                if (prev >=
                    animationLists[type].length - 1) {
                    return 0;
                }
                else {
                    return prev + 1;
                }
            });
        }, 100);
        setIntervalId(interval);
        return () => {
            clearInterval(interval);
        };
    }, []);
    return (<>
      <div className="react-terminal__loading">
        <div className="react-terminal__loading-icon">
          {animationLists[type][animationIndex]}
        </div>
        <div className="react-terminal__loading-text">{text}</div>
      </div>
    </>);
};
export default Loading;
