"use client" import { memo, useCallback, useRef } from "react" import { Reorder } from "motion/react" import { X } from "lucide-react" import { useTranslations } from "next-intl" import { cn } from "@/lib/utils" import { STATUS_COLORS } from "@/lib/types" import type { ConversationStatus } from "@/lib/types" import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger, } from "@/components/ui/context-menu" import type { TabItem as TabItemData } from "@/contexts/tab-context" interface TabItemProps { tab: TabItemData isActive: boolean isTileMode: boolean folderName: string | null folderBranch: string | null onSwitch: (tabId: string) => void onClose: (tabId: string) => void onCloseOthers: (tabId: string) => void onCloseAll: () => void onPin: (tabId: string) => void onToggleTile: () => void } export const TabItem = memo(function TabItem({ tab, isActive, isTileMode, folderName, folderBranch, onSwitch, onClose, onCloseOthers, onCloseAll, onPin, onToggleTile, }: TabItemProps) { const t = useTranslations("Folder.tabs") const isDragging = useRef(false) const itemRef = useRef(null) const resolvedFolderName = folderName ?? String(tab.folderId) const tooltip = folderBranch ? `${resolvedFolderName} · ${folderBranch} — ${tab.title}` : `${resolvedFolderName} — ${tab.title}` const clearResidualStyles = useCallback(() => { const el = itemRef.current if (!el) return el.style.transform = "" el.style.zIndex = "" el.style.position = "" el.style.userSelect = "" }, []) const handleClick = useCallback(() => { if (isDragging.current) return onSwitch(tab.id) }, [onSwitch, tab.id]) const handleDoubleClick = useCallback(() => { if (isDragging.current) return if (!tab.isPinned) { onPin(tab.id) } }, [onPin, tab.id, tab.isPinned]) const handleClose = useCallback(() => { onClose(tab.id) }, [onClose, tab.id]) const handleCloseOthers = useCallback(() => { onCloseOthers(tab.id) }, [onCloseOthers, tab.id]) return ( { isDragging.current = true }} onDragEnd={() => { setTimeout(() => { isDragging.current = false clearResidualStyles() }, 200) }} onLayoutAnimationComplete={clearResidualStyles} className="shrink-0 rounded-full cursor-grab active:cursor-grabbing active:opacity-90 active:shadow-md active:z-50" >
{tab.title}
{t("close")} {t("closeOthers")} {isTileMode ? t("untileDisplay") : t("tileDisplay")} {t("closeAll")}
) })