// /$$$$$$ /$$$$$$ /$$ /$$ /$$$$$$$$ /$$ /$$ /$$$$$$$$ /$$$$$$ /$$$$$ /$$$$$$ /$$$$$$$ // /$$__ $$|_ $$_/| $$ | $$| $$_____/ | $$$ /$$$| $$_____/ /$$__ $$ |__ $$ /$$__ $$| $$__ $$ // | $$ \__/ | $$ | $$ | $$| $$ | $$$$ /$$$$| $$ | $$ \ $$ | $$| $$ \ $$| $$ \ $$ // | $$ /$$$$ | $$ | $$ / $$/| $$$$$ | $$ $$/$$ $$| $$$$$ | $$$$$$$$ | $$| $$ | $$| $$$$$$$ // | $$|_ $$ | $$ \ $$ $$/ | $$__/ | $$ $$$| $$| $$__/ | $$__ $$ /$$ | $$| $$ | $$| $$__ $$ // | $$ \ $$ | $$ \ $$$/ | $$ | $$\ $ | $$| $$ | $$ | $$ | $$ | $$| $$ | $$| $$ \ $$ // | $$$$$$/ /$$$$$$ \ $/ | $$$$$$$$ | $$ \/ | $$| $$$$$$$$ | $$ | $$ | $$$$$$/| $$$$$$/| $$$$$$$/ // \______/ |______/ \_/ |________/ |__/ |__/|________/ |__/ |__/ \______/ \______/ |_______/ // // Hi, I'm Roland and i'm looking for a job. // Resume in /public/resume.pdf // roland.vrignon@roland.com // https://www.linkedin.com/in/roland-vrignon/ // 'use client'; import { FC, useState, useEffect, Dispatch, SetStateAction, useRef } from 'react'; import Image from 'next/image'; interface Message { content: string; role: 'lawyer' | 'judge'; requiredWords?: string[]; } interface Chat { messages: Message[]; } interface LawyerSceneProps { language: 'fr' | 'en' | 'es'; chat: Chat; setNextScene: () => void; currentQuestion: string; round: number; setRound: Dispatch>; } const LawyerScene: FC = ({ language, chat, setNextScene, currentQuestion, round, setRound, }) => { const [visible, setVisible] = useState(false); const [buttonEnabled, setButtonEnabled] = useState(false); const [countdown, setCountdown] = useState(3); const [question, setQuestion] = useState(''); const [answer, setAnswer] = useState(''); const audioRef = useRef(null); useEffect(() => { const lastJudgeMessage = chat.messages.filter((message: Message) => message.role === 'judge').slice(-1)[0]?.content; const lastLawyerMessage = chat.messages.filter((message: Message) => message.role === 'lawyer').slice(-1)[0]?.content; setQuestion(lastJudgeMessage || ''); setAnswer(lastLawyerMessage || ''); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); // Only run once on mount useEffect(() => { const playAudio = async () => { try { if (!answer) return; const response = await fetch('/api/voice', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ language, text: answer, role: 'lawyer' }) }); if (!response.ok) { throw new Error('Failed to generate audio'); } const audioBlob = await response.blob(); const audioUrl = URL.createObjectURL(audioBlob); const audio = new Audio(audioUrl); audioRef.current = audio; audio.play(); } catch (error) { console.error('Error playing audio:', error); } }; playAudio(); return () => { if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } }; }, [answer, language]); useEffect(() => { setVisible(true); setRound(round + 1); const timer = setInterval(() => { setCountdown((prev) => { if (prev <= 1) { setButtonEnabled(true); clearInterval(timer); return 0; } return prev - 1; }); }, 1000); return () => clearInterval(timer); }, []); const handleNextScene = () => { if (audioRef.current) { audioRef.current.pause(); audioRef.current = null; } setNextScene(); }; return (
{/* Image de fond */} Background {/* Contenu avec overlay noir */}
{/* Question du juge */}

{language === 'fr' ? 'Question du juge' : language === 'en' ? 'Judge\'s question' : 'Pregunta del juez'}:

{question}

{/* Réponse de l'avocat avec flèche */}

{language === 'fr' ? 'Votre réponse' : language === 'en' ? 'Your answer' : 'Tu respuesta'}:

{answer}

{/* Flèche à droite */}
); }; export default LawyerScene;