import { Box, Text, useInput } from "ink"; import type { UnifiedRepo, DirectoryConfig } from "../types/index.ts"; export interface CloneDialogProps { repos: UnifiedRepo[]; directories: DirectoryConfig[]; selectedDirIndex: number; useSSH: boolean; onConfirm: (targetDir: string, useSSH: boolean) => void; onCancel: () => void; onSelectDir: (index: number) => void; onToggleSSH: () => void; } export function CloneDialog({ repos, directories, selectedDirIndex, useSSH, onConfirm, onCancel, onSelectDir, onToggleSSH, }: CloneDialogProps) { useInput((input, key) => { if (key.escape || input === "n" || input === "N") { onCancel(); return; } if (key.return || input === "y" || input === "Y") { const targetDir = directories[selectedDirIndex]?.path; if (targetDir) { // Expand ~ to home directory const expandedPath = targetDir.replace(/^~/, process.env.HOME || ""); onConfirm(expandedPath, useSSH); } return; } // Navigate directories if (input === "j" || key.downArrow) { const nextIndex = Math.min(selectedDirIndex + 1, directories.length - 1); onSelectDir(nextIndex); return; } if (input === "k" || key.upArrow) { const prevIndex = Math.max(selectedDirIndex - 1, 0); onSelectDir(prevIndex); return; } // Toggle SSH/HTTPS if (input === "p" || input === "P") { onToggleSSH(); return; } }); const maxItems = 5; const displayRepos = repos.slice(0, maxItems); const remainingCount = repos.length - maxItems; return ( {/* Title */} Clone GitHub {repos.length === 1 ? "Repository" : `Repositories (${repos.length})`} {/* Repos to clone */} Repositories to clone: {displayRepos.map((repo) => ( {" ☁ "} {repo.github?.fullName || repo.name} ))} {remainingCount > 0 && ( {" "}...and {remainingCount} more )} {/* Target directory selection */} Target directory (j/k to select): {directories.map((dir, index) => ( {index === selectedDirIndex ? "●" : "○"} {dir.label || dir.path} ({dir.path}) ))} {/* Protocol selection */} Protocol: {useSSH ? "[●]" : "[ ]"} SSH {!useSSH ? "[●]" : "[ ]"} HTTPS (p to toggle) {/* Actions */} Press Enter/y to clone, Esc/n to cancel ); }