"use strict";(self.webpackChunkurncjp=self.webpackChunkurncjp||[]).push([[675],{675:(e,t,o)=>{o.r(t),o.d(t,{default:()=>l});var n=o(752),a=o(120),r=o(158),s=o(256),c=o(979),i=o(916);async function d(e="",t={}){const o=i.ServerConnection.makeSettings(),n=c.URLExt.join(o.baseUrl,"jupyter-exam",e);let a;try{a=await i.ServerConnection.makeRequest(n,t,o)}catch(e){throw new i.ServerConnection.NetworkError(e)}let r=await a.text();if(r.length>0)try{r=JSON.parse(r)}catch(e){console.log("Not a JSON response body.",a)}if(!a.ok)throw new i.ServerConnection.ResponseError(a,r.message||r);return r}const u={id:"urncjp:plugin",description:"A JupyterLab extension to collect exam files",autoStart:!0,requires:[a.ICommandPalette,r.INotebookTracker],optional:[n.ISettingRegistry],activate:(e,t,o,n)=>{console.log("JupyterLab extension urncjp is activated!");const{commands:r}=e,c=document.createElement("div");c.textContent="";const i=new s.Widget({node:c});i.id=a.DOMUtils.createDomID(),i.addClass("jp-UserWidget"),e.shell.add(i,"top",{rank:1e3});const l=document.createElement("div");l.textContent="submit";const m=new s.Widget({node:l});m.id=a.DOMUtils.createDomID(),m.addClass("jp-SubmitWidget"),e.shell.add(m,"top",{rank:1e3}),r.addCommand("urncjp:submit",{label:"Submit Exam",caption:"Submit the exam to the server",execute:()=>{var e;const t=o.currentWidget;if(!t)return void console.error("No notebook is active");const n=null===(e=t.content.model)||void 0===e?void 0:e.toJSON();if(!n)return void console.error("Failed to get notebook data");const a=n;a.metadata&&a.metadata.exam?async function(e){return d("submit",{body:e,method:"POST"})}(JSON.stringify(n)).then((e=>{const{submission:t}=e,{createdAt:o,valid:n}=t,a=new Date(o).toLocaleString("de-DE");n?(m.node.textContent=`Submitted at ${a}`,m.node.style.backgroundColor="#006045"):(m.node.textContent="Exam submissions are closed",m.node.style.backgroundColor="#1d293d")})).catch((e=>{console.error("Failed to submit notebook:",e)})):console.log("Not an exam notebook. Skipping submission.")}}),r.addCommand("urncjp:status",{label:"Check Status",caption:"Check the status of the exam",execute:()=>{(async function(){return d("user")})().then((e=>{const{name:t,sub:o,display_name:n}=e;i.node.textContent=`Jupyter Exam: ${n},  ${t} (${o})`}))}}),t.addItem({command:"urncjp:status",category:"Notebook Operations"}),t.addItem({command:"urncjp:submit",category:"Notebook Operations"}),o.currentChanged.connect(((e,t)=>{t&&(r.execute("urncjp:status"),t.context.saveState.connect(((e,t)=>{"completed"===t&&r.execute("urncjp:submit")})))})),n&&n.load(u.id).then((e=>{console.log("urncjp settings loaded:",e.composite)})).catch((e=>{console.error("Failed to load settings for urncjp.",e)}))}},l=u}}]);