import { useMemo } from 'react'; import { OptionTypes } from 'librechat-data-provider'; import type { DynamicSettingProps } from 'librechat-data-provider'; import { Label, Checkbox, HoverCard, HoverCardTrigger } from '@librechat/client'; import { TranslationKeys, useLocalize, useDebouncedInput, useParameterEffects } from '~/hooks'; import { useChatContext } from '~/Providers'; import OptionHover from './OptionHover'; import { ESide } from '~/common'; function DynamicCheckbox({ label = '', settingKey, defaultValue, description = '', columnSpan, setOption, optionType, readonly = false, showDefault = false, labelCode = false, descriptionCode = false, conversation, }: DynamicSettingProps) { const localize = useLocalize(); const { preset } = useChatContext(); const [setInputValue, inputValue, setLocalValue] = useDebouncedInput({ optionKey: settingKey, initialValue: optionType !== OptionTypes.Custom ? conversation?.[settingKey] : defaultValue, setter: () => ({}), setOption, }); const selectedValue = useMemo(() => { return conversation?.[settingKey] ?? defaultValue; }, [conversation, defaultValue, settingKey]); const handleCheckedChange = (checked: boolean) => { setInputValue(checked); setOption(settingKey)(checked); }; useParameterEffects({ preset, settingKey, defaultValue, conversation, inputValue, setInputValue: setLocalValue, }); return (
{description && ( )}
); } export default DynamicCheckbox;