import { useState, type ComponentProps, type Ref } from "react"; import { ChevronDown } from "lucide-react"; import { useTranslation } from "react-i18next"; import { Input } from "@/components/ui/input"; import { changeProxyAddress, changeProxyAuthentication, isProxyUrlReference, splitProxyUrl } from "@/lib/proxy-url"; import { cn } from "@/lib/utils"; type AddressProps = Pick, "id" | "aria-describedby" | "aria-invalid">; export function SharedProxyEditor({ value, onChange, disabled, inputRef, addressProps, stackCredentials = false }: { value: string; onChange: (value: string) => void; disabled?: boolean; inputRef?: Ref; addressProps?: AddressProps; stackCredentials?: boolean; }) { const { t } = useTranslation(); const parts = splitProxyUrl(value); const [expanded, setExpanded] = useState(null); const open = expanded ?? parts.userinfo !== null; const reference = isProxyUrlReference(parts.address); const credentialsDisabled = disabled || !parts.address.trim() || reference; return (
onChange(changeProxyAddress(value, event.target.value))} /> {open ? reference ? (

{t("settings.network.proxyReferenceAuth")}

) : (
) : null}
); }