import React, { useState, useRef } from "react"; import { View, TextInput, TouchableOpacity, Text, StyleSheet, Keyboard, } from "react-native"; import type { OperoChatInputProps } from "../types"; import { mergeStyles } from "../utils/helpers"; export const OperoChatInput: React.FC = ({ onSend, placeholder = "Type your message...", disabled = false, customStyles, }) => { const [message, setMessage] = useState(""); const [inputHeight, setInputHeight] = useState(44); const inputRef = useRef(null); const styles = createStyles(mergeStyles(customStyles)); const handleSend = () => { const trimmedMessage = message.trim(); if (trimmedMessage && !disabled) { onSend(trimmedMessage); setMessage(""); setInputHeight(44); Keyboard.dismiss(); } }; const handleKeyPress = (e: any) => { if (e.nativeEvent.key === "Enter" && !e.nativeEvent.shiftKey) { e.preventDefault(); handleSend(); } }; const handleContentSizeChange = (event: any) => { const height = Math.min( Math.max(event.nativeEvent.contentSize.height, 44), 120, ); setInputHeight(height); }; const isSendDisabled = !message.trim() || disabled; return ( Send ); }; const createStyles = (theme: any) => StyleSheet.create({ container: { flexDirection: "row", alignItems: "flex-end", paddingHorizontal: 20, paddingVertical: 16, borderTopWidth: 1, borderTopColor: "#e5e7eb", backgroundColor: "#ffffff", }, inputContainer: { flex: 1, marginRight: 12, }, input: { borderWidth: 1, borderColor: "#e5e7eb", borderRadius: theme.borderRadius || 8, paddingHorizontal: 16, paddingVertical: 12, fontSize: theme.fontSize || 16, color: theme.textColor || "#1f2937", backgroundColor: "#ffffff", textAlignVertical: "top", }, sendButton: { backgroundColor: theme.primaryColor || "#3b82f6", paddingHorizontal: 16, paddingVertical: 12, borderRadius: theme.borderRadius || 8, minWidth: 60, alignItems: "center", }, sendButtonDisabled: { backgroundColor: "#9ca3af", }, sendButtonText: { color: "#ffffff", fontSize: 16, fontWeight: "600", }, sendButtonTextDisabled: { color: "#6b7280", }, });