import type { WsClient } from '../../lib/ws-client';
import { useChat } from '../../hooks/useChat';
import MessageList from './MessageList';
import InputBar from './InputBar';

interface Props {
  ws: WsClient | null;
  onClearContext?: () => void;
  clearContextRef?: React.MutableRefObject<(() => void) | null>;
  whisperEnabled?: boolean;
}

export default function ChatView({ ws, clearContextRef, whisperEnabled }: Props) {
  const { messages, streaming, streamBuffer, tools, sendMessage, stopStreaming, clearContext } = useChat(ws);

  // Expose clearContext to parent via ref
  if (clearContextRef) clearContextRef.current = clearContext;

  return (
    <div className="flex flex-col h-full overflow-hidden">
      <MessageList messages={messages} streaming={streaming} streamBuffer={streamBuffer} tools={tools} />
      <InputBar onSend={sendMessage} onStop={stopStreaming} streaming={streaming} whisperEnabled={whisperEnabled} />
    </div>
  );
}
