function AlienConstructionTraining({user,isOpen,onClose,topic,difficulty='f',onComplete,passNeeded=3,secondsPerQuestion=30}) { const [round]=React.useState(()=>window.TrainingStudioCatalog.shuffle(topic?.constructionExercises || window.AlienConstruction.bank(topic?.topicId,difficulty,user?.id)).slice(0,3)); const [index,setIndex]=React.useState(0),[values,setValues]=React.useState({}),[field,setField]=React.useState(null),[feedback,setFeedback]=React.useState(null),[seconds,setSeconds]=React.useState(secondsPerQuestion); const answers=React.useRef([]),locked=React.useRef(false),timer=React.useRef(null),live=React.useRef(true); const exercise=round[index]; React.useEffect(()=>{live.current=true;return()=>{live.current=false;clearTimeout(timer.current);};},[]); const finish=(timeout=false)=>{ if(locked.current||!exercise)return;locked.current=true; const result=timeout?{correct:false,reason:'Se acabó el tiempo.',answer:window.AlienConstruction.sentence(exercise,values,difficulty)}:window.AlienConstruction.grade(exercise,values,difficulty); const next=[...answers.current,{learningId:exercise.id,questionId:exercise.id,masterIds:exercise.masterIds||[],baseQuestionId:exercise.id,topicIds:[exercise.topicId,...(exercise.additionalTopics||[])],studentAnswer:result.answer,isCorrect:result.correct}];answers.current=next;setFeedback(result); timer.current=setTimeout(()=>{if(!live.current)return;if(index+1===round.length){onComplete?.({correct:next.filter(a=>a.isCorrect).length,total:round.length,needed:passNeeded,checked:next.filter(a=>a.isCorrect).length>=passNeeded,answers:next});}else{setIndex(i=>i+1);setValues({});setField(null);setFeedback(null);setSeconds(secondsPerQuestion);locked.current=false;}},1000); }; const finishRef=React.useRef(finish);finishRef.current=finish; React.useEffect(()=>{if(!isOpen||feedback||!exercise)return;const id=setInterval(()=>setSeconds(s=>Math.max(0,s-1)),1000);return()=>clearInterval(id);},[isOpen,index,feedback]); React.useEffect(()=>{if(seconds===0&&!feedback)finishRef.current(true);},[seconds,feedback]); if(!isOpen)return null; const asset=exercise && window.REAL_CONSTRUCTION_CONFIG.images[exercise.image]; const layout=asset && window.REAL_CONSTRUCTION_CONFIG.layouts[asset.layout]; const names={objective:difficulty==='f'?'Objective':'Substitution',indicator:'Indicator',description:exercise?.endingLabel||'Description',not:'NOT'}; return
No hay escenas para este tema.
:<>{difficulty==='f'?'Toca las figuras y elige los elementos correctos.':difficulty==='m'?'Escribe cada elemento. Usa un pronombre como sujeto.':'Escribe cada elemento. Usa un pronombre, mayúscula inicial y signo final en el último elemento.'}
{difficulty!=='f'&&{Object.keys(values).length?window.AlienConstruction.sentence(exercise,values,difficulty):''}
{feedback&&{feedback.reason}
{!feedback.correct&&feedback.expectedAnswer&&{feedback.expectedAnswer}
}