import { PackageIcon } from "lucide-react"; import { useMemo } from "react"; import { Controller, type UseFormReturn, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { FieldLabel, FieldSet } from "@/components/ui/field"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Spinner } from "@/components/ui/spinner"; import type { PackerConfig } from "@/types/memshell"; import type { MemShellFormSchema } from "@/types/schema"; export default function PackageConfigCard({ packerConfig, form, }: Readonly<{ packerConfig: PackerConfig | undefined; form: UseFormReturn; }>) { const { t } = useTranslation("common"); const shellType = useWatch({ control: form.control, name: "shellType", }); const server = useWatch({ control: form.control, name: "server", }); const options = useMemo(() => { 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"); }); form.setValue("packingMethod", filteredOptions[0]); return filteredOptions.map((name) => ({ name: t(name), value: name, })); }, [packerConfig, shellType, server, t, form]); return ( {t("packerConfig.title")} {options.length > 0 ? ( (
{t("packerMethod")} {options.map(({ name, value }) => (
{name}
))}
)} /> ) : (
{t("loading")}
)}
); }