!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:r,useEffect:o,Fragment:i}=wp.element,{select:d,dispatch:l}=wp.data;var u=t=>{const[e,s]=r(!1),[n,u]=r(null),[c,p]=r([]),[_,m]=r(""),[g,w]=r({}),[b,h]=r(!1);o(()=>{h(!0)},[]);const f=()=>{for(var t="#",e=0;e<6;e++)t+="0123456789ABCDEF"[Math.floor(16*Math.random())];return t};return o(()=>{s(!0),p([]),fetch(`${window.student_stats.api}/student_stats?type=${t.type}&user_id=${t.settings.user_id}`,{method:"post",body:JSON.stringify({type:t.type,token:d("vibebp").getToken(),user_id:t.settings.user_id})}).then(t=>t.ok?t.json():{status:0,message:window.wplms_course_data.translations.error_loading_data}).then(e=>{e.status?p(e.result):m(e.message),setTimeout(()=>{s(!1);var e=new CustomEvent("vibebp_widget_loaded",{detail:{props:t}});document.dispatchEvent(e)},200)}).catch(t=>{s(!1),console.error("Uh oh, an error!",t),l("vibebp").addNotification({text:window.wplms_course_data.translations.error_loading_data})})},[t.type]),o(()=>{if(!e&&c&&c.length&&b){g&&Object.keys(g).length&&(console.log("chartt",g),g.destroy());let e=[],s=[],a=[];c.map(t=>{e.push(t.label),a.push(t.marks),s.push(t.average?t.average:0)});let n=[],r=f(),o=f();a.length&&n.push({label:(window.wplms_course_data.translations[t.type]+" "+window.wplms_course_data.translations.marks).toUpperCase(),data:a,borderColor:r,backgroundColor:o,showLines:!0,fill:!1}),s.length&&n.push({label:(window.wplms_course_data.translations[t.type]+" "+window.wplms_course_data.translations.averages).toUpperCase(),data:s,borderColor:o,backgroundColor:o,showLines:!0,fill:!1});let i=document.getElementById("student_stats_wplms_chart").getContext("2d"),d=new Chart(i,{type:"line",data:{labels:e,datasets:n}});w(d)}},[c,e,b]),a(i,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"},c.length?a("canvas",{id:"student_stats_wplms_chart",ref:t=>{t&&!n&&u(t)}}):a("div",{className:"vbp_message"},window.student_stats.translations.not_found)))};const{createElement:c,render:p,useState:_,useEffect:m,Fragment:g}=wp.element,w=t=>{const[e,s]=_(!0),[a,n]=_("");return m(()=>{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,settings:t.settings}))))};document.addEventListener("wplms_student_stats",t=>{document.querySelector(".wplms_dashboard_student_stats")&&p(c(w,{settings:t.detail.widget.options}),document.querySelector(".wplms_dashboard_student_stats"))})}]);