import { Button } from '@/components/ui/button' import { Plus, Minus, FileText, FilePlus, FileX, FileSearch, CircleDot, RotateCcw } from 'lucide-react' import { cn } from '@/lib/utils' import type { GitFileStatus } from '@/types/git' import { GIT_STATUS_COLORS, GIT_UI_COLORS } from '@/lib/git-status-styles' interface GitFlatFileItemProps { file: GitFileStatus isSelected: boolean onSelect: (path: string, staged: boolean) => void onStage?: (path: string) => void onUnstage?: (path: string) => void onDiscard?: (path: string, staged: boolean) => void } const statusIcons = { modified: FileSearch, added: FilePlus, deleted: FileX, renamed: FileSearch, untracked: CircleDot, copied: FilePlus, } export function GitFlatFileItem({ file, isSelected, onSelect, onStage, onUnstage, onDiscard }: GitFlatFileItemProps) { const StatusIcon = statusIcons[file.status] || FileText const statusColor = GIT_STATUS_COLORS[file.status] || 'text-muted-foreground' const fileName = file.path.split('/').pop() || file.path const dirPath = file.path.includes('/') ? file.path.substring(0, file.path.lastIndexOf('/')) : '' const handleAction = (e: React.MouseEvent) => { e.stopPropagation() if (file.staged && onUnstage) { onUnstage(file.path) } else if (!file.staged && onStage) { onStage(file.path) } } const handleDiscard = (e: React.MouseEvent) => { e.stopPropagation() if (onDiscard) { onDiscard(file.path, file.staged) } } return (
onSelect(file.path, file.staged)} >
{fileName} {dirPath && ( {dirPath} )}
{file.staged && ( staged )} {(file.additions !== undefined || file.deletions !== undefined) && (
{file.additions !== undefined && file.additions > 0 && ( +{file.additions} )} {file.deletions !== undefined && file.deletions > 0 && ( -{file.deletions} )}
)} {(onStage || onUnstage) && ( )} {onDiscard && ( )}
) }