import React, { useCallback, useState } from 'react' import { Box, Text } from '../ink.js' import { getDisplayPath } from '../utils/file.js' import { removePathFromRepo, validateRepoAtPath, } from '../utils/githubRepoPathMapping.js' import { Select } from './CustomSelect/index.js' import { Dialog } from './design-system/Dialog.js' import { Spinner } from './Spinner.js' type Props = { targetRepo: string initialPaths: string[] onSelectPath: (path: string) => void onCancel: () => void } export function TeleportRepoMismatchDialog({ targetRepo, initialPaths, onSelectPath, onCancel, }: Props): React.ReactNode { const [availablePaths, setAvailablePaths] = useState(initialPaths) const [errorMessage, setErrorMessage] = useState(null) const [validating, setValidating] = useState(false) const handleChange = useCallback( async (value: string): Promise => { if (value === 'cancel') { onCancel() return } setValidating(true) setErrorMessage(null) const isValid = await validateRepoAtPath(value, targetRepo) if (isValid) { onSelectPath(value) return } // Path is invalid - remove it from config and update state removePathFromRepo(targetRepo, value) const updatedPaths = availablePaths.filter(p => p !== value) setAvailablePaths(updatedPaths) setValidating(false) setErrorMessage( `${getDisplayPath(value)} no longer contains the correct repository. Select another path.`, ) }, [targetRepo, availablePaths, onSelectPath, onCancel], ) const options = [ ...availablePaths.map(path => ({ label: ( Use {getDisplayPath(path)} ), value: path, })), { label: 'Cancel', value: 'cancel' }, ] return ( {availablePaths.length > 0 ? ( <> {errorMessage && {errorMessage}} Open Claude Code in {targetRepo}: {validating ? ( Validating repository… ) : (