import { PackageIcon } from "lucide-react"; import { useEffect, useState } from "react"; import { FormProvider, type UseFormReturn } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { FormControl, FormField, FormItem, FormLabel, } from "@/components/ui/form"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import type { PackerConfig } from "@/types/memshell"; import type { MemShellFormSchema } 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 shellType = form.watch("shellType"); const server = form.watch("server"); const { t } = useTranslation("common"); useEffect(() => { const filteredOptions = (packerConfig ?? []).filter((name) => { if (!shellType || shellType === " ") { return true; } if (shellType.startsWith("Agent")) { return name.startsWith("Agent"); } if (server.startsWith("XXL")) { return !name.startsWith("Agent"); } return !name.startsWith("Agent") && !name.toLowerCase().startsWith("xxl"); }); const mappedOptions = filteredOptions.map((name) => { return { name: t(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, server, shellType, t]); return ( {t("packerConfig.title")} {options.length > 0 ? ( ( {t("packerMethod")} {options.map(({ name, value }) => ( {name} ))} )} /> ) : (
{t("loading")}
)} ); }