import { Check, GitBranch, Globe, Plus, RefreshCw, Trash2 } from 'lucide-react'; import { useState } from 'react'; import type { ConfirmationRequest, GitRemoteStatus } from '../../types/types'; import NewBranchModal from '../modals/NewBranchModal'; type BranchesViewProps = { isMobile: boolean; isLoading: boolean; currentBranch: string; localBranches: string[]; remoteBranches: string[]; remoteStatus: GitRemoteStatus | null; isCreatingBranch: boolean; onSwitchBranch: (branchName: string) => Promise; onCreateBranch: (branchName: string) => Promise; onDeleteBranch: (branchName: string) => Promise; onRequestConfirmation: (request: ConfirmationRequest) => void; }; // --------------------------------------------------------------------------- // Branch row // --------------------------------------------------------------------------- type BranchRowProps = { name: string; isCurrent: boolean; isRemote: boolean; aheadCount: number; behindCount: number; isMobile: boolean; onSwitch: () => void; onDelete: () => void; }; function BranchRow({ name, isCurrent, isRemote, aheadCount, behindCount, isMobile, onSwitch, onDelete }: BranchRowProps) { return (
{/* Branch icon */}
{isRemote ? : }
{/* Name + pills */}
{name} {isCurrent && ( current )} {isRemote && !isCurrent && ( remote )}
{/* Ahead/behind — only meaningful for the current branch */} {isCurrent && (aheadCount > 0 || behindCount > 0) && (
{aheadCount > 0 && ( ↑{aheadCount} ahead )} {behindCount > 0 && ( ↓{behindCount} behind )}
)}
{/* Actions */}
{isCurrent ? ( ) : !isRemote ? ( <> ) : null}
); } // --------------------------------------------------------------------------- // Section header // --------------------------------------------------------------------------- function SectionHeader({ label, count }: { label: string; count: number }) { return (
{label} {count}
); } // --------------------------------------------------------------------------- // BranchesView // --------------------------------------------------------------------------- export default function BranchesView({ isMobile, isLoading, currentBranch, localBranches, remoteBranches, remoteStatus, isCreatingBranch, onSwitchBranch, onCreateBranch, onDeleteBranch, onRequestConfirmation, }: BranchesViewProps) { const [showNewBranchModal, setShowNewBranchModal] = useState(false); const aheadCount = remoteStatus?.ahead ?? 0; const behindCount = remoteStatus?.behind ?? 0; const requestSwitch = (branch: string) => { onRequestConfirmation({ type: 'commit', // reuse neutral type for switch message: `Switch to branch "${branch}"? Make sure you have no uncommitted changes.`, onConfirm: () => void onSwitchBranch(branch), }); }; const requestDelete = (branch: string) => { onRequestConfirmation({ type: 'deleteBranch', message: `Delete branch "${branch}"? This cannot be undone.`, onConfirm: () => void onDeleteBranch(branch), }); }; if (isLoading && localBranches.length === 0) { return (
); } return (
{/* Create branch button */}
{localBranches.length} local{remoteBranches.length > 0 ? `, ${remoteBranches.length} remote` : ''}
{/* Branch list */}
{localBranches.length > 0 && ( <> {localBranches.map((branch) => ( requestSwitch(branch)} onDelete={() => requestDelete(branch)} /> ))} )} {remoteBranches.length > 0 && ( <> {remoteBranches.map((branch) => ( requestSwitch(branch)} onDelete={() => requestDelete(branch)} /> ))} )} {localBranches.length === 0 && remoteBranches.length === 0 && (

No branches found

)}
setShowNewBranchModal(false)} onCreateBranch={onCreateBranch} />
); }