/******/ (() => { // webpackBootstrap
/*!*******************************************!*\
  !*** ./assets/src/blocks/counter/view.js ***!
  \*******************************************/
document.addEventListener('DOMContentLoaded', () => {
  const counters = document.querySelectorAll('.thim-blocks-counter .counter-number');
  const options = {
    threshold: 0.5
  };
  const formatNumber = num => {
    return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  };
  const startCounter = el => {
    const target = parseInt(el.dataset.number || '0');
    const valueEl = el.querySelector('.counter-value');
    if (!valueEl) return;
    let current = 0;
    const duration = 1000;
    const step = Math.ceil(target / (duration / 16));
    const update = () => {
      current += step;
      if (current >= target) {
        valueEl.textContent = formatNumber(target);
      } else {
        valueEl.textContent = formatNumber(current);
        requestAnimationFrame(update);
      }
    };
    update();
  };
  const observer = new IntersectionObserver((entries, obs) => {
    entries.forEach(entry => {
      if (entry.isIntersecting) {
        const el = entry.target;
        startCounter(el);
        obs.unobserve(el);
      }
    });
  }, options);
  counters.forEach(el => {
    observer.observe(el);
  });
});
/******/ })()
;
//# sourceMappingURL=view.js.map