import React from 'react'; import { Button } from '@/components/ui/button'; import { Icon } from "@/components/icon/Icon"; import type { GitMergeInProgress, GitRebaseInProgress } from '@/lib/api/types'; import { useI18n } from '@/lib/i18n'; interface InProgressOperationBannerProps { mergeInProgress: GitMergeInProgress | null | undefined; rebaseInProgress: GitRebaseInProgress | null | undefined; onContinue: () => Promise; onAbort: () => Promise; onResolveWithAI?: () => void; conflictCount?: number; isLoading?: boolean; } export const InProgressOperationBanner: React.FC = ({ mergeInProgress, rebaseInProgress, onContinue, onAbort, onResolveWithAI, conflictCount = 0, isLoading = false, }) => { const { t } = useI18n(); const [processingAction, setProcessingAction] = React.useState<'continue' | 'abort' | null>(null); // Only show banner if we have actual in-progress operation data const hasMergeInProgress = mergeInProgress && mergeInProgress.head; const hasRebaseInProgress = rebaseInProgress && (rebaseInProgress.headName || rebaseInProgress.onto); const operation = hasMergeInProgress ? 'merge' : hasRebaseInProgress ? 'rebase' : null; if (!operation) { return null; } const handleContinue = async () => { setProcessingAction('continue'); try { await onContinue(); } finally { setProcessingAction(null); } }; const handleAbort = async () => { setProcessingAction('abort'); try { await onAbort(); } finally { setProcessingAction(null); } }; const isProcessing = processingAction !== null; const hasUnresolvedConflicts = conflictCount > 0; const operationLabel = operation === 'merge' ? t('gitView.operation.merge') : t('gitView.operation.rebase'); // Build description let description = ''; if (mergeInProgress) { description = mergeInProgress.message ? t('gitView.operation.mergingMessage', { message: mergeInProgress.message }) : t('gitView.operation.mergeInProgressWithHead', { head: mergeInProgress.head }); } else if (rebaseInProgress) { description = rebaseInProgress.headName ? t('gitView.operation.rebasingOnto', { headName: rebaseInProgress.headName, onto: rebaseInProgress.onto || '' }) : t('gitView.operation.rebaseInProgress'); } const title = !hasUnresolvedConflicts ? t('gitView.operation.inProgressTitle', { operation: operationLabel }) : conflictCount === 1 ? t('gitView.operation.inProgressTitleOneConflict', { operation: operationLabel, count: conflictCount }) : t('gitView.operation.inProgressTitleManyConflicts', { operation: operationLabel, count: conflictCount }); const hint = hasUnresolvedConflicts ? t('gitView.operation.resolveConflictsHint') : t('gitView.operation.readyToContinueHint'); return (

{title}

{description && (

{description}

)}

{hint}

{hasUnresolvedConflicts ? onResolveWithAI && ( ) : ( )}
); };