import AutoExpandingTextArea from "@/components/Low/AutoExpandingTextarea"; import { Card, CardContent } from "@/components/ui/card"; import { AiOutlinePlus, AiOutlineDelete } from 'react-icons/ai'; import { SpeakingExercise } from "@/interfaces/exam"; import useExamEditorStore from "@/stores/examEditor"; import { useEffect, useState } from "react"; import useSectionEdit from "../../Hooks/useSectionEdit"; import Header from "../../Shared/Header"; import { Tooltip } from "react-tooltip"; import { BsFileText } from 'react-icons/bs'; import { AiOutlineUnorderedList } from 'react-icons/ai'; import { BiQuestionMark, BiMessageRoundedDetail } from "react-icons/bi"; import GenLoader from "../Shared/GenLoader"; import { RiVideoLine } from 'react-icons/ri'; import { Module } from "@/interfaces"; interface Props { sectionId: number; exercise: SpeakingExercise; module?: Module; } const Speaking2: React.FC = ({ sectionId, exercise, module = "speaking" }) => { const { dispatch } = useExamEditorStore(); const [local, setLocal] = useState(exercise); const { generating, genResult, state } = useExamEditorStore( (state) => state.modules[module].sections.find((section) => section.sectionId === sectionId)! ); const { editing, setEditing, handleSave, handleDiscard, handleEdit, handlePractice } = useSectionEdit({ sectionId, onSave: () => { setEditing(false); dispatch({ type: "UPDATE_SECTION_STATE", payload: { sectionId: sectionId, update: local , module} }); if (genResult) { dispatch({ type: "UPDATE_SECTION_SINGLE_FIELD", payload: { sectionId, module: module, field: "genResult", value: undefined } }); } }, onDiscard: () => { setLocal(exercise); }, onPractice: () => { const updatedExercise = { ...state, isPractice: !local.isPractice }; setLocal((prev) => ({...prev, isPractice: !local.isPractice})) dispatch({ type: 'UPDATE_SECTION_STATE', payload: { sectionId, update: updatedExercise, module: module } }); }, }); useEffect(() => { if (genResult && generating === "speakingScript") { setEditing(true); setLocal({ ...local, title: genResult.result[0].topic, text: genResult.result[0].question, prompts: genResult.result[0].prompts }); dispatch({ type: "UPDATE_SECTION_SINGLE_FIELD", payload: { sectionId, module: module, field: "generating", value: undefined } }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [genResult, generating]); useEffect(() => { if (genResult && generating === "video") { setLocal({...local, video_url: genResult.result[0].video_url}); dispatch({ type: "UPDATE_SECTION_STATE", payload: { sectionId, update: {...local, video_url: genResult.result[0].video_url} , module} }); dispatch({ type: "UPDATE_SECTION_SINGLE_FIELD", payload: { sectionId, module: module, field: "generating", value: undefined } }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [genResult, generating]); const addPrompt = () => { setLocal(prev => ({ ...prev, prompts: [...prev.prompts, ""] })); }; const removePrompt = (index: number) => { setLocal(prev => ({ ...prev, prompts: prev.prompts.filter((_, i) => i !== index) })); }; const updatePrompt = (index: number, text: string) => { setLocal(prev => { const newPrompts = [...prev.prompts]; newPrompts[index] = text; return { ...prev, prompts: newPrompts }; }); }; const isUnedited = local.text === "" || (local.title === undefined || local.title === "") || local.prompts.length === 0; const tooltipContent = `

Prompts are guiding points that help candidates structure their talk. They typically include aspects like:

`; return ( <>
{generating && generating === "speakingScript" ? ( ) : ( <> {editing ? ( <>

Title

setLocal(prev => ({ ...prev, title: text }))} className="w-full p-3 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent min-h-[80px] transition-all" placeholder="Enter the topic" />

Question

setLocal(prev => ({ ...prev, text: text }))} className="w-full p-3 border border-gray-300 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent min-h-[80px] transition-all" placeholder="Enter the main question" />

Prompts

{local.prompts.length === 0 ? (

No prompts added yet

) : ( local.prompts.map((prompt, index) => (

Prompt {index + 1}

updatePrompt(index, text)} className="w-full p-3 border border-gray-200 rounded-md focus:ring-2 focus:ring-blue-500 focus:border-transparent min-h-[80px] transition-all bg-white" placeholder={`Enter prompt ${index + 1}`} />
)) )}
) : isUnedited ? (

Generate or edit the script!

) : (
{local.video_url &&

Video

} {generating && generating === "video" && }

Title

{local.title || 'Untitled'}

Question

{local.text || 'No question provided'}

{local.prompts && local.prompts.length > 0 && (

Prompts

{local.prompts.map((prompt, index) => (

{prompt}

))}
)}
)} )} ); } export default Speaking2;