import { useState, useEffect } from "react"; import { api, type ClaudeInstallation } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog"; import { ExternalLink, FileQuestion, Terminal, AlertCircle, Loader2 } from "lucide-react"; import { ClaudeVersionSelector } from "./ClaudeVersionSelector"; import { useTranslation } from "@/hooks/useTranslation"; interface ClaudeBinaryDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onSuccess: () => void; onError: (message: string) => void; } export function ClaudeBinaryDialog({ open, onOpenChange, onSuccess, onError }: ClaudeBinaryDialogProps) { const { t } = useTranslation(); const [selectedInstallation, setSelectedInstallation] = useState(null); const [isValidating, setIsValidating] = useState(false); const [hasInstallations, setHasInstallations] = useState(true); const [checkingInstallations, setCheckingInstallations] = useState(true); useEffect(() => { if (open) { checkInstallations(); } }, [open]); const checkInstallations = async () => { try { setCheckingInstallations(true); const installations = await api.listClaudeInstallations(); setHasInstallations(installations.length > 0); } catch (error) { // If the API call fails, it means no installations found setHasInstallations(false); } finally { setCheckingInstallations(false); } }; const handleSave = async () => { if (!selectedInstallation) { onError(t('pleaseSelectInstallation')); return; } setIsValidating(true); try { await api.setClaudeBinaryPath(selectedInstallation.path); onSuccess(); onOpenChange(false); } catch (error) { console.error("Failed to save Claude binary path:", error); onError(error instanceof Error ? error.message : "Failed to save Claude binary path"); } finally { setIsValidating(false); } }; return ( {t('selectClaudeCodeInstallation')} {checkingInstallations ? (
{t('searchingInstallations')}
) : hasInstallations ? (

{t('multipleInstallationsFound')}

) : ( <>

{t('claudeCodeNotFoundDialog')}

{t('searchedLocations')}: PATH, /usr/local/bin, /opt/homebrew/bin, ~/.nvm/versions/node/*/bin, ~/.claude/local, ~/.local/bin

)} {!checkingInstallations && (

{t('validation.required')}: {t('installationTip')}{" "} npm install -g @claude

)}
{!checkingInstallations && hasInstallations && (
setSelectedInstallation(installation)} selectedPath={null} />
)}
); }