!function(t){var e={};function s(a){if(e[a])return e[a].exports;var n=e[a]={i:a,l:!1,exports:{}};return t[a].call(n.exports,n,n.exports,s),n.l=!0,n.exports}s.m=t,s.c=e,s.d=function(t,e,a){s.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},s.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},s.t=function(t,e){if(1&e&&(t=s(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(s.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)s.d(a,n,function(e){return t[e]}.bind(null,n));return a},s.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(e,"a",e),e},s.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},s.p="",s(s.s=0)}([function(t,e,s){"use strict";s.r(e);const{createElement:a,render:n,useState:o,useEffect:r,Fragment:l}=wp.element,{select:d,dispatch:i}=wp.data;var u=t=>{const[e,s]=o(!1),[n,i]=o(null),[u,c]=o([]),[p,m]=o(""),[g,_]=o({}),[b,h]=o(!1);r(()=>{if(document.getElementById("chartjs"))h(!0);else{const t=document.createElement("script");t.src=window.wplms_course_data.chartjs,t.id="chartjs",document.body.appendChild(t),t.onload=()=>{h(!0)}}},[]);const f=()=>{for(var t="#",e=0;e<6;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return t};return r(()=>{s(!0),fetch(`${window.student_stats.api}/student_stats/`,{method:"post",body:JSON.stringify({type:t.type,token:d("vibebp").getToken(),user_id:window.student_stats.user_id})}).then(t=>t.json()).then(t=>{console.log("return",t),t.status?(console.log("Data Updated",t.result),c(t.result)):(console.log("Message Updated",t.message),m(t.message)),setTimeout(()=>{s(!1)},200)})},[t.type]),r(()=>{if(!e&&u&&u.length&&b){g&&Object.keys(g).length&&(console.log("chartt",g),g.destroy());let e=[],s=[],a=[];u.map(t=>{e.push(t.label),a.push(t.marks),s.push(t.average?t.average:0)});let n=[],o=f(),r=f();a.length&&n.push({label:(t.type+" Marks").toUpperCase(),data:a,borderColor:o,backgroundColor:r,showLines:!0,fill:!1}),s.length&&n.push({label:(t.type+" Averages").toUpperCase(),data:s,borderColor:r,backgroundColor:r,showLines:!0,fill:!1});let l=document.getElementById("student_stats_wplms_chart").getContext("2d"),d=new Chart(l,{type:"line",data:{labels:e,datasets:n}});_(d)}},[u,e,b]),a(l,null,e?a("div",{class:"widget_loader"},a("div",null),a("div",null),a("div",null),a("div",null)):a("div",{className:"dashboard_tab_pane"},u.length?a("canvas",{id:"student_stats_wplms_chart",ref:t=>{t&&!n&&i(t)}}):a("div",{className:"vbp_message"},window.student_stats.translations.not_found)))};const{createElement:c,render:p,useState:m,useEffect:g,Fragment:_}=wp.element,b=t=>{const[e,s]=m(!0),[a,n]=m("");return g(()=>{e&&(s(!1),t.settings.quiz?n("quiz"):t.settings.assignments?n("assignments"):t.settings.course&&n("course"))}),c("div",{className:"wplms_dashboard_student_stats_wrapper"},c("h3",{className:"widget_title"},t.settings.title),c("div",{className:"dashboard_tabs"},c("ul",{className:"dash-tabs-wrapper"},t.settings.course?c("span",{className:"course"==a?"dash-tab-active":"dash-tab",onClick:()=>{n("course")}},window.student_stats.translations.course):"",t.settings.quiz?c("span",{className:"quiz"==a?"dash-tab-active":"dash-tab",onClick:()=>{n("quiz")}},window.student_stats.translations.quiz):"",t.settings.assignments?c("span",{className:"assignments"==a?"dash-tab-active":"dash-tab",onClick:()=>{n("assignments")}},window.student_stats.translations.assignments):""),c("div",{className:"dashboard_tab_content"},c(u,{type:a}))))};document.addEventListener("wplms_student_stats",t=>{console.log("hastalavista",t),document.querySelector(".wplms_dashboard_student_stats")&&p(c(b,{settings:t.detail.widget.options}),document.querySelector(".wplms_dashboard_student_stats"))})}]);