ChatInput.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Button } from "@/components/ui/button";
  2. import { Input } from "@/components/ui/input";
  3. import { Send, StopCircle } from "lucide-react";
  4. interface ChatInputProps {
  5. inputMessage: string;
  6. setInputMessage: (message: string) => void;
  7. onSendMessage: () => void;
  8. isLimitReached: boolean;
  9. isLoading: boolean;
  10. chatType: "medical" | "psychological";
  11. onEndConversation?: () => void;
  12. hasMessages?: boolean;
  13. }
  14. export const ChatInput = ({
  15. inputMessage,
  16. setInputMessage,
  17. onSendMessage,
  18. isLimitReached,
  19. isLoading,
  20. chatType,
  21. onEndConversation,
  22. hasMessages = false,
  23. }: ChatInputProps) => {
  24. const handleKeyPress = (e: React.KeyboardEvent) => {
  25. if (e.key === "Enter" && !e.shiftKey) {
  26. e.preventDefault();
  27. onSendMessage();
  28. }
  29. };
  30. const isPsychological = chatType === "psychological";
  31. const placeholder = isPsychological
  32. ? "Comparte lo que tengas en mente..."
  33. : "Describe tu consulta médica aquí...";
  34. return (
  35. <div className="p-6 border-t border-border">
  36. <div className="flex flex-col space-y-3">
  37. <div className="flex space-x-3">
  38. <Input
  39. value={inputMessage}
  40. onChange={(e) => setInputMessage(e.target.value)}
  41. onKeyPress={handleKeyPress}
  42. placeholder={placeholder}
  43. disabled={isLimitReached || isLoading}
  44. className="flex-1 rounded-xl"
  45. />
  46. <Button
  47. onClick={onSendMessage}
  48. disabled={!inputMessage.trim() || isLimitReached || isLoading}
  49. size="icon"
  50. className="rounded-xl"
  51. >
  52. <Send className="w-4 h-4" />
  53. </Button>
  54. </div>
  55. {/* Botón terminar conversación para chat psicológico */}
  56. {isPsychological && hasMessages && onEndConversation && (
  57. <Button
  58. variant="outline"
  59. size="sm"
  60. onClick={onEndConversation}
  61. disabled={isLoading}
  62. className="self-end text-purple-600 hover:text-purple-700 hover:bg-purple-50 dark:text-purple-400 dark:hover:bg-purple-900/20"
  63. >
  64. <StopCircle className="w-4 h-4 mr-2" />
  65. Terminar conversación
  66. </Button>
  67. )}
  68. </div>
  69. </div>
  70. );
  71. };