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 (