
import TextInputBar from "./TextInputBar";
import VoiceInputBar from "./VoiceInputBar";
import { TAgentDetail } from "@/types/agent";
interface Props {
  agent: TAgentDetail | null;
  // histories: (TMessage|TRobotMessage)[];
  setShowWelcome: (b: boolean) => void;
  enableOutputAudioStream: boolean;
  chatInputActions: {
    handleBeforeSend: () => void;
    handleVoiceError: () => void;
    sendVoiceChatMessage: (message: string) => void;
    sendChatMessage: (message: string) => Promise<void>;
  };
  // InputBar 内部状态
  isVoice: boolean;
  setIsVoice: (isVoice: boolean) => void;
  disabled: boolean;
}

export default ({ agent, enableOutputAudioStream, setShowWelcome, chatInputActions, isVoice, setIsVoice, disabled }: Props) => {
  const {handleBeforeSend, handleVoiceError, sendVoiceChatMessage, sendChatMessage} = chatInputActions;

  const handleTextInputBarSwitch = () => {
    console.log("voice input on");
    setIsVoice(true);
  };
  const handleVoiceInputBarSwitch = () => {
    console.log("voice input off");
    setIsVoice(false);
  };
  

  if (isVoice) {
    console.log(agent)
    // 语音输入
    return (
      <VoiceInputBar
        agentId={agent?.agentId}
        disabled={disabled}
        onSend={sendVoiceChatMessage}
        beforeSend={handleBeforeSend}
        onIconClick={handleVoiceInputBarSwitch}
        onError={handleVoiceError}
      />
    );
  }

  // 文本输入
  return (
    <TextInputBar
      disabled={disabled}
      onSend={sendChatMessage}
      onIconClick={handleTextInputBarSwitch}
    ></TextInputBar>
  );
};
