import { cn } from "@/lib/utils" import { m } from "framer-motion" import { createRef, useEffect, useRef } from "react" export default function GroupSwitch({ tabs, currentTab, setCurrentTab, }: { tabs: string[] currentTab: string setCurrentTab: (tab: string) => void }) { const customBackgroundImage = (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined const scrollRef = useRef(null) const tagRefs = useRef(tabs.map(() => createRef())) useEffect(() => { const container = scrollRef.current if (!container) return const isOverflowing = container.scrollWidth > container.clientWidth if (!isOverflowing) return const onWheel = (e: WheelEvent) => { e.preventDefault() container.scrollLeft += e.deltaY } container.addEventListener("wheel", onWheel, { passive: false }) return () => { container.removeEventListener("wheel", onWheel) } }, []) useEffect(() => { const savedGroup = sessionStorage.getItem("selectedGroup") if (savedGroup && tabs.includes(savedGroup)) { setCurrentTab(savedGroup) } }, [tabs, setCurrentTab]) useEffect(() => { const currentTagRef = tagRefs.current[tabs.indexOf(currentTab)] if (currentTagRef && currentTagRef.current) { currentTagRef.current.scrollIntoView({ behavior: "smooth", block: "nearest", inline: "center", }) } }, [currentTab]) return (
{tabs.map((tab: string, index: number) => (
setCurrentTab(tab)} className={cn( "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500", currentTab === tab ? "text-black dark:text-white" : "text-stone-400 dark:text-stone-500", )} > {currentTab === tab && ( )}

{tab}

))}
) }