"use client"; import { IconArrowBackUp, IconPlus, IconMinus, IconCheck, IconLoader2, IconPencil, } from "@tabler/icons-react"; import { Button } from "@kandev/ui/button"; import { cn } from "@/lib/utils"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { LineStat } from "@/components/diff-stat"; import type { FileInfo } from "@/lib/state/store"; import { FileStatusIcon } from "./file-status-icon"; import type { OpenDiffOptions } from "./changes-diff-target"; const splitPath = (path: string) => { const lastSlash = path.lastIndexOf("/"); if (lastSlash === -1) return { folder: "", file: path }; return { folder: path.slice(0, lastSlash), file: path.slice(lastSlash + 1), }; }; type ChangedFile = { path: string; status: FileInfo["status"]; staged: boolean; plus: number | undefined; minus: number | undefined; oldPath: string | undefined; /** Multi-repo: name of the repo this file lives in. Empty for single-repo. */ repositoryName?: string; }; type FileRowProps = { file: ChangedFile; isPending: boolean; isSelected?: boolean; onSelect?: (path: string, e: React.MouseEvent) => boolean; onOpenDiff: (path: string, options?: OpenDiffOptions) => void; // Multi-repo: handlers receive the file's repository_name so the per-file // staging op routes to the right git repo. Same-named files (e.g. README.md // in two repos) cannot be disambiguated by path alone. onStage: (path: string, repo?: string) => void; onUnstage: (path: string, repo?: string) => void; onDiscard: (path: string, repo?: string) => void; onEditFile: (path: string) => void; }; export function FileRow({ file, isPending, isSelected, onSelect, onOpenDiff, onStage, onUnstage, onDiscard, onEditFile, }: FileRowProps) { const { folder, file: name } = splitPath(file.path); const handleClick = (e: React.MouseEvent) => { if (e.button === 2) return; const consumed = onSelect?.(file.path, e); if (!consumed) { onOpenDiff(file.path, { source: "uncommitted", repositoryName: file.repositoryName, }); } }; return (