import { useRef, useState } from 'react'; import { LoaderCircle } from 'lucide-react'; import { RepositoryBranchSelect, type RepositoryBranch } from '@/components/RepositoryBranchSelect'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'; /** Presentational branch repair. The caller owns branch discovery and saving. */ export function SkillSourceBranchRepairDialog({ repository, currentBranch, branches, loading, loadError, onRetry, onSave, onClose, onReturnFocus }: { repository: string; currentBranch: string; branches: readonly RepositoryBranch[]; loading?: boolean; loadError?: string | null; onRetry?: () => void; onSave: (branch: string) => Promise; onClose: () => void; onReturnFocus?: () => void; }) { const [branch, setBranch] = useState(''); const [pending, setPending] = useState(false); const [error, setError] = useState(null); const title = useRef(null); async function save() { setPending(true); setError(null); try { await onSave(branch); onClose(); } catch (problem) { setError(problem instanceof Error ? problem.message : 'Could not change the branch. Try again.'); } finally { setPending(false); } } return { if (!open && !pending) onClose(); }}> { event.preventDefault(); title.current?.focus(); }} onCloseAutoFocus={event => { if (onReturnFocus) { event.preventDefault(); onReturnFocus(); } }}> Choose a new branch {repository} · Currently tracking {currentBranch === 'HEAD' ? 'the default branch' : currentBranch}
{ event.preventDefault(); if (branch && !pending) void save(); }}> { setBranch(value); setError(null); }} onRetry={onRetry} /> {error &&

{error}

}
; }