"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";
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) => 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);
}
};
return (
);
}
function StageButton({
isPending,
staged,
path,
repo,
onStage,
onUnstage,
}: {
isPending: boolean;
staged: boolean;
path: string;
repo?: string;
onStage: (path: string, repo?: string) => void;
onUnstage: (path: string, repo?: string) => void;
}) {
if (isPending) {
return (
);
}
if (staged) {
return (
);
}
return (
);
}
function FileRowActions({
path,
repo,
onDiscard,
onEditFile,
}: {
path: string;
repo?: string;
onDiscard: (path: string, repo?: string) => void;
onEditFile: (path: string) => void;
}) {
return (
Discard changes
Edit
);
}
// --- Bulk action components (used by FileListSection) ---
export function DefaultActionButtons({
actionLabel,
isActionLoading,
onAction,
secondaryActionLabel,
isSecondaryActionLoading,
onSecondaryAction,
}: {
actionLabel: string;
isActionLoading?: boolean;
onAction: () => void;
secondaryActionLabel?: string;
isSecondaryActionLoading?: boolean;
onSecondaryAction?: () => void;
}) {
return (
<>
{onSecondaryAction && secondaryActionLabel && (
)}
>
);
}
export function BulkActionBar({
variant,
selectionCount,
selectedPaths,
onBulkStage,
onBulkUnstage,
onBulkDiscard,
}: {
variant: "unstaged" | "staged";
selectionCount: number;
selectedPaths: Set;
onBulkStage?: (paths: string[]) => void;
onBulkUnstage?: (paths: string[]) => void;
onBulkDiscard?: (paths: string[]) => void;
}) {
const paths = [...selectedPaths];
return (
{selectionCount} selected
{variant === "unstaged" && onBulkStage && (
)}
{variant === "staged" && onBulkUnstage && (
)}
{onBulkDiscard && (
)}
);
}