import { useState } from 'react' import { useGitStatus } from '@/api/git' import { Loader2, FileText, FilePlus, FileX, FileEdit, File, ChevronRight, ArrowUp, ArrowDown } from 'lucide-react' import { cn } from '@/lib/utils' import type { GitFileStatus, GitFileStatusType } from '@/types/git' interface GitChangesPanelProps { repoId: number onFileSelect: (path: string) => void selectedFile?: string } const statusConfig: Record = { modified: { icon: FileEdit, color: 'text-yellow-500', label: 'Modified' }, added: { icon: FilePlus, color: 'text-green-500', label: 'Added' }, deleted: { icon: FileX, color: 'text-red-500', label: 'Deleted' }, renamed: { icon: FileText, color: 'text-blue-500', label: 'Renamed' }, untracked: { icon: File, color: 'text-muted-foreground', label: 'Untracked' }, copied: { icon: FileText, color: 'text-purple-500', label: 'Copied' }, } function FileStatusItem({ file, isSelected, onClick }: { file: GitFileStatus; isSelected: boolean; onClick: () => void }) { const config = statusConfig[file.status] const Icon = config.icon const fileName = file.path.split('/').pop() || file.path const dirPath = file.path.includes('/') ? file.path.substring(0, file.path.lastIndexOf('/')) : '' return ( ) } export function GitChangesPanel({ repoId, onFileSelect, selectedFile }: GitChangesPanelProps) { const { data: status, isLoading, error } = useGitStatus(repoId) const [filter, setFilter] = useState('all') if (isLoading) { return (
) } if (error) { return (

Failed to load git status

{error.message}

) } if (!status || !status.hasChanges) { return (

No uncommitted changes

) } const filteredFiles = filter === 'all' ? status.files : status.files.filter(f => f.status === filter) const statusCounts = status.files.reduce((acc, file) => { acc[file.status] = (acc[file.status] || 0) + 1 return acc }, {} as Record) return (
{status.branch}
{status.ahead > 0 && ( {status.ahead} )} {status.behind > 0 && ( {status.behind} )}
{Object.entries(statusCounts).map(([statusKey, count]) => { const config = statusConfig[statusKey as GitFileStatusType] return ( ) })}
{filteredFiles.map((file) => ( onFileSelect(file.path)} /> ))}
) }