(function () { const gallery = document.querySelector('[data-hero-gallery]'); const data = document.getElementById('shop-hero-products'); const controls = gallery?.querySelector('[data-hero-controls]'); if (!data || !controls) return; const products = JSON.parse(data.textContent); const link = gallery.querySelector('[data-hero-link]'); const image = gallery.querySelector('[data-hero-image]'); const title = gallery.querySelector('[data-hero-title]'); const note = gallery.querySelector('[data-hero-note]'); const pause = controls.querySelector('[data-hero-pause]'); const next = controls.querySelector('[data-hero-next]'); const motion = window.matchMedia('(prefers-reduced-motion: reduce)'); let index = 0; let paused = motion.matches; let hovering = false; let timer; let preloaded; function preloadNext() { preloaded = new Image(); preloaded.src = products[(index + 1) % products.length].image; } function schedule() { window.clearTimeout(timer); if (paused || hovering || document.hidden || document.activeElement === link) return; timer = window.setTimeout(advance, 3000); } function advance() { index = (index + 1) % products.length; const product = products[index]; link.href = product.url; image.src = preloaded?.src || product.image; title.textContent = product.name; note.textContent = [product.preview ? 'Yakında' : '', product.sample ? 'Örnek görsel' : ''].filter(Boolean).join(' · '); note.hidden = !note.textContent; preloadNext(); schedule(); } function updatePause() { pause.setAttribute('aria-label', paused ? 'Ürün geçişini başlat' : 'Ürün geçişini duraklat'); pause.title = paused ? 'Başlat' : 'Duraklat'; pause.querySelector('i').className = paused ? 'fas fa-play' : 'fas fa-pause'; schedule(); } gallery.addEventListener('pointerenter', (event) => { if (event.pointerType === 'touch') return; hovering = true; schedule(); }); gallery.addEventListener('pointerleave', () => { hovering = false; schedule(); }); link.addEventListener('focus', schedule); link.addEventListener('blur', () => window.setTimeout(schedule, 0)); pause.addEventListener('click', () => { paused = !paused; updatePause(); }); next.addEventListener('click', advance); document.addEventListener('visibilitychange', schedule); motion.addEventListener('change', () => { paused = motion.matches; updatePause(); }); controls.hidden = false; preloadNext(); updatePause(); })();