import { PackageIcon } from "lucide-react"; import { useEffect, useState } from "react"; import { Controller, type UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { FieldLabel } from "@/components/ui/field"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import type { PackerConfig } from "@/types/memshell"; import type { ProbeShellFormSchema } from "@/types/schema"; type Option = { name: string; value: string; }; export default function PackageConfigCard({ packerConfig, form, }: Readonly<{ packerConfig: PackerConfig | undefined; form: UseFormReturn; }>) { const [options, setOptions] = useState>([]); const { t } = useTranslation("common"); useEffect(() => { const filteredOptions = (packerConfig ?? []).filter((name) => { return ( !name.startsWith("Agent") && !name.toLowerCase().startsWith("xxl") && !name.toLowerCase().endsWith("jar") ); }); const mappedOptions = filteredOptions.map((name) => { return { name: name, value: name, }; }); setOptions(mappedOptions); const currentValue = form.getValues("packingMethod"); if ( filteredOptions.length > 0 && (!currentValue || !filteredOptions.includes(currentValue)) ) { form.setValue("packingMethod", filteredOptions[0]); } }, [form, packerConfig]); return ( {t("packerConfig.title")} {options.length > 0 ? ( (
{t("packerMethod")}
{options.map(({ name, value }) => (
{name}
))}
)} /> ) : (
{t("loading")}
)} ); }