/// file: public/assets/js/modules/parallax.js

export function initParallax() {
  const hero = document.querySelector('.hero');
  if (!hero || hero.hasAttribute('data-home-touch-root')) return;
  if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
  if (window.matchMedia('(max-width: 768px)').matches) return;
  const title = hero.querySelector('.hero__title');
  window.addEventListener(
    'pointermove',
    (e) => {
      const cx = window.innerWidth / 2;
      const cy = window.innerHeight / 2;
      const dx = (e.clientX - cx) / cx;
      const dy = (e.clientY - cy) / cy;
      hero.style.transform = `translate3d(${dx * 6}px, ${dy * 4}px, 0)`;
      if (title) title.style.transform = `translate3d(${dx * -4}px, ${dy * -3}px, 0)`;
    },
    { passive: true }
  );
}
