import { useState, type ReactNode } from "react"; import { Ionicons } from "@expo/vector-icons"; import { Pressable, TextInput, View, type TextInputProps, } from "react-native"; import { Text } from "@/components/ui/Text"; import { colors, fonts, radii } from "@/lib/theme"; type Props = TextInputProps & { onClear?: () => void; /** Renders as a button instead of an input (home screen → search screen). */ readOnlyPress?: () => void; trailing?: ReactNode; }; export function SearchField({ value, onClear, readOnlyPress, trailing, placeholder = "Search medicine, brand or symptom", ...rest }: Props) { const [focused, setFocused] = useState(false); const body = ( {readOnlyPress ? ( {value || placeholder} ) : ( setFocused(true)} onBlur={() => setFocused(false)} returnKeyType="search" style={{ flex: 1, fontFamily: fonts.regular, fontSize: 14, color: colors.ink, paddingVertical: 0, }} {...rest} /> )} {value && onClear && !readOnlyPress ? ( ) : null} {trailing} ); if (readOnlyPress) { return ( ({ opacity: pressed ? 0.9 : 1 })}> {body} ); } return body; } /** Lime pill action that sits inside the search field (scan entry point). */ export function SearchAction({ icon, label, onPress, }: { icon: keyof typeof Ionicons.glyphMap; label?: string; onPress?: () => void; }) { return ( ({ flexDirection: "row", alignItems: "center", gap: 6, backgroundColor: colors.brand, borderRadius: radii.pill, paddingHorizontal: label ? 14 : 10, height: 40, opacity: pressed ? 0.85 : 1, })} > {label ? ( {label} ) : null} ); }