"use client";
import { IconGitCommit, IconGitPullRequest, IconCloudUpload } from "@tabler/icons-react";
import { Button } from "@kandev/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip";
import { cn } from "@/lib/utils";
import type { FileInfo } from "@/lib/state/store";
// --- Timeline visual components ---
type ChangedFile = {
path: string;
status: FileInfo["status"];
staged: boolean;
plus: number | undefined;
minus: number | undefined;
oldPath: string | undefined;
};
// --- Timeline section dot colors ---
const DOT_COLORS = {
unstaged: "bg-yellow-500",
staged: "bg-emerald-500",
commits: "bg-blue-500",
action: "bg-muted-foreground/25",
} as const;
function TimelineDot({ color }: { color: string }) {
return
;
}
function TimelineSection({
dotColor,
label,
count,
action,
isLast,
children,
}: {
dotColor: string;
label?: string;
count?: number;
action?: React.ReactNode;
isLast?: boolean;
children?: React.ReactNode;
}) {
return (
{/* Vertical line + dot */}
{/* Content */}
{/* Header */}
{label && (
{label}
{typeof count === "number" && count > 0 && (
({count})
)}
{action}
)}
{/* Children (file list, buttons, etc.) */}
{children}
);
}
// --- Commits section ---
type CommitItem = {
commit_sha: string;
commit_message: string;
insertions: number;
deletions: number;
};
type CommitsSectionProps = {
commits: CommitItem[];
isLast: boolean;
onOpenCommitDetail?: (sha: string) => void;
};
export function CommitsSection({ commits, isLast, onOpenCommitDetail }: CommitsSectionProps) {
return (
{commits.map((commit) => (
- onOpenCommitDetail?.(commit.commit_sha)}
>
{commit.commit_sha.slice(0, 7)}
{commit.commit_message}
+{commit.insertions}{" "}
-{commit.deletions}
))}
);
}
// --- Action buttons section (Create PR / Push) ---
type ActionButtonsSectionProps = {
onOpenPRDialog: () => void;
onPush: () => void;
isLoading: boolean;
aheadCount: number;
};
export function ActionButtonsSection({
onOpenPRDialog,
onPush,
isLoading,
aheadCount,
}: ActionButtonsSectionProps) {
return (
);
}
// --- File list sections (Unstaged / Staged) ---
import { FileRow } from "./changes-panel-file-row";
type FileListSectionProps = {
variant: "unstaged" | "staged";
files: ChangedFile[];
pendingStageFiles: Set;
isLast: boolean;
actionLabel: string;
onAction: () => void;
onOpenDiff: (path: string) => void;
onEditFile: (path: string) => void;
onStage: (path: string) => void;
onUnstage: (path: string) => void;
onDiscard: (path: string) => void;
};
export function FileListSection({
variant,
files,
pendingStageFiles,
isLast,
actionLabel,
onAction,
onOpenDiff,
onEditFile,
onStage,
onUnstage,
onDiscard,
}: FileListSectionProps) {
const dotColor = variant === "unstaged" ? DOT_COLORS.unstaged : DOT_COLORS.staged;
const label = variant === "unstaged" ? "Unstaged" : "Staged";
return (
{actionLabel}
}
>
{files.map((file) => (
))}
);
}
// --- Review progress bar ---
type ReviewProgressBarProps = {
reviewedCount: number;
totalFileCount: number;
onOpenReview?: () => void;
};
export function ReviewProgressBar({
reviewedCount,
totalFileCount,
onOpenReview,
}: ReviewProgressBarProps) {
const progressPercent = totalFileCount > 0 ? (reviewedCount / totalFileCount) * 100 : 0;
if (totalFileCount <= 0) return null;
return (
{reviewedCount}/{totalFileCount} reviewed
{reviewedCount} of {totalFileCount} files reviewed
);
}