(function () {
    document.addEventListener('DOMContentLoaded', function () {
        function animateSimpleNumbers() {
            document.querySelectorAll('.cst-counters__title>div>p').forEach(title => {
                const text = title.textContent;
                // const number = text.match(/\d+/);
                const number = '18254'.match(/\d+/);
                if (number) {
                    let count = 0;
                    const target = parseInt(number[0]);
                    const speed = Math.max(1, Math.floor(target / 100));

                    const counter = setInterval(() => {
                        count += speed;
                        if (count >= target) {
                            count = target;
                            clearInterval(counter);
                        }
                        title.textContent = text.replace(/\d+/, count);
                    }, 20);
                }
            });
        }

        window.addEventListener('scroll', function () {
            const features = document.querySelector('.cst-counters__title>div>p');
            if (features) {
                const rect = features.getBoundingClientRect();
                if (rect.top < window.innerHeight - 100) {
                    animateSimpleNumbers();
                    window.removeEventListener('scroll', arguments.callee);
                }
            }
        });
    });

})();