import { useState } from 'react'; import * as Menu from '@ariakit/react/menu'; import { ChevronDown, Eye, EyeOff } from 'lucide-react'; import { Input, Label, DropdownPopup } from '@librechat/client'; import type { SearchApiKeyFormData } from '~/hooks/Plugins/useAuthSearchTool'; import type { UseFormRegister } from 'react-hook-form'; import type { MenuItemProps } from '~/common'; import { useLocalize } from '~/hooks'; interface InputConfig { placeholder: string; type?: 'text' | 'password'; link?: { url: string; text: string; }; } interface DropdownOption { key: string; label: string; inputs?: Record; } interface InputSectionProps { title: string; selectedKey: string; onSelectionChange: (key: string) => void; dropdownOptions: DropdownOption[]; showDropdown: boolean; register: UseFormRegister; dropdownOpen: boolean; setDropdownOpen: (open: boolean) => void; dropdownKey: string; } export default function InputSection({ title, selectedKey, onSelectionChange, dropdownOptions, showDropdown, register, dropdownOpen, setDropdownOpen, dropdownKey, }: InputSectionProps) { const localize = useLocalize(); const [passwordVisibility, setPasswordVisibility] = useState>({}); const selectedOption = dropdownOptions.find((opt) => opt.key === selectedKey); const dropdownItems: MenuItemProps[] = dropdownOptions.map((option) => ({ label: option.label, onClick: () => onSelectionChange(option.key), })); const togglePasswordVisibility = (fieldName: string) => { setPasswordVisibility((prev) => ({ ...prev, [fieldName]: !prev[fieldName], })); }; return (
{showDropdown ? ( setDropdownOpen(!dropdownOpen)} className="flex items-center rounded-md border border-border-light px-3 py-1 text-sm text-text-secondary" > {selectedOption?.label} } /> ) : (
{selectedOption?.label}
)}
{selectedOption?.inputs && Object.entries(selectedOption.inputs).map(([name, config], index) => (
(e.target.readOnly = false) : undefined } className={`${index > 0 ? 'mb-2' : 'mb-2'} ${ config.type === 'password' ? 'pr-10' : '' }`} {...register(name as keyof SearchApiKeyFormData)} /> {config.type === 'password' && ( )}
{config.link && ( )}
))}
); } export type { InputConfig, DropdownOption };