(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var s in n)e.o(n,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:n[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.element,n=window.wp.domReady;var s=e.n(n);const i=window.wp.components,l=window.wp.apiFetch;var r=e.n(l);const c=window.ReactJSXRuntime,a=({questions:e,userAns:n,refAns:s})=>{let l=n,[a,o]=(0,t.useState)(n.length);0==l.length&&(l=new Array(e.length));let[d,m]=(0,t.useState)(l);return(0,c.jsxs)("div",{children:[e&&e.map(((e,l)=>{const[r,o]=(0,t.useState)(d[l]),u=e=>{a||o(e)},x=t=>{if(!a){let n=[];e?.single?n=[t]:(Array.isArray(r)&&(n=[...r]),n.includes(t)?n.splice(n.indexOf(t),1):n.push(t)),o(n)}};(0,t.useEffect)((()=>{((e,t)=>{let n=[...d];n[e]=t,m(n)})(l,r)}),[r]);let h="",p="";return s&&(s[l]==r?r?h="mcv-quiz-ok":p="mcv-quiz-ok":r?(p="mcv-quiz-ok",h="mcv-quiz-wrong"):(h="mcv-quiz-ok",p="mcv-quiz-wrong")),(0,c.jsxs)("div",{children:[(0,c.jsxs)(i.Flex,{style:{alignItems:"center"},children:[(0,c.jsxs)(i.FlexItem,{children:[l+1,"."]}),(0,c.jsxs)(i.FlexItem,{children:["(","select"==e.type?"选择题":"boolean"==e.type?"判断题":"问答题",")"]}),(0,c.jsx)(i.FlexBlock,{children:(0,c.jsx)("h2",{children:e.title})})]}),"select"==e.type&&(0,c.jsxs)("div",{children:[e.options.map(((t,a)=>{let o="";return s&&Array.isArray(s[l])&&s[l].includes(a)&&(o="mcv-quiz-ok"),s&&Array.isArray(n[l])&&n[l].includes(a)&&Array.isArray(s[l])&&!s[l].includes(a)&&(o="mcv-quiz-wrong"),(0,c.jsxs)(i.Flex,{style:{alignItems:"center",paddingLeft:"2rem",marginBottom:"6px"},className:"mcv-quiz-opt "+o,children:[(0,c.jsx)(i.FlexItem,{children:e?.single?(0,c.jsx)(i.Button,{className:"mcv-quiz-btn",icon:r==a?"yes-alt":"marker",onClick:()=>x(a)}):(0,c.jsx)(i.Button,{className:r==a||Array.isArray(r)&&r?.includes(a)?"mcv-quiz-btn muti":"muti",icon:"yes",onClick:()=>x(a)})}),(0,c.jsx)(i.FlexBlock,{onClick:()=>{x(a)},children:(0,c.jsx)("h3",{children:t.title})})]},"key"+a)})),(0,c.jsxs)("p",{style:{textAlign:"left"},children:[(0,c.jsx)("b",{children:"答案解析"}),"：",e?.tip?e.tip:"暂无"]})]}),"boolean"==e.type&&(0,c.jsxs)("div",{children:[(0,c.jsxs)(i.Flex,{style:{alignItems:"center",paddingLeft:"2rem",marginBottom:"6px"},className:"mcv-quiz-opt "+h,children:[(0,c.jsx)(i.FlexItem,{children:(0,c.jsx)(i.Button,{className:"mcv-quiz-btn",icon:!0===r?"yes-alt":"marker",onClick:()=>u(!0)})}),(0,c.jsx)(i.FlexBlock,{onClick:()=>u(!0),children:(0,c.jsx)("h3",{children:"正确"})})]}),(0,c.jsxs)(i.Flex,{style:{alignItems:"center",paddingLeft:"2rem"},className:"mcv-quiz-opt "+p,children:[(0,c.jsx)(i.FlexItem,{children:(0,c.jsx)(i.Button,{className:"mcv-quiz-btn",icon:!1===r?"yes-alt":"marker",onClick:()=>u(!1)})}),(0,c.jsx)(i.FlexBlock,{onClick:()=>u(!1),children:(0,c.jsx)("h3",{children:"错误"})})]}),(0,c.jsxs)("p",{style:{textAlign:"left"},children:[(0,c.jsx)("b",{children:"答案解析"}),"：",e?.tip?e.tip:"暂无"]})]}),"textarea"==e.type&&(0,c.jsxs)("div",{children:[(0,c.jsx)(i.TextareaControl,{className:"mcv-txa",value:r||"",onChange:e=>{o(e)},readOnly:a}),(0,c.jsxs)("p",{style:{textAlign:"left"},children:[(0,c.jsx)("b",{children:"答案解析"}),"：",e?.tip?e.tip:"暂无"]})]})]},"key"+l)})),(0,c.jsx)(i.Button,{style:{background:"#2080f7"},onClick:()=>{a||(()=>{let e=[];for(let t=0;t<d.length;t++)["boolean","string","number","object"].includes(typeof d[t])||e.push(t+1);e.length>0?layer.msg("请答完所有题目（"+e.join(", ")+"）再提交"):r()({path:"/mine-cloudvod/v1/lms/quiz/submit",method:"POST",data:{answer:d,lid:mcv_lesson_data.current}}).then((e=>{o(!0),layer.msg("提交成功",{time:2e3},(function(){location.reload()}))})).catch((e=>{layer.msg(e.message)}))})()},variant:"primary",style:{margin:"20px"},children:a?"已提交":"提交测试"})]})};s()((function(){document.querySelector("#mcv_quiz_wrap")&&(t.createRoot?(0,t.createRoot)(document.getElementById("mcv_quiz_wrap")).render((0,c.jsx)(a,{questions:mcv_quiz_data?.questions,userAns:mcv_quiz_data?.answers,refAns:mcv_quiz_data?.refAnswers})):(0,t.render)((0,c.jsx)(a,{questions:mcv_quiz_data?.questions,userAns:mcv_quiz_data?.answers,refAns:mcv_quiz_data?.refAnswers}),document.getElementById("mcv_quiz_wrap")))}))})();