/// file: public/assets/js/modules/text-reveal.js

export function initTextReveal() {
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
  const els = document.querySelectorAll('[data-reveal]');
  if (!els.length || !('IntersectionObserver' in window)) return;
  const io = new IntersectionObserver(
    (entries) => {
      entries.forEach((en) => {
        if (en.isIntersecting) {
          en.target.classList.add('opacity-100', 'translate-y-0');
          en.target.classList.remove('opacity-0', 'translate-y-6');
          io.unobserve(en.target);
        }
      });
    },
    { threshold: 0.2 }
  );
  els.forEach((el) => {
    el.classList.add('opacity-0', 'translate-y-6', 'transition', 'duration-700');
    el.style.transitionTimingFunction = 'cubic-bezier(0.16, 1, 0.3, 1)';
    io.observe(el);
  });
}
