// File: frontend/components/ai/ai-chat-input.tsx // Change Log: // - 2026-05-19: สร้างคอมโพเนนต์สำหรับรับข้อมูลข้อความ (Chat Input) 'use client'; import { useState, useRef, useEffect } from 'react'; import { Send, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; interface AiChatInputProps { onSend: (text: string) => void; isLoading: boolean; } export function AiChatInput({ onSend, isLoading }: AiChatInputProps) { const [value, setValue] = useState(''); const textareaRef = useRef(null); const handleSubmit = () => { const trimmed = value.trim(); if (trimmed && !isLoading) { onSend(trimmed); setValue(''); } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit(); } }; useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${Math.min(textareaRef.current.scrollHeight, 120)}px`; } }, [value]); return (