// components/ui/search-bar.tsx import * as React from 'react'; import { View, Pressable, Platform, TextInput } from 'react-native'; import { Search, X } from 'lucide-react-native'; import { cn } from '@/lib/utils'; import { useThemeColors } from '@/hooks/useThemeColors'; export interface SearchBarProps { value?: string; defaultValue?: string; placeholder?: string; onValueChange?: (value: string) => void; onDebouncedValueChange?: (value: string) => void; debounceDelay?: number; className?: string; disabled?: boolean; } export function SearchBar({ value: controlledValue, defaultValue = '', placeholder = 'Search...', onValueChange, onDebouncedValueChange, debounceDelay = 500, className, disabled = false, }: SearchBarProps) { const { colors } = useThemeColors(); const [internalValue, setInternalValue] = React.useState(defaultValue); const currentValue = controlledValue ?? internalValue; const timerRef = React.useRef(null); const handleChange = (text: string) => { if (controlledValue === undefined) { setInternalValue(text); } onValueChange?.(text); if (onDebouncedValueChange) { if (timerRef.current) clearTimeout(timerRef.current); timerRef.current = setTimeout(() => { onDebouncedValueChange(text); }, debounceDelay); } }; const handleClear = () => { handleChange(''); }; return ( {currentValue.length > 0 && !disabled && ( )} ); }