import React, { useState, useCallback, useRef, useEffect } from 'react'; import type { AlchemicalResult, ChatMessage } from '../types'; import { getSocraticResponse } from '../services/hermeticEngine'; import Spinner from './ui/Spinner'; type Tab = 'mirror' | 'quintessence' | 'dialogue'; interface Props { result: AlchemicalResult; } const TabButton: React.FC<{ active: boolean; onClick: () => void; children: React.ReactNode }> = ({ active, onClick, children }) => ( {children} ); const DialogueTab: React.FC<{ result: AlchemicalResult }> = ({ result }) => { const [history, setHistory] = useState([]); const [userInput, setUserInput] = useState(''); const [isThinking, setIsThinking] = useState(false); const chatEndRef = useRef(null); useEffect(() => { chatEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [history]); const handleSend = useCallback(() => { if (!userInput.trim() && history.length > 0) return; const userMessage: ChatMessage = { sender: 'user', text: userInput }; setHistory(prev => [...prev, userMessage]); setUserInput(''); setIsThinking(true); setTimeout(() => { const aethelredResponse = getSocraticResponse(result, history); setHistory(prev => [...prev, aethelredResponse]); setIsThinking(false); }, 1500 + Math.random() * 500); }, [userInput, result, history]); useEffect(() => { // Initial message from Aethelred setIsThinking(true); setTimeout(() => { const initialQuestion = getSocraticResponse(result, []); setHistory([initialQuestion]); setIsThinking(false); }, 1000); }, [result]); return ( {history.map((msg, index) => ( {msg.text} ))} {isThinking && ( )} setUserInput(e.target.value)} onKeyPress={(e) => e.key === 'Enter' && !isThinking && handleSend()} placeholder="Responde o pregunta..." className="flex-grow p-3 bg-[#181818] border border-gray-700 rounded-l-md focus:outline-none focus:ring-1 focus:ring-[#a9a3f4] text-white" disabled={isThinking} /> Enviar ); }; export default function ReflectionView({ result }: Props) { const [activeTab, setActiveTab] = useState('mirror'); return ( setActiveTab('mirror')}>El Espejo Hermético setActiveTab('quintessence')}>La Quintaesencia setActiveTab('dialogue')}>El Diálogo Alquímico {activeTab === 'mirror' && ( {result.mirror.archetype} Principio en Luz {result.mirror.principleInLight.name} {result.mirror.principleInLight.description} Principio en Sombra {result.mirror.principleInShadow.name} {result.mirror.principleInShadow.description} )} {activeTab === 'quintessence' && ( "{result.quintessence}" )} {activeTab === 'dialogue' && } ); }
{msg.text}
{result.mirror.principleInLight.name}
{result.mirror.principleInLight.description}
{result.mirror.principleInShadow.name}
{result.mirror.principleInShadow.description}
"{result.quintessence}"