import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useRef, useState } from "react";
import '../resources.css';
const Dynamictext = (props) => {
    const timer = useRef(undefined);
    const [index, setIndex] = useState(Math.round((props.list.length - 1) * Math.random()));
    const [attr, setAttr] = useState({
        opacity: 1,
        scale: 1,
        y: 0
    });
    useEffect(() => {
        if (!timer.current) {
            timer.current = setInterval(() => {
                setTimeout(() => {
                    setAttr({
                        opacity: 0,
                        scale: 1,
                        y: 10
                    });
                }, props.timePeriod - 500);
                setTimeout(() => {
                    setIndex((prevIndex) => prevIndex == props.list.length - 1 ? 0 : prevIndex + 1);
                    setAttr({
                        opacity: 1,
                        scale: 1,
                        y: 0
                    });
                }, props.timePeriod - 250);
            }, props.timePeriod);
        }
        //return clearInterval(timer.current)
    }, []);
    return (_jsx("span", { className: "avamodule-dynamictext", style: { ...props.style, opacity: attr.opacity, transform: "scale(" + attr.scale + ") translateY(" + attr.y + "px)" }, children: props.list[index] }));
};
export default Dynamictext;
//# sourceMappingURL=Dynamictext.js.map