import { useTranslation } from 'react-i18next'; import { useRef, useEffect } from 'react'; import { MENU_SECTIONS } from './constants'; import { StarIcon } from './icons'; interface SettingsMobileTabsProps { activeSection: string; setActiveSection: (section: string) => void; favoritesCount: number; } export function SettingsMobileTabs({ activeSection, setActiveSection, favoritesCount, }: SettingsMobileTabsProps) { const { t } = useTranslation(); const scrollRef = useRef(null); const activeRef = useRef(null); // Scroll active tab into view useEffect(() => { if (activeRef.current && scrollRef.current) { const container = scrollRef.current; const activeEl = activeRef.current; const containerRect = container.getBoundingClientRect(); const activeRect = activeEl.getBoundingClientRect(); // Check if active element is not fully visible if (activeRect.left < containerRect.left || activeRect.right > containerRect.right) { activeEl.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }); } } }, [activeSection]); // Flatten all items from all sections const allItems = MENU_SECTIONS.flatMap((section) => section.items); return (
{allItems.map((item) => { const isActive = activeSection === item.id; const hasIcon = item.iconType === 'star'; return ( ); })}
); }