import { useEffect, useRef, useState, type ReactNode } from "react"; import { ChevronDown } from "lucide-react"; import { useTranslation } from "react-i18next"; import { ToggleButton } from "@/components/ui/toggle-button"; import { SettingsGroup, SettingsRow } from "@/components/settings/shared/SettingsControls"; import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; import { Disclosure } from "@/components/ui/disclosure"; export function SettingsAdvancedOptions({ children, initialOpen = false }: { children: ReactNode; initialOpen?: boolean }) { const { t } = useTranslation(); return ( {t("settings.runtimeConfig.advancedOptions")} } >
{children}
); } export function SettingsFeature({ title, enabled, onChange, disabled, initialOpen = false, error, children, onClose, }: { title: string; enabled: boolean; onChange: (enabled: boolean) => void; disabled?: boolean; initialOpen?: boolean; error?: string; children?: ReactNode; onClose?: () => void; }) { const { t } = useTranslation(); const [open, setOpen] = useState(initialOpen && enabled); const section = useRef(null); const opener = useRef(null); const changeOpen = (next: boolean) => { if (next) opener.current = document.activeElement instanceof HTMLElement ? document.activeElement : null; setOpen(next); }; useEffect(() => { if (initialOpen && enabled) { setOpen(true); section.current?.scrollIntoView?.({ block: "nearest" }); } }, [initialOpen, enabled]); return (
{ changeOpen(next); if (!next) onClose?.(); }}> ) : title}> {children ? : null} { changeOpen(next); onChange(next); }} /> {children ? { if (opener.current?.isConnected && !opener.current.matches(":disabled")) { opener.current.focus({ preventScroll: true }); // Saving on close can disable the switch that opened this dialog. // Let Radix restore its Configure trigger if the opener cannot focus. if (document.activeElement === opener.current) event.preventDefault(); } }} className="settings-grid max-h-[85dvh] w-[min(calc(100vw-2rem),40rem)] max-w-none overflow-y-auto p-0 [--settings-surface:var(--background)]"> {title}
{children}
: null}
{error && !open ?

{error}

: null}
); }