"use client"; import { useState, useRef, useCallback } from "react"; import { SendHorizontal, Square } from "lucide-react"; import { cn } from "@/lib/utils"; import { useChatStore } from "@/stores/chatStore"; import { getChatbotConfig } from "@/lib/chatbotConfig"; interface ChatInputProps { onSend: (message: string) => void; disabled?: boolean; } export function ChatInput({ onSend, disabled }: ChatInputProps) { const [value, setValue] = useState(""); const textareaRef = useRef(null); const { isSending } = useChatStore(); const [chatbotConfig] = useState(() => getChatbotConfig()); const autoResize = useCallback(() => { const ta = textareaRef.current; if (!ta) return; ta.style.height = "auto"; ta.style.height = Math.min(ta.scrollHeight, 180) + "px"; }, []); function handleChange(e: React.ChangeEvent) { setValue(e.target.value); autoResize(); } function handleKeyDown(e: React.KeyboardEvent) { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSubmit(); } } function handleSubmit() { const trimmed = value.trim(); if (!trimmed || disabled || isSending) return; onSend(trimmed); setValue(""); if (textareaRef.current) { textareaRef.current.style.height = "auto"; } } const isDisabled = disabled || isSending; const isEmpty = !value.trim(); return (