document.addEventListener('DOMContentLoaded', function () {
  function animateValue(id, start, end, duration) {
    const obj = document.getElementById(id);
    const range = end - start;
    const minTimer = 50;
    const stepTime = Math.abs(Math.floor(duration / range));
    const startTime = new Date().getTime();
    const endTime = startTime + duration;
    let timer;

    function run() {
      const now = new Date().getTime();
      const remaining = Math.max((endTime - now) / duration, 0);
      const value = Math.round(end - remaining * range);
      obj.innerHTML = value.toLocaleString();
      if (value === end) {
        clearInterval(timer);
      }
    }

    timer = setInterval(run, Math.max(stepTime, minTimer));
    run();
  }

  // Виклик функції для кожного числа
  animateValue('yearsExperience', 0, 5, 2000);
  animateValue('trustedClients', 0, 100, 2000);
  animateValue('debtsWrittenOff', 0, 50, 2000);
  animateValue('propertySaved', 0, 1000, 2000);
});
