import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import { Box, FolderSearch, Server } from "lucide-react"; import { Input } from "@/components/input"; import { SectionCard, SettingRow, FakeSwitch } from "@/components/section-card"; import { getCredentials } from "@/main-axios"; import type { HostEditorForm } from "./HostEditorData"; type SetHostField = ( key: K, value: HostEditorForm[K], ) => void; export function HostDockerTab({ form, setField, }: { form: HostEditorForm; setField: SetHostField; }) { const { t } = useTranslation(); const dockerConfig = form.dockerConfig ?? { runtime: "docker" as const }; const runtime = dockerConfig.runtime === "podman" ? ("podman" as const) : ("docker" as const); return ( } >
setField("enableDocker", v)} /> {form.enableDocker && ( )}
); } export function HostProxmoxTab({ form, setField, }: { form: HostEditorForm; setField: SetHostField; }) { const { t } = useTranslation(); const [credentials, setCredentials] = useState< { id: number; name: string; username: string | null }[] >([]); useEffect(() => { getCredentials() .then((res: unknown) => { const raw = (res as { credentials?: unknown })?.credentials ?? res ?? []; const list = (Array.isArray(raw) ? raw : []).map( (c: Record) => ({ id: c.id as number, name: c.name as string, username: (c.username as string | null) ?? null, }), ); setCredentials(list); }) .catch(() => {}); }, []); const cfg = form.proxmoxConfig ?? { defaultCredentialId: null, defaultAuthType: "password", windowsPatterns: "win, windows", dockerPatterns: "docker", preferredPrefixes: "10., 192.168.", autoSyncEnabled: false, syncIntervalMinutes: 15, markMissingGuests: true, }; const lastSyncResult = cfg.lastSyncResult; const lastSyncSummary = lastSyncResult ? t("hosts.proxmoxLastSyncSummary", { created: lastSyncResult.created, updated: lastSyncResult.updated, markedMissing: lastSyncResult.markedMissing, skipped: lastSyncResult.skipped, }) : t("hosts.proxmoxLastSyncNoResult"); const lastSyncDescription = cfg.lastSyncAt ? `${new Date(cfg.lastSyncAt).toLocaleString()} ยท ${lastSyncSummary}` : t("hosts.proxmoxLastSyncNever"); return ( } >
{t("hosts.enableProxmoxDesc")}{" "} {t("hosts.docsLink")} } > setField("enableProxmox", v)} /> {form.enableProxmox && ( <> setField("proxmoxConfig", { ...cfg, windowsPatterns: e.target.value, }) } placeholder="win, windows" /> setField("proxmoxConfig", { ...cfg, dockerPatterns: e.target.value, }) } placeholder="docker" /> setField("proxmoxConfig", { ...cfg, preferredPrefixes: e.target.value, }) } placeholder="10., 192.168." /> setField("proxmoxConfig", { ...cfg, autoSyncEnabled: v, }) } /> setField("proxmoxConfig", { ...cfg, syncIntervalMinutes: Math.max( 5, Number.parseInt(e.target.value || "15", 10), ), }) } /> setField("proxmoxConfig", { ...cfg, markMissingGuests: v, }) } /> {cfg.lastSyncStatus ? t(`hosts.proxmoxLastSyncStatus.${cfg.lastSyncStatus}`) : t("hosts.proxmoxLastSyncStatus.pending")} )}
); } export function HostFilesTab({ form, setField, }: { form: HostEditorForm; setField: SetHostField; }) { const { t } = useTranslation(); return ( } >
setField("enableFileManager", v)} /> setField("scpLegacy", v)} />
setField("defaultPath", e.target.value)} /> {t("hosts.fileManagerPathHint")}
); }