import { useState, useMemo } from 'react'; import { OptionTypes } from 'librechat-data-provider'; import type { DynamicSettingProps } from 'librechat-data-provider'; import { Label, Switch, HoverCard, HoverCardTrigger } from '~/components/ui'; import { TranslationKeys, useLocalize, useParameterEffects } from '~/hooks'; import { useChatContext } from '~/Providers'; import OptionHover from './OptionHover'; import { ESide } from '~/common'; function DynamicSwitch({ label = '', settingKey, defaultValue, description = '', columnSpan, setOption, optionType, readonly = false, showDefault = false, labelCode = false, descriptionCode = false, conversation, }: DynamicSettingProps) { const localize = useLocalize(); const { preset } = useChatContext(); const [inputValue, setInputValue] = useState(!!(defaultValue as boolean | undefined)); useParameterEffects({ preset, settingKey, defaultValue, conversation, inputValue, setInputValue, preventDelayedUpdate: true, }); const selectedValue = useMemo(() => { if (optionType === OptionTypes.Custom) { // TODO: custom logic, add to payload but not to conversation return inputValue; } return conversation?.[settingKey] ?? defaultValue; }, [conversation, defaultValue, optionType, settingKey, inputValue]); const handleCheckedChange = (checked: boolean) => { if (optionType === OptionTypes.Custom) { // TODO: custom logic, add to payload but not to conversation setInputValue(checked); return; } setOption(settingKey)(checked); }; return (
{description && ( )}
); } export default DynamicSwitch;