import React from "react"; import { AlertTriangle, ChevronDown, ChevronUp, Forward, Globe, HeartPulse, Link2, Palette, Plus, Router, ShieldAlert, TerminalSquare, Wifi, X, Variable } from "lucide-react"; import { customThemeStore } from "../application/state/customThemeStore"; import { clearHostFontSizeOverride, clearHostThemeOverride } from "../domain/terminalAppearance"; import { MAX_FONT_SIZE, MIN_FONT_SIZE } from "../infrastructure/config/fonts"; import { AlgorithmOverridesPanel } from "./host-details/AlgorithmOverridesPanel"; import { Badge } from "./ui/badge"; import { Button } from "./ui/button"; import { HostDetailsSection, HostDetailsSettingRow } from "./host-details"; import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "./ui/collapsible"; import { Input } from "./ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./ui/select"; import { Switch } from "./ui/switch"; import { Textarea } from "./ui/textarea"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "./ui/tooltip"; // eslint-disable-next-line @typescript-eslint/no-explicit-any type HostDetailsAdvancedSectionsProps = Record; const ToggleRow: React.FC<{ label: string; hint?: React.ReactNode; enabled: boolean; onToggle: () => void }> = ({ label, hint, enabled, onToggle }) => { return ( onToggle()} /> ); }; export const HostDetailsAdvancedSections: React.FC = ({ t, form, setForm, update, effectiveThemeId, hasEffectiveThemeOverride, effectiveFontSize, hasEffectiveFontSizeOverride, sshAgentStatus, effectiveGroupDefaults, showAlgorithmOverrides, setShowAlgorithmOverrides, chainedHosts, setActiveSubPanel, clearHostChain, proxySummaryType, proxySummaryLabel, proxySummaryTooltip, clearProxyConfig, groupDefaults, }) => ( <> } title={t("hostDetails.section.appearance")} > {/* SSH Theme Selection */} {hasEffectiveThemeOverride && ( )} {/* Font Size */}
{ const val = parseInt(e.target.value); if (val >= MIN_FONT_SIZE && val <= MAX_FONT_SIZE) { setForm((prev) => ({ ...prev, fontSize: val, fontSizeOverride: true, })); } }} className="h-8 w-16 text-center" /> pt {hasEffectiveFontSizeOverride && ( )}
} title={t("hostDetails.section.mosh")} > { const enabling = !form.moshEnabled; if (enabling) { setForm(prev => ({ ...prev, moshEnabled: true, etEnabled: false, deviceType: prev.deviceType === 'network' ? undefined : prev.deviceType, x11Forwarding: undefined, })); } else { update("moshEnabled", false); } }} /> } title={t("hostDetails.section.et")} > { const enabling = !form.etEnabled; if (enabling) { setForm(prev => ({ ...prev, etEnabled: true, moshEnabled: false, deviceType: prev.deviceType === 'network' ? undefined : prev.deviceType, x11Forwarding: undefined, })); } else { update("etEnabled", false); } }} /> {form.etEnabled && ( <> { const v = e.target.value.trim(); update("etPort", v === "" ? undefined : Number(v)); }} /> )} {/* Agent Forwarding */} } title={t("hostDetails.section.agentForwarding")} > update("agentForwarding", !form.agentForwarding)} /> {form.agentForwarding && sshAgentStatus && !sshAgentStatus.running && (

{t("hostDetails.agentForwarding.agentNotRunning")}

{t("hostDetails.agentForwarding.agentNotRunningHint")}

)}
{/* X11 Forwarding */} {(!form.protocol || form.protocol === "ssh") && !form.moshEnabled && !form.etEnabled && ( } title={t("hostDetails.section.x11Forwarding")} > update("x11Forwarding", !form.x11Forwarding)} /> )} {/* Network Device Mode — only for SSH hosts without Mosh / ET (serial already uses raw mode) */} {(!form.protocol || form.protocol === 'ssh') && !form.moshEnabled && !form.etEnabled && ( } title={t("hostDetails.section.deviceType")} > update("deviceType", form.deviceType === 'network' ? undefined : 'network')} /> {form.deviceType === 'network' && (

{t("hostDetails.deviceType.warning")}

)}
)} {/* SSH Algorithms */} } title={t("hostDetails.section.sshAlgorithms")} > {/* Display the *effective* value of these toggles (host field falling back to the resolved group default). Without the fallback a host that inherits the flag from its group would show "off" while the runtime applied it anyway, and the toggle's onToggle handler would compute the wrong "next" value from the raw host field. */} update( "legacyAlgorithms", !(form.legacyAlgorithms ?? effectiveGroupDefaults?.legacyAlgorithms), )} /> {(form.legacyAlgorithms ?? effectiveGroupDefaults?.legacyAlgorithms) && (

{t("hostDetails.legacyAlgorithms.warning")}

)} update( "skipEcdsaHostKey", !(form.skipEcdsaHostKey ?? effectiveGroupDefaults?.skipEcdsaHostKey), )} /> update("algorithms", next)} />
{/* Terminal Behavior — input/output key mappings (backspace, etc.) */} } title={t("hostDetails.section.terminalBehavior")} > {/* Per-host keepalive override */} } title={t("hostDetails.section.keepalive")} > { const next = !form.keepaliveOverride; update("keepaliveOverride", next); // Seed sensible per-host defaults the first time the user // turns the override on so the inputs aren't empty. if (next) { if (form.keepaliveInterval == null) update("keepaliveInterval", 0); if (form.keepaliveCountMax == null) update("keepaliveCountMax", 3); } }} /> {form.keepaliveOverride && (
{ const v = parseInt(e.target.value, 10); if (!Number.isFinite(v)) return; if (v < 0 || v > 3600) return; update("keepaliveInterval", v); }} /> { const v = parseInt(e.target.value, 10); if (!Number.isFinite(v)) return; if (v < 1 || v > 100) return; update("keepaliveCountMax", v); }} /> {(form.keepaliveInterval ?? 0) === 0 && (

{t("hostDetails.keepalive.disabledHint")}

)}
)}
{/* Proxy via Hosts (Jump Hosts / ProxyJump) */} } title={t("hostDetails.jumpHosts")} action={ chainedHosts.length > 0 ? ( {t("hostDetails.jumpHosts.hops", { count: chainedHosts.length })} ) : ( {t("hostDetails.jumpHosts.direct")} ) } > {chainedHosts.length > 0 && ( )} {chainedHosts.length === 0 && ( )} {/* Proxy Configuration */} } title={t("hostDetails.proxy")} className="overflow-hidden" > {form.proxyConfig?.host || form.proxyConfig?.command || form.proxyProfileId ? (
) : ( )}
{/* Environment Variables */} } title={t("hostDetails.envVars")} > {(form.environmentVariables?.length || 0) > 0 ? ( ) : ( )} {/* Startup Command */} } title={t("hostDetails.startupCommand")} hint={t("hostDetails.startupCommand.help")} >