import React, { useCallback, useRef, useState } from "react"; import { Keyboard, Pressable, Text, TextInput, View, } from "react-native"; import * as Haptics from "expo-haptics"; import { VoiceButton } from "./VoiceButton"; import { useTheme } from "../../contexts/ThemeContext"; interface InputBarProps { onSendText: (text: string) => void; onVoiceRecorded: (uri: string, durationMs?: number) => void; onReplay: () => void; isTextMode: boolean; onToggleMode: () => void; audioPlaying?: boolean; } export function InputBar({ onSendText, onVoiceRecorded, onReplay, isTextMode, onToggleMode, audioPlaying = false, }: InputBarProps) { const [text, setText] = useState(""); const inputRef = useRef(null); const { colors } = useTheme(); const canSend = !!text.trim(); const handleSend = useCallback(() => { const trimmed = text.trim(); if (!trimmed) return; onSendText(trimmed); setText(""); Keyboard.dismiss(); }, [text, onSendText]); if (!isTextMode) { // Voice mode: [Replay] [Talk] [Aa] return ( {/* Replay / Stop */} { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); onReplay(); }} > {audioPlaying ? "\u23F8" : "\u25B6"} {audioPlaying ? "Stop" : "Replay"} {/* Talk button */} {/* Text mode toggle */} { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); onToggleMode(); setTimeout(() => inputRef.current?.focus(), 150); }} > Aa ); } // Text mode: [Mic] [TextInput] [Send] return ( {/* Voice mode toggle */} { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); Keyboard.dismiss(); onToggleMode(); }} style={{ width: 40, height: 40, borderRadius: 20, alignItems: "center", justifyContent: "center", backgroundColor: colors.bgTertiary, marginBottom: 2, }} > {"\uD83C\uDFA4"} {/* Text input */} {/* Send button */} {"\u2191"} ); }