import { Plus, X, ChevronDown, ChevronUp, Image as ImageIcon, FileText } from "lucide-react" import { useState } from "react" import { Button } from "../../ui/button" import { TFile, TFolder } from "@/lib/types" import { Popover, PopoverContent, PopoverTrigger, } from "@/components/ui/popover" import { Input } from "@/components/ui/input" import { Socket } from "socket.io-client" interface ContextTab { id: string type: "file" | "code" | "image" name: string content: string sourceFile?: string lineRange?: { start: number end: number } } interface ContextTabsProps { activeFileName: string onAddFile: () => void contextTabs: ContextTab[] onRemoveTab: (id: string) => void isExpanded: boolean onToggleExpand: () => void files?: (TFile | TFolder)[] onFileSelect?: (file: TFile) => void socket: Socket | null } export default function ContextTabs({ onAddFile, contextTabs, onRemoveTab, className, files = [], onFileSelect, }: ContextTabsProps & { className?: string }) { const [previewTab, setPreviewTab] = useState(null) const [searchQuery, setSearchQuery] = useState("") const togglePreview = (tab: ContextTab) => { if (previewTab?.id === tab.id) { setPreviewTab(null) } else { setPreviewTab(tab) } } const handleRemoveTab = (id: string) => { if (previewTab?.id === id) { setPreviewTab(null) } onRemoveTab(id) } const getAllFiles = (items: (TFile | TFolder)[]): TFile[] => { return items.reduce((acc: TFile[], item) => { if (item.type === "file") { acc.push(item) } else { acc.push(...getAllFiles(item.children)) } return acc }, []) } const allFiles = getAllFiles(files) const filteredFiles = allFiles.filter(file => file.name.toLowerCase().includes(searchQuery.toLowerCase()) ) return (
setSearchQuery(e.target.value)} className="mb-2" />
{filteredFiles.map((file) => ( ))}
{contextTabs.length === 0 && (
Add Context
)} {contextTabs.map((tab) => (
togglePreview(tab)} > {tab.type === "image" && } {tab.name}
))}
{/* Preview Section */} {previewTab && (
{previewTab.lineRange && (
Lines {previewTab.lineRange.start}-{previewTab.lineRange.end}
)} {previewTab.type === "image" ? ( {previewTab.name} ) : (
                {previewTab.content}
              
)}
)}
) }