import { useEffect, useState } from "react"; import { useSshAuthTypes, useTranslation } from "@termix/plugin-sdk/frontend"; import { Server } from "lucide-react"; import { FakeSwitch, Input, SectionCard, Select2, SettingRow, } from "@termix/plugin-sdk/ui"; import { listCredentials } from "@termix/plugin-sdk/frontend"; import type { ProxmoxHostConfig } from "./types"; interface HostProxmoxForm { enableProxmox: boolean; proxmoxConfig: ProxmoxHostConfig | null; } type SetHostField = (key: string, value: unknown) => void; export function HostProxmoxTab({ form, setField, }: { form: HostProxmoxForm; setField: SetHostField; }) { const { t } = useTranslation(); const sshAuthTypes = useSshAuthTypes(); const [credentials, setCredentials] = useState< { id: number; name: string; username: string | null }[] >([]); useEffect(() => { listCredentials() .then((list) => setCredentials( list.map((c) => ({ id: c.id, name: c.name, username: c.username ?? null, })), ), ) .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, defaultAuthType: e.target.value, }) } className="h-7 w-44 text-xs border border-border bg-background px-2 outline-none focus:ring-1 focus:ring-ring" > {sshAuthTypes.types.map((option) => ( ))} setField("proxmoxConfig", { ...cfg, defaultCredentialId: e.target.value ? Number(e.target.value) : null, }) } className="h-7 w-44 text-xs border border-border bg-background px-2 outline-none focus:ring-1 focus:ring-ring" > {credentials.map((c) => ( ))} 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")} )}
); }