'use client' import { useEffect, useRef, useState } from 'react' import type { Category } from '@/data/menu' type Props = { categories: Category[] lang: string } export default function BottomTabBar({ categories, lang }: Props) { const l = lang as 'tr' | 'en' const [activeId, setActiveId] = useState(categories[0]?.id ?? '') const scrollRef = useRef(null) /* ── Intersection Observer: aktif kategoriyi takip et ── */ useEffect(() => { const observers: IntersectionObserver[] = [] categories.forEach((cat) => { const el = document.getElementById(cat.id) if (!el) return const observer = new IntersectionObserver( (entries) => { entries.forEach((entry) => { if (entry.isIntersecting) setActiveId(cat.id) }) }, { rootMargin: '-15% 0px -80% 0px', threshold: 0 } ) observer.observe(el) observers.push(observer) }) return () => observers.forEach((o) => o.disconnect()) }, [categories]) /* ── Aktif tab görünüme kaydır ── */ useEffect(() => { if (!scrollRef.current) return const activeEl = scrollRef.current.querySelector( `[data-id="${activeId}"]` ) if (!activeEl) return activeEl.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }) }, [activeId]) return ( ) }