import { CheckboxField, FormControl, FormField, FormItem, FormLabel, Input, Switch, } from "@marzneshin/common/components"; import { useFormContext, useWatch } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { ProtocolField } from "./protocol"; import { XudpProxy443Field } from "./xudp-proxy-443"; export const MuxSettingsFields = () => { const { t } = useTranslation(); const form = useFormContext(); const mux_settings = useWatch({ name: "mux_settings" }); const protocol = useWatch({ name: "mux_settings.protocol" }); const isMuxCool = protocol === "mux_cool"; const isMuxSettingsDisabled = mux_settings === null; const updateFieldValue = (path: string, value: any) => { form.setValue(path, value === "" ? null : value, { shouldDirty: true, shouldValidate: true, }); }; return ( ( <> {t("page.hosts.mux-settings")} form.setValue( "mux_settings", checked ? { protocol: "mux_cool", mux_cool_settings: { xudp_proxy_443: "reject", }, } : null, ) } /> {!isMuxSettingsDisabled && ( <> {isMuxCool ? (
{[ "concurrency", "xudp_concurrency", ].map((fieldName) => ( ( {t( `${fieldName.replace(/_/g, " ")}`, )} updateFieldValue( `mux_settings.mux_cool_settings.${fieldName}`, e.target .value === "" ? null : Number.parseInt( e .target .value, ), ) } className="w-full" /> )} /> ))}
) : (
{[ "max_connections", "max_streams", "min_streams", ].map((fieldName) => ( ( {t( `${fieldName.replace(/_/g, " ")}`, )} updateFieldValue( `mux_settings.sing_box_mux_settings.${fieldName}`, e .target .value === "" ? null : Number.parseInt( e .target .value, ), ) } className="w-full" /> )} /> ))}
)}
)} )} /> ); };