import { FormControl, FormDescription, FormField, FormItem, FormLabel, } from "@/components/ui/form.tsx"; import { Input } from "@/components/ui/input.tsx"; import { Switch } from "@/components/ui/switch.tsx"; import { Button } from "@/components/ui/button.tsx"; import { Checkbox } from "@/components/ui/checkbox.tsx"; import { Alert, AlertDescription } from "@/components/ui/alert.tsx"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select.tsx"; import { Plus, X } from "lucide-react"; import type { HostStatisticsTabProps } from "./shared/tab-types"; import { QuickActionItem } from "./shared/QuickActionItem"; export function HostStatisticsTab({ form, statusIntervalUnit, setStatusIntervalUnit, metricsIntervalUnit, setMetricsIntervalUnit, snippets, t, }: HostStatisticsTabProps) { return (
(
{t("hosts.statusCheckEnabled")} {t("hosts.statusCheckEnabledDesc")}
)} /> {form.watch("statsConfig.statusCheckEnabled") && ( { const displayValue = statusIntervalUnit === "minutes" ? Math.round((field.value || 30) / 60) : field.value || 30; const handleIntervalChange = (value: string) => { const numValue = parseInt(value) || 0; const seconds = statusIntervalUnit === "minutes" ? numValue * 60 : numValue; field.onChange(seconds); }; return ( {t("hosts.statusCheckInterval")}
handleIntervalChange(e.target.value)} className="flex-1" />
{t("hosts.statusCheckIntervalDesc")}
); }} /> )}
(
{t("hosts.metricsEnabled")} {t("hosts.metricsEnabledDesc")}
)} /> {form.watch("statsConfig.metricsEnabled") && ( { const displayValue = metricsIntervalUnit === "minutes" ? Math.round((field.value || 30) / 60) : field.value || 30; const handleIntervalChange = (value: string) => { const numValue = parseInt(value) || 0; const seconds = metricsIntervalUnit === "minutes" ? numValue * 60 : numValue; field.onChange(seconds); }; return ( {t("hosts.metricsInterval")}
handleIntervalChange(e.target.value)} className="flex-1" />
{t("hosts.metricsIntervalDesc")}
); }} /> )}
{form.watch("statsConfig.metricsEnabled") && ( <> ( {t("hosts.enabledWidgets")} {t("hosts.enabledWidgetsDesc")}
{( [ "cpu", "memory", "disk", "network", "uptime", "processes", "system", "login_stats", "firewall", ] as const ).map((widget) => (
{ const currentWidgets = field.value || []; if (checked) { field.onChange([...currentWidgets, widget]); } else { field.onChange( currentWidgets.filter((w) => w !== widget), ); } }} />
))}
)} /> )}

{t("hosts.quickActions")}

{t("hosts.quickActionsDescription")} ( {t("hosts.quickActionsList")}
{field.value.map((quickAction, index) => ( { const newQuickActions = [...field.value]; newQuickActions[index] = { name, snippetId, }; field.onChange(newQuickActions); }} onRemove={() => { const newQuickActions = field.value.filter( (_, i) => i !== index, ); field.onChange(newQuickActions); }} t={t} /> ))}
{t("hosts.quickActionsOrder")}
)} />
); }