"use client"; import { useRef, useEffect } from "react"; import { Group } from "@/lib/api"; import { useTranslation } from "@/lib/i18n"; interface GroupSelectorProps { groups: Group[]; selected: string | null; onSelect: (id: string | null) => void; } export default function GroupSelector({ groups, selected, onSelect, }: GroupSelectorProps) { const scrollRef = useRef(null); const activeRef = useRef(null); const { t } = useTranslation(); // Scroll active button into view useEffect(() => { if (activeRef.current && scrollRef.current) { const container = scrollRef.current; const btn = activeRef.current; const containerRect = container.getBoundingClientRect(); const btnRect = btn.getBoundingClientRect(); if (btnRect.left < containerRect.left || btnRect.right > containerRect.right) { btn.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center" }); } } }, [selected]); return (
{groups.map((g) => ( ))}
); }