import { ChevronDown, Eye, EyeOff, Key, Lock, User } from "lucide-react"; import React, { useState } from "react"; import { cn } from "../lib/utils"; import { Host, SSHKey } from "../types"; import { DistroAvatar } from "./DistroAvatar"; import { Button } from "./ui/button"; import { Input } from "./ui/input"; import { Label } from "./ui/label"; import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover"; import { ScrollArea } from "./ui/scroll-area"; interface AuthDialogProps { host: Host; keys: SSHKey[]; onSubmit: (auth: { username: string; authMethod: "password" | "key"; password?: string; keyId?: string; saveCredentials: boolean; }) => void; onCancel: () => void; } const AuthDialog: React.FC = ({ host, keys, onSubmit, onCancel, }) => { const [username, setUsername] = useState(host.username || "root"); const [authMethod, setAuthMethod] = useState<"password" | "key">("password"); const [password, setPassword] = useState(""); const [selectedKeyId, setSelectedKeyId] = useState(null); const [showPassword, setShowPassword] = useState(false); const [saveCredentials, setSaveCredentials] = useState(true); const [isKeySelectOpen, setIsKeySelectOpen] = useState(false); const _selectedKey = keys.find((k) => k.id === selectedKeyId); const handleSubmit = () => { onSubmit({ username, authMethod, password: authMethod === "password" ? password : undefined, keyId: authMethod === "key" ? (selectedKeyId ?? undefined) : undefined, saveCredentials, }); }; const isValid = username.trim() && ((authMethod === "password" && password.trim()) || (authMethod === "key" && selectedKeyId)); return (
{/* Header */}

{host.label}

SSH {host.hostname}:{host.port || 22}

{/* Progress indicator */}
{authMethod === "password" ? ( ) : ( )}
{">_"}
{/* Auth method tabs */}
{/* Form */}
{/* Username field (shown when no username on host) */} {!host.username && (
setUsername(e.target.value)} placeholder="root" autoFocus />
)} {/* Password field */} {authMethod === "password" && (
setPassword(e.target.value)} placeholder="Enter password" className="pr-10" autoFocus={!!host.username} onKeyDown={(e) => { if (e.key === "Enter" && isValid) { handleSubmit(); } }} />
)} {/* Key selection */} {authMethod === "key" && (
{keys.length === 0 ? (
No keys available. Add keys in the Keychain section.
) : (
{keys .filter((k) => k.category === "key") .slice(0, 5) .map((key) => ( ))} {keys.filter((k) => k.category === "key").length > 5 && (
{keys .filter((k) => k.category === "key") .map((key) => ( ))}
)}
)}
)}
{/* Footer */}
); }; export default AuthDialog;