import React, { useState, useEffect, useRef } from "react"; import { Box, VStack, HStack, Text, Textarea, IconButton, Image } from "@chakra-ui/react"; import { InputFieldProps } from "~/components/types"; import ArrowLeftIcon from "~/assets/icons/arrow-left.svg"; import AiRainbowIcon from "~/assets/icons/ai-rainbow.svg"; const ChatOnlyInputField: React.FC = ({ placeholder = "Write a prompt or paste a contract address", value = "", onChange, onSend }) => { const [inputValue, setInputValue] = useState(value); const [isExpanded, setIsExpanded] = useState(false); const textareaRef = useRef(null); const handleContainerClick = () => { setIsExpanded(true); setTimeout(() => { if (textareaRef.current) { textareaRef.current.focus(); const length = textareaRef.current.value.length; textareaRef.current.setSelectionRange(length, length); } }, 100); }; useEffect(() => { setInputValue(removeSpaces(value)); }, [value]); const handleInputChange = (newValue: string) => { const trimmedValue = removeSpaces(newValue); setInputValue(trimmedValue); onChange?.(trimmedValue); }; const handleSend = () => { if (inputValue.trim()) { onSend?.({ message: inputValue.trim() }); setInputValue(""); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey && !e.repeat) { e.preventDefault(); handleSend(); } }; const addSpaces = (text: string) => ` ${text}`; const removeSpaces = (text: string) => text.trimStart(); return ( AI {placeholder} { e.stopPropagation(); handleSend(); }} _hover={{ bg: "gray.800" }} disabled={!inputValue.trim()} transition="all 0.4s cubic-bezier(0.4, 0, 0.2, 1)" _disabled={{ bg: "#CCCCCC", cursor: "not-allowed" }} transform="scale(1)" zIndex={2} > Send