"use client"; import { UseFormReturn } from "react-hook-form"; import { useTranslations } from "next-intl"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Switch } from "@/components/ui/switch"; import { HeadersInput } from "@app/components/HeadersInput"; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@/components/ui/form"; type HealthCheckFormFieldsProps = { form: UseFormReturn; onFieldChange?: (fieldName: string, value: any) => void; showNameField?: boolean; hideEnabledField?: boolean; watchedEnabled?: boolean; watchedMode?: string; }; export function HealthCheckFormFields({ form, onFieldChange, showNameField, hideEnabledField, watchedEnabled, watchedMode }: HealthCheckFormFieldsProps) { const t = useTranslations(); const showFields = hideEnabledField || watchedEnabled; const handleChange = (fieldName: string, value: any, fieldOnChange: (v: any) => void) => { fieldOnChange(value); if (onFieldChange) { onFieldChange(fieldName, value); } }; return ( <> {/* Name */} {showNameField && ( ( {t("standaloneHcNameLabel")} )} /> )} {/* Enable Health Checks */} {!hideEnabledField && ( (
{t("enableHealthChecks")}
handleChange("hcEnabled", value, field.onChange) } />
)} /> )} {showFields && (
{/* Strategy */} ( {t("healthCheckStrategy")} )} /> {/* Connection fields */} {watchedMode === "tcp" ? (
( {t("healthHostname")} handleChange( "hcHostname", e.target.value, (v) => field.onChange(e) ) } /> )} /> ( {t("healthPort")} { const value = e.target.value; handleChange("hcPort", value, field.onChange); }} /> )} />
) : (
( {t("healthScheme")} )} /> ( {t("healthHostname")} handleChange( "hcHostname", e.target.value, (v) => field.onChange(e) ) } /> )} /> ( {t("healthPort")} { const value = e.target.value; handleChange("hcPort", value, field.onChange); }} /> )} />
)} {/* HTTP Method + Timeout (shown when not TCP) */} {watchedMode !== "tcp" && (
( {t("httpMethod")} )} /> ( {t("healthCheckPath")} handleChange( "hcPath", e.target.value, (v) => field.onChange(e) ) } /> )} /> ( {t("timeoutSeconds")} { const value = parseInt(e.target.value); handleChange("hcTimeout", value, field.onChange); }} /> )} />
)} {/* TCP timeout (shown only for TCP) */} {watchedMode === "tcp" && ( ( {t("timeoutSeconds")} { const value = parseInt(e.target.value); handleChange("hcTimeout", value, field.onChange); }} /> )} /> )} {/* Healthy interval + healthy threshold */}
( {t("healthyIntervalSeconds")} { const value = parseInt(e.target.value); handleChange("hcInterval", value, field.onChange); }} /> )} /> ( {t("healthyThreshold")} { const value = parseInt(e.target.value); handleChange( "hcHealthyThreshold", value, field.onChange ); }} /> )} />
{/* Unhealthy interval + unhealthy threshold */}
( {t("unhealthyIntervalSeconds")} { const value = parseInt(e.target.value); handleChange( "hcUnhealthyInterval", value, field.onChange ); }} /> )} /> ( {t("unhealthyThreshold")} { const value = parseInt(e.target.value); handleChange( "hcUnhealthyThreshold", value, field.onChange ); }} /> )} />
{/* HTTP-only fields */} {watchedMode !== "tcp" && ( <> {/* Expected Response Codes + TLS Server Name + Follow Redirects */}
( {t("expectedResponseCodes")} { const val = e.target.value; const value = val ? parseInt(val) : null; handleChange("hcStatus", value, field.onChange); }} /> )} /> ( {t("tlsServerName")} handleChange( "hcTlsServerName", e.target.value, (v) => field.onChange(e) ) } /> )} />
{/* Follow Redirects inline toggle */} ( {t("followRedirects")} handleChange( "hcFollowRedirects", value, field.onChange ) } /> )} /> {/* Custom Headers */} ( {t("customHeaders")} handleChange( "hcHeaders", value, field.onChange ) } rows={4} /> {t("customHeadersDescription")} )} /> )}
)} ); }