PageSourceSearch

https://thediscourse.ai/assets/Dashboard-DJBc2q9O.js

js thediscourse.ai collected 2026-10-10 00:42:46 UTC 170,930 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/web-Cc7o-ryu.js","assets/index-CoMAdSaI.js","assets/react-vendor-73cbJX8F.js","assets/framer-motion-CXnF6ox9.js","assets/index-Bn6y4_R-.css","assets/web-BQesvTZ3.js","assets/index-CPsH98q0.js"])))=>i.map(i=>d[i]);
2var e=(e,t,s)=>new Promise((r,a)=>{var l=e=>{try{i(s.next(e))}catch(t){a(t)}},n=e=>{try{i(s.throw(e))}catch(t){a(t)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);i((s=s.apply(e,t)).next())});import{a as t,u as s,C as r,b as a,A as l,g as n,l as i,r as o,_ as d,H as c,N as u,I as h,c as m,d as g,e as x,t as b,T as p,f,h as y,i as v,j as k,k as w,m as j,n as N,P as C}from"./index-CoMAdSaI.js";import{r as S,j as A,R as D,L as I,a as R}from"./react-vendor-73cbJX8F.js";import{G as E,C as M}from"./GamificationStats-BzfuqBkD.js";import O from"./LiveSessionRoom-DCFkD5c0.js";import{P}from"./ProductTour-CxIGINSJ.js";import"./framer-motion-CXnF6ox9.js";import"./SocraticTutor-D1PWsSJQ.js";import"./purify.es-BaO-PeKJ.js";const T=({isOpen:e,onClose:t,onSuccess:s})=>{const[r,a]=S.useState(""),[l,n]=S.useState(""),[i,o]=S.useState(!1),[d,c]=S.useState(""),[u,h]=S.useState(!1),[m,g]=S.useState([]),x=S.useRef(null),b=()=>{i||(n(""),c(""),h(!1),g([]),x.current&&(x.current.value=""),t())};return e?A.jsx("div",{className:"fixed inset-0 bg-gray-500 bg-opacity-75 flex items-center justify-center p-4 z-50",children:A.jsxs("div",{className:"bg-white rounded-lg shadow-xl max-w-2xl w-full max-h-[95vh] flex flex-col",children:[A.jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200",children:[A.jsxs("div",{className:"flex items-center space-x-3",children:[A.jsx("div",{className:"w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center",children:A.jsx("svg",{className:"w-5 h-5 text-blue-600",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),A.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Report a Problem"})]}),A.jsx("button",{onClick:b,disabled:i,className:"text-gray-400 hover:text-gray-600 transition-colors",children:A.jsx("svg",{className:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]}),A.jsx("div",{className:"flex-1 p-4 overflow-y-auto",children:A.jsxs("div",{className:"space-y-4",children:[!u&&A.jsxs("div",{className:"flex items-start space-x-3",children:[A.jsx("div",{className:"w-8 h-8 bg-blue-600 rounded-full flex items-center justify-center flex-shrink-0",children:A.jsx("svg",{className:"w-5 h-5 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7-4a1 1 0 11-2 0 1 1 0 012 0zM9 9a1 1 0 000 2v3a1 1 0 001 1h1a1 1 0 100-2v-3a1 1 0 00-1-1H9z",clipRule:"evenodd"})})}),A.jsx("div",{className:"bg-blue-50 rounded-lg p-3 max-w-md border border-blue-200",children:A.jsx("p",{className:"text-sm text-gray-700",children:"👋 Please describe the technical issue you're experiencing. Include as much detail as possible to help us resolve it quickly."})})]}),u&&A.jsxs("div",{className:"flex items-start space-x-3",children:[A.jsx("div",{className:"w-12 h-12 bg-green-600 rounded-full flex items-center justify-center flex-shrink-0",children:A.jsx("svg",{className:"w-7 h-7 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})}),A.jsxs("div",{className:"bg-green-50 rounded-lg p-5 max-w-xl border-2 border-green-300 shadow-sm",children:[A.jsx("h4",{className:"text-lg font-bold text-green-800 mb-3",children:"✅ Report Submitted Successfully!"}),A.jsx("p",{className:"text-base text-green-700 mb-3",children:"Thank you for reporting this issue. We've received your message and will investigate it promptly."}),A.jsxs("p",{className:"text-base text-green-700 font-medium",children:["We'll contact you at ",A.jsx("span",{className:"font-bold",children:l})," within 24-48 hours to provide updates and resolve your issue."]})]})]}),d&&A.jsxs("div",{className:"flex items-start space-x-3",children:[A.jsx("div",{className:"w-8 h-8 bg-red-600 rounded-full flex items-center justify-center flex-shrink-0",children:A.jsx("svg",{className:"w-5 h-5 text-white",f
2ill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-7 4a1 1 0 11-2 0 1 1 0 012 0zm-1-9a1 1 0 00-1 1v4a1 1 0 102 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),A.jsx("div",{className:"bg-red-50 rounded-lg p-3 max-w-xs",children:A.jsx("p",{className:"text-sm text-red-800",children:d})})]})]})}),A.jsx("div",{className:"p-4 border-t border-gray-200",children:A.jsxs("form",{onSubmit:e=>{return n=null,i=null,d=function*(){if(e.preventDefault(),r.trim())if(l.trim()&&l.includes("@")){o(!0),c("");try{if(0===m.length){const e={message:r.trim(),userEmail:l.trim(),userId:"",timestamp:(new Date).toISOString(),userAgent:navigator.userAgent,url:window.location.href},i=yield fetch("/api/report-problem",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(i.ok)h(!0),a(""),setTimeout(()=>{t(),h(!1),s&&s()},2e3);else{const e=yield i.text();let t;try{t=JSON.parse(e)}catch(n){t={error:e}}c(t.error||`Failed to submit report (${i.status}). Please try again.`)}}else{const e=new FormData;e.append("message",r.trim()),e.append("userEmail",l.trim()),e.append("userId",""),e.append("timestamp",(new Date).toISOString()),e.append("userAgent",navigator.userAgent),e.append("url",window.location.href),m.forEach((t,s)=>{e.append(`image_${s}`,t)}),e.append("imageCount",m.length.toString());const i=yield fetch("/api/report-problem",{method:"POST",body:e});if(i.ok)h(!0),a(""),setTimeout(()=>{t(),h(!1),s&&s()},2e3);else{const e=yield i.text();let t;try{t=JSON.parse(e)}catch(n){t={error:e}}c(t.error||`Failed to submit report (${i.status}). Please try again.`)}}}catch(i){c("Network error. Please check your connection and try again.")}finally{o(!1)}}else c("Please enter a valid email address.");else c("Please enter a message describing your issue.")},new Promise((t,s)=>{var r=t=>{try{l(d.next(t))}catch(e){s(e)}},a=t=>{try{l(d.throw(t))}catch(e){s(e)}},l=e=>e.done?t(e.value):Promise.resolve(e.value).then(r,a);l((d=d.apply(n,i)).next())});var n,i,d},className:"space-y-3",children:[A.jsxs("div",{children:[A.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Your Email Address *"}),A.jsx("input",{type:"email",value:l,onChange:e=>n(e.target.value),placeholder:"Enter your email address",className:"w-full px-4 py-3 border border-blue-200 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",disabled:i||u,required:!0})]}),A.jsxs("div",{className:"relative",children:[A.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Describe the Issue *"}),A.jsx("textarea",{value:r,onChange:e=>a(e.target.value),placeholder:"Please describe the technical issue you're experiencing in detail...",className:"w-full px-4 py-3 border border-blue-200 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none",rows:"4",disabled:i||u,maxLength:"1000",required:!0}),A.jsxs("div",{className:"absolute bottom-2 right-2 text-xs text-gray-400",children:[r.length,"/1000"]})]}),A.jsxs("div",{className:"space-y-2",children:[A.jsx("label",{className:"block text-sm font-medium text-gray-700",children:"Attach Images (Optional)"}),A.jsxs("div",{className:"flex items-center space-x-2",children:[A.jsx("input",{ref:x,type:"file",accept:"image/*",multiple:!0,onChange:e=>{const t=Array.from(e.target.files),s=t.filter(e=>{const t=["image/jpeg","image/png","image/gif","image/webp"].includes(e.type),s=e.size<=5242880;return t&&s});s.length!==t.length&&c("Some files were rejected. Only JPEG, PNG, GIF, and WebP images under 5MB are allowed."),g(e=>[...e,...s].slice(0,3))},disabled:i||u||m.length>=3,className:"hidden"}),A.jsxs("button",{type:"button",onClick:()=>{var e;return null==(e=x.current)?void 0:e.click()},disabled:i||u||m.length>=3,className:"inline-flex items-center px-3 py-2 text-sm font-medium text-blue-700 bg-blue-50 border border-blue-300 rounded-md hover:bg-blue-100 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors disabled:opacity-50",children:[A.jsx("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),"Add Images"]}),A.jsxs("span",{className:"text-xs text-gray-500",children:[m.length,"/3 images (max 5MB each)"]}
2)]}),m.length>0&&A.jsx("div",{className:"grid grid-cols-3 gap-2",children:m.map((e,t)=>A.jsxs("div",{className:"relative group",children:[A.jsx("img",{src:URL.createObjectURL(e),alt:`Preview ${t+1}`,className:"w-full h-20 object-cover rounded border border-gray-200"}),A.jsx("button",{type:"button",onClick:()=>(e=>{g(t=>t.filter((t,s)=>s!==e))})(t),className:"absolute -top-2 -right-2 w-6 h-6 bg-red-500 text-white rounded-full flex items-center justify-center text-xs hover:bg-red-600 transition-colors",children:"×"}),A.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black bg-opacity-50 text-white text-xs p-1 truncate",children:e.name})]},t))})]}),A.jsxs("div",{className:"flex items-center justify-between",children:[A.jsx("p",{className:"text-xs text-gray-500",children:"Your report will include your email and technical details to help us assist you."}),A.jsxs("div",{className:"flex space-x-2",children:[A.jsx("button",{type:"button",onClick:b,disabled:i,className:"px-4 py-2 text-sm font-medium text-blue-700 bg-white border border-blue-300 rounded-lg hover:bg-blue-50 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors disabled:opacity-50",children:"Cancel"}),A.jsx("button",{type:"submit",disabled:i||!r.trim()||u,className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 transition-colors disabled:opacity-50 flex items-center space-x-2",children:i?A.jsxs(A.Fragment,{children:[A.jsxs("svg",{className:"animate-spin -ml-1 mr-2 h-4 w-4 text-white",fill:"none",viewBox:"0 0 24 24",children:[A.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),A.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),A.jsx("span",{children:"Sending..."})]}):A.jsxs(A.Fragment,{children:[A.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 19l9 2-9-18-9 18 9-2zm0 0v-8"})}),A.jsx("span",{children:"Send Report"})]})})]})]})]})})]})}):null};var L,z,B=Object.defineProperty,$=Object.getOwnPropertySymbols,F=Object.prototype.hasOwnProperty,_=Object.prototype.propertyIsEnumerable,H=(e,t,s)=>t in e?B(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,U=(e,t)=>{for(var s in t||(t={}))F.call(t,s)&&H(e,s,t[s]);if($)for(var s of $(t))_.call(t,s)&&H(e,s,t[s]);return e},W=(e,t)=>{var s={};for(var r in e)F.call(e,r)&&t.indexOf(r)<0&&(s[r]=e[r]);if(null!=e&&$)for(var r of $(e))t.indexOf(r)<0&&_.call(e,r)&&(s[r]=e[r]);return s};(e=>{const t=class t{constructor(e,s,r,l){if(this.version=e,this.errorCorrectionLevel=s,this.modules=[],this.isFunction=[],e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version value out of range");if(l<-1||l>7)throw new RangeError("Mask value out of range");this.size=4*e+17;let n=[];for(let t=0;t<this.size;t++)n.push(!1);for(let t=0;t<this.size;t++)this.modules.push(n.slice()),this.isFunction.push(n.slice());this.drawFunctionPatterns();const i=this.addEccAndInterleave(r);if(this.drawCodewords(i),-1==l){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);const s=this.getPenaltyScore();s<e&&(l=t,e=s),this.applyMask(t)}}a(0<=l&&l<=7),this.mask=l,this.applyMask(l),this.drawFormatBits(l),this.isFunction=[]}static encodeText(s,r){const a=e.QrSegment.makeSegments(s);return t.encodeSegments(a,r)}static encodeBinary(s,r){const a=e.QrSegment.makeBytes(s);return t.encodeSegments([a],r)}static encodeSegments(e,r,l=1,i=40,o=-1,d=!0){if(!(t.MIN_VERSION<=l&&l<=i&&i<=t.MAX_VERSION)||o<-1||o>7)throw new RangeError("Invalid value");let c,u;for(c=l;;c++){const s=8*t.getNumDataCodewords(c,r),a=n.getTotalBits(e,c);if(a<=s){u=a;break}if(c>=i)throw new RangeError("Data too long")}for(const s of[t.Ecc.MEDIUM,t.Ecc.QUARTILE,t.Ecc.HIGH])d&&u<=8*t.getNumDataCodewords(c,s)&&(r=s);let h=[];for(const t of e){s(t.mode.modeBits,4,h),s(t.numChars,t.mode.numCharCountBits(c),h);for(const e of t.getData())h.push(e)}a(h.length==u);const m=8*t.getNumDataCodewords(c,r);a(h.length<=m),s(0,Math.min(4,m-h.length),h),s(0,(8-h.length%8)%8,h),a(h.length%8==0);for(let t=236;h.length<m;t^=253)s(t,8,h);let g=[];for(;8*g.length<h.length;)g.push(0);return h.forEach((e,t)=>g[t>>>3]|=e<<7-(7&t)),new t(c,r,g,o)}getModule(e,t){return 0<=e&&e<this.size&&0<=t&&t<this.size&&this.modules[t][e]}getModules(){return this.modules}drawFunctionPatterns(){for(let s=0;s<this.size;s++)this.setFunctionModule(6,s,s%2==0),this.setFunctionModule(s,6,s%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const e=this.getAlignmentPatternPositions(),t=e.length;for(let s=0;s<t;s++)for(let r=0;r<t;r++)0==s&&0==r||0==s&&r==t-1||s==t-1&&0==r||this.drawAlignmentPattern(e[s],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){const t=this.errorCorrectionLevel.formatBits<<3|e;let s=t;for(let r=0;r<10;r++)s=s<<1^1335*(s>>>9);const l=21522^(t<<10|s);a(l>>>15==0);for(let a=0;a<=5;a++)this.setFunctionModule(8,a,r(l,a));this.setFunctionModule(8,7,r(l,6)),this.setFunctionModule(8,8,r(l,7)),this.setFunctionModule(7,8,r(l,8));for(let a=9;a<15;a++)this.setFunctionModule(14-a,8,r(l,a));for(let a=0;a<8;a++)this.setFunctionModule(this.size-1-a,8,r(l,a));for(let a=8;a<15;a++)this.setFunctionModule(8,this.size-15+a,r(l,a));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let s=0;s<12;s++)e=e<<1^7973*(e>>>11);const t=this.version<<12|e;a(t>>
vendor: 9,380 bytes, line 2
2>18==0);for(let s=0;s<18;s++){const e=r(t,s),a=this.size-11+s%3,l=Math.floor(s/3);this.setFunctionModule(a,l,e),this.setFunctionModule(l,a,e)}}drawFinderPattern(e,t){for(let s=-4;s<=4;s++)for(let r=-4;r<=4;r++){const a=Math.max(Math.abs(r),Math.abs(s)),l=e+r,n=t+s;0<=l&&l<this.size&&0<=n&&n<this.size&&this.setFunctionModule(l,n,2!=a&&4!=a)}}drawAlignmentPattern(e,t){for(let s=-2;s<=2;s++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+s,1!=Math.max(Math.abs(r),Math.abs(s)))}setFunctionModule(e,t,s){this.modules[t][e]=s,this.isFunction[t][e]=!0}addEccAndInterleave(e){const s=this.version,r=this.errorCorrectionLevel;if(e.length!=t.getNumDataCodewords(s,r))throw new RangeError("Invalid argument");const l=t.NUM_ERROR_CORRECTION_BLOCKS[r.ordinal][s],n=t.ECC_CODEWORDS_PER_BLOCK[r.ordinal][s],i=Math.floor(t.getNumRawDataModules(s)/8),o=l-i%l,d=Math.floor(i/l);let c=[];const u=t.reedSolomonComputeDivisor(n);for(let a=0,m=0;a<l;a++){let s=e.slice(m,m+d-n+(a<o?0:1));m+=s.length;const r=t.reedSolomonComputeRemainder(s,u);a<o&&s.push(0),c.push(s.concat(r))}let h=[];for(let t=0;t<c[0].length;t++)c.forEach((e,s)=>{(t!=d-n||s>=o)&&h.push(e[t])});return a(h.length==i),h}drawCodewords(e){if(e.length!=Math.floor(t.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let s=0;for(let t=this.size-1;t>=1;t-=2){6==t&&(t=5);for(let a=0;a<this.size;a++)for(let l=0;l<2;l++){const n=t-l,i=!(t+1&2)?this.size-1-a:a;!this.isFunction[i][n]&&s<8*e.length&&(this.modules[i][n]=r(e[s>>>3],7-(7&s)),s++)}}a(s==8*e.length)}applyMask(e){if(e<0||e>7)throw new RangeError("Mask value out of range");for(let t=0;t<this.size;t++)for(let s=0;s<this.size;s++){let r;switch(e){case 0:r=(s+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=s%3==0;break;case 3:r=(s+t)%3==0;break;case 4:r=(Math.floor(s/3)+Math.floor(t/2))%2==0;break;case 5:r=s*t%2+s*t%3==0;break;case 6:r=(s*t%2+s*t%3)%2==0;break;case 7:r=((s+t)%2+s*t%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[t][s]&&r&&(this.modules[t][s]=!this.modules[t][s])}}getPenaltyScore(){let e=0;for(let a=0;a<this.size;a++){let s=!1,r=0,l=[0,0,0,0,0,0,0];for(let n=0;n<this.size;n++)this.modules[a][n]==s?(r++,5==r?e+=t.PENALTY_N1:r>5&&e++):(this.finderPenaltyAddHistory(r,l),s||(e+=this.finderPenaltyCountPatterns(l)*t.PENALTY_N3),s=this.modules[a][n],r=1);e+=this.finderPenaltyTerminateAndCount(s,r,l)*t.PENALTY_N3}for(let a=0;a<this.size;a++){let s=!1,r=0,l=[0,0,0,0,0,0,0];for(let n=0;n<this.size;n++)this.modules[n][a]==s?(r++,5==r?e+=t.PENALTY_N1:r>5&&e++):(this.finderPenaltyAddHistory(r,l),s||(e+=this.finderPenaltyCountPatterns(l)*t.PENALTY_N3),s=this.modules[n][a],r=1);e+=this.finderPenaltyTerminateAndCount(s,r,l)*t.PENALTY_N3}for(let a=0;a<this.size-1;a++)for(let s=0;s<this.size-1;s++){const r=this.modules[a][s];r==this.modules[a][s+1]&&r==this.modules[a+1][s]&&r==this.modules[a+1][s+1]&&(e+=t.PENALTY_N2)}let s=0;for(const t of this.modules)s=t.reduce((e,t)=>e+(t?1:0),s);const r=this.size*this.size,l=Math.ceil(Math.abs(20*s-10*r)/r)-1;return a(0<=l&&l<=9),e+=l*t.PENALTY_N4,a(0<=e&&e<=2568888),e}getAlignmentPatternPositions(){if(1==this.version)return[];{const e=Math.floor(this.version/7)+2,t=32==this.version?26:2*Math.ceil((4*this.version+4)/(2*e-2));let s=[6];for(let r=this.size-7;s.length<e;r-=t)s.splice(1,0,r);return s}}static getNumRawDataModules(e){if(e<t.MIN_VERSION||e>t.MAX_VERSION)throw new RangeError("Version number out of range");let s=(16*e+128)*e+64;if(e>=2){const t=Math.floor(e/7)+2;s-=(25*t-10)*t-55,e>=7&&(s-=36)}return a(208<=s&&s<=29648),s}static getNumDataCodewords(e,s){return Math.floor(t.getNumRawDataModules(e)/8)-t.ECC_CODEWORDS_PER_BLOCK[s.ordinal][e]*t.NUM_ERROR_CORRECTION_BLOCKS[s.ordinal][e]}static reedSolomonComputeDivisor(e){if(e<1||e>255)throw new RangeError("Degree out of range");let s=[];for(let t=0;t<e-1;t++)s.push(0);s.push(1);let r=1;for(let a=0;a<e;a++){for(let e=0;e<s.length;e++)s[e]=t.reedSolomonMultiply(s[e],r),e+1<s.length&&(s[e]^=s[e+1]);r=t.reedSolomonMultiply(r,2)}return s}static reedSolomonComputeRemainder(e,s){let r=s.map(e=>0);for(const a of e){const e=a^r.shift();r.push(0),s.forEach((s,a)=>r[a]^=t.reedSolomonMultiply(s,e))}return r}static reedSolomonMultiply(e,t){if(e>>>8!=0||t>>>8!=0)throw new RangeError("Byte out of range");let s=0;for(let r=7;r>=0;r--)s=s<<1^285*(s>>>7),s^=(t>>>r&1)*e;return a(s>>>8==0),s}finderPenaltyCountPatterns(e){const t=e[1];a(t<=3*this.size);const s=t>0&&e[2]==t&&e[3]==3*t&&e[4]==t&&e[5]==t;return(s&&e[0]>=4*t&&e[6]>=t?1:0)+(s&&e[6]>=4*t&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,s){return e&&(this.finderPenaltyAddHistory(t,s),t=0),t+=this.size,this.finderPenaltyAddHistory(t,s),this.finderPenaltyCountPatterns(s)}finderPenaltyAddHistory(e,t){0==t[0]&&(e+=this.size),t.pop(),t.unshift(e)}};function s(e,t,s){if(t<0||t>31||e>>>t!=0)throw new RangeError("Value out of range");for(let r=t-1;r>=0;r--)s.push(e>>>r&1)}function r(e,t){return!!(e>>>t&1)}function a(e){if(!e)throw new Error("Assertion error")}t.MIN_VERSION=1,t.MAX_VERSION=40,t.PENALTY_N1=3,t.PENALTY_N2=3,t.PENALTY_N3=40,t.PENALTY_N4=10,t.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],t.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=t;const l=class e{constructor(e,t,s){if(this.mode=e,this.numChars=t,this.bitData=s,t<0)throw new RangeError("Invalid argument");this.bitData=s.slice()}static makeBytes(t){let r=[];for(const e of t)s(e,8,r);return new e(e.Mode.BYTE,t.length,r)}static makeNumeric(t){if(!e.isNumeric(t))throw new RangeError("String contains non-numeric characters");let r=[];for(let e=0;e<t.length;){const a=Math.min(t.length-e,3);s(parseInt(t.substring(e,e+a),10),3*a+1,r),e+=a}return new e(e.Mode.NUMERIC,t.length,r)}static makeAlphanumeric(t){if(!e.isAlphanumeric(t))throw new RangeError("String contains unencodable characters in alphanumeric mode");let r,a=[];for(r=0;r+2<=t.length;r+=2){let l=45*e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r));l+=e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r+1)),s(l,11,a)}return r<t.length&&s(e.ALPHANUMERIC_CHARSET.indexOf(t.charAt(r)),6,a),new e(e.Mode.ALPHANUMERIC,t.length,a)}static makeSegments(t){return""==t?[]:e.isNumeric(t)?[e.makeNumeric(t)]:e.isAlphanumeric(t)?[e.makeAlphanumeric(t)]:[e.makeBytes(e.toUtf8ByteArray(t))]}static makeEci(t){let r=[];if(t<0)throw new RangeError("ECI assignment value out of range");if(t<128)s(t,8,r);else if(t<16384)s(2,2,r),s(t,14,r);else{if(!(t<1e6))throw new RangeError("ECI assignment value out of range");s(6,3,r),s(t,21,r)}return new e(e.Mode.ECI,0,r)}static isNumeric(t){return e.NUMERIC_REGEX.test(t)}static isAlphanumeric(t){return e.ALPHANUMERIC_REGEX.test(t)}getData(){return this.bitData.slice()}static getTotalBits(e,t){let s=0;for(const r of e){const e=r.mode.numCharCountBits(t);if(r.numChars>=1<<e)return 1/0;s+=4+e+r.bitData.length}return s}static toUtf8ByteArray(e){e=encodeURI(e);let t=[];for(let s=0;s<e.length;s++)"%"!=e.charAt(s)?t.push(e.charCodeAt(s)):(t.push(parseInt(e.substring(s+1,s+3),16)),s+=2);return t}};l.NUMERIC_REGEX=/^[0-9]*$/,l.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,l.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let n=l;e.QrSegment=l})(L||(L={})),(e=>{const t=class{constructor(e,t){this.ordinal=e,this.formatBits=t}};t.LOW=new t(0,1),t.MEDIUM=new t(1,0),t.QUARTILE=new t(2,3),t.HIGH=new t(3,2),e.Ecc=t})((z=L||(L={})).QrCode||(z.QrCode={})),(e=>{(e=>{const t=class{constructor(e,t){this.modeBits=e,this.numBitsCharCount=t}numCharCountBits(e){return this.numBitsCharCount[Math.floor((e+7)/17)]}};t.NUMERIC=new t(1,[10,12,14]),t.ALPHANUMERIC=new t(2,[9,11,13]),t.BYTE=new t(4,[8,16,16]),t.KANJI=new t(8,[8,10,12]),t.ECI=new t(7,[0,0,0]),e.Mode=t})(e.QrSegment||(e.QrSegment={}))})(L||(L={}));var V=L,G={L:V.QrCode.Ecc.LOW,M:V.QrCode.Ecc.MEDIUM,Q:V.QrCode.Ecc.QUARTILE,H:V.QrCode.Ecc.HIGH},Q=128,Y="L",q="#FFFFFF",J="#000000",K=!1,X=1;function Z(e,t=0){const s=[];return e.forEach(function(e,r){let a=null;e.forEach(function(l,n){if(!l&&null!==a)return s.push(`M${a+t} ${r+t}h${n-a}v1H${a+t}z`),void(a=null);if(n!==e.length-1)l&&null===a&&(a=n);else{if(!l)return;null===a?s.push(`M${n+t},${r+t} h1v1H${n+t}z`):s.push(`M${a+t},${r+t} h${n+1-a}v1H${a+t}z`)}})}),s.join("")}function ee(e,t){return e.slice().map((e,s)=>s<t.y||s>=t.y+t.h?e:e.map((e,s)=>(s<t.x||s>=t.x+t.w)&&e))}function te({value:e,level:t,minVersion:s,includeMargin:r,marginSize:a,imageSettings:l,size:n,boostLevel:i}){let o=D.useMemo(()=>{const r=(Array.isArray(e)?e:[e]).reduce((e,t)=>
2(e.push(...V.QrSegment.makeSegments(t)),e),[]);return V.QrCode.encodeSegments(r,G[t],s,void 0,void 0,i)},[e,t,s,i]);const{cells:d,margin:c,numCells:u,calculatedImageSettings:h}=D.useMemo(()=>{let e=o.getModules();const t=function(e,t){return null!=t?Math.max(Math.floor(t),0):e?4:0}(r,a),s=e.length+2*t,i=function(e,t,s,r){if(null==r)return null;const a=e.length+2*s,l=Math.floor(.1*t),n=a/t,i=(r.width||l)*n,o=(r.height||l)*n,d=null==r.x?e.length/2-i/2:r.x*n,c=null==r.y?e.length/2-o/2:r.y*n,u=null==r.opacity?1:r.opacity;let h=null;if(r.excavate){let e=Math.floor(d),t=Math.floor(c);h={x:e,y:t,w:Math.ceil(i+d-e),h:Math.ceil(o+c-t)}}return{x:d,y:c,h:o,w:i,excavation:h,opacity:u,crossOrigin:r.crossOrigin}}(e,n,t,l);return{cells:e,margin:t,numCells:s,calculatedImageSettings:i}},[o,n,l,r,a]);return{qrcode:o,margin:c,cells:d,numCells:u,calculatedImageSettings:h}}var se=function(){try{(new Path2D).addPath(new Path2D)}catch(e){return!1}return!0}();D.forwardRef(function(e,t){const s=e,{value:r,size:a=Q,level:l=Y,bgColor:n=q,fgColor:i=J,includeMargin:o=K,minVersion:d=X,boostLevel:c,marginSize:u,imageSettings:h}=s,m=W(s,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:g}=m,x=W(m,["style"]),b=null==h?void 0:h.src,p=D.useRef(null),f=D.useRef(null),y=D.useCallback(e=>{p.current=e,"function"==typeof t?t(e):t&&(t.current=e)},[t]),[v,k]=D.useState(!1),{margin:w,cells:j,numCells:N,calculatedImageSettings:C}=te({value:r,level:l,minVersion:d,boostLevel:c,includeMargin:o,marginSize:u,imageSettings:h,size:a});D.useEffect(()=>{if(null!=p.current){const e=p.current,t=e.getContext("2d");if(!t)return;let s=j;const r=f.current,l=null!=C&&null!==r&&r.complete&&0!==r.naturalHeight&&0!==r.naturalWidth;l&&null!=C.excavation&&(s=ee(j,C.excavation));const o=window.devicePixelRatio||1;e.height=e.width=a*o;const d=a/N*o;t.scale(d,d),t.fillStyle=n,t.fillRect(0,0,N,N),t.fillStyle=i,se?t.fill(new Path2D(Z(s,w))):j.forEach(function(e,s){e.forEach(function(e,r){e&&t.fillRect(r+w,s+w,1,1)})}),C&&(t.globalAlpha=C.opacity),l&&t.drawImage(r,C.x+w,C.y+w,C.w,C.h)}}),D.useEffect(()=>{k(!1)},[b]);const S=U({height:a,width:a},g);let A=null;return null!=b&&(A=D.createElement("img",{src:b,key:b,style:{display:"none"},onLoad:()=>{k(!0)},ref:f,crossOrigin:null==C?void 0:C.crossOrigin})),D.createElement(D.Fragment,null,D.createElement("canvas",U({style:S,height:a,width:a,ref:y,role:"img"},x)),A)}).displayName="QRCodeCanvas",D.forwardRef(function(e,t){const s=e,{value:r,size:a=Q,level:l=Y,bgColor:n=q,fgColor:i=J,includeMargin:o=K,minVersion:d=X,boostLevel:c,title:u,marginSize:h,imageSettings:m}=s,g=W(s,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:x,cells:b,numCells:p,calculatedImageSettings:f}=te({value:r,level:l,minVersion:d,boostLevel:c,includeMargin:o,marginSize:h,imageSettings:m,size:a});let y=b,v=null;null!=m&&null!=f&&(null!=f.excavation&&(y=ee(b,f.excavation)),v=D.createElement("image",{href:m.src,height:f.h,width:f.w,x:f.x+x,y:f.y+x,preserveAspectRatio:"none",opacity:f.opacity,crossOrigin:f.crossOrigin}));const k=Z(y,x);return D.createElement("svg",U({height:a,width:a,viewBox:`0 0 ${p} ${p}`,ref:t,role:"img"},g),!!u&&D.createElement("title",null,u),D.createElement("path",{fill:n,d:`M0,0 h${p}v${p}H0z`,shapeRendering:"crispEdges"}),D.createElement("path",{fill:i,d:k,shapeRendering:"crispEdges"}),v)}).displayName="QRCodeSVG";var re=(e,t,s)=>new Promise((r,a)=>{var l=e=>{try{i(s.next(e))}catch(t){a(t)}},n=e=>{try{i(s.throw(e))}catch(t){a(t)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);i((s=s.apply(e,t)).next())});const ae=()=>{const{user:e}=t(),{t:l}=s(),[n,i]=S.useState((null==e?void 0:e.twoFactorEnabled)||!1),[o,d]=S.useState(!1),[c,u]=S.useState(""),[h,m]=S.useState(""),[g,x]=S.useState(""),[b,p]=S.useState(!1),[f,y]=S.useState(""),[v,k]=S.useState("");S.useEffect(()=>{e&&i(e.twoFactorEnabled)},[e]);return A.jsxs("div",{className:"security-settings mt-6 border-t border-gray-200 dark:border-slate-800 pt-6",children:[A.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-2",children:l("securitySettings.title")}),A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-4",children:l("securitySettings.description")}),f&&A.jsx("div",{className:"text-sm text-red-600 mb-4",children:f}),v&&A.jsx("div",{className:"text-sm text-green-600 mb-4",children:v}),o?A.jsxs("div",{className:"setup-container bg-gray-50 dark:bg-slate-800 p-4 rounded-lg",children:[A.jsxs("p",{className:"text-xs font-medium text-gray-700 dark:text-slate-300 mb-4",children:[l("securitySettings.scanInstruction")," ",r.isNativePlatform()?"":l("securitySettings.scanInstructionApps"),":"]}),A.jsx("div",{className:"flex justify-center mb-4 p-2 bg-white rounded-lg inline-block",children:A.jsx("img",{src:c,alt:l("securitySettings.qrCodeAlt"),style:{width:"180px",height:"180px"}})}),A.jsxs("p",{className:"text-xs text-gray-500 mb-4",children:[l("securitySettings.enterManually")," ",A.jsx("code",{className:"bg-gray-200 dark:bg-slate-700 px-1 rounded",children:h})]}),A.jsx("p",{className:"text-xs font-medium text-gray-700 dark:text-slate-300 mb-2",children:l("securitySettings.enterCode")}),A.jsxs("div",{className:"flex gap-2",children:[A.jsx("input",{type:"text",maxLength:"6",placeholder:"000000",value:g,onChange:e=>x(e.target.value.replace(/[^0-9]/g,"")),className:"w-32 px-3 py-2 border border-gray-300 dark:border-slate-600 rounded-md bg-white dark:bg-slate-700 text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-slate-500 text-center text-lg tracking-widest outline-none focus:ring-2 focus:ring-blue-500 transition-colors duration-200"}),A.jsx("button",{onClick:()=>re(null,null,function*(){y(""),p(!0);try{yield a.enable2FA(g),i(!0),d(!1),k(l("securitySettings.enabledSuccess")),setTimeout(()=>k(""),5e3)}catch(e){y(e.message||"Invalid verification code")}finally{p(!1)}}),disabled:b||6!==g.length,className:"px-4 py-2 bg-blue-600 text-white rounded-md text-sm font-medium hover:bg-blue-700 disabled:opacity-50",children:l("securitySettings.verifyEnable")}),A.jsx("button",{onClick:()=>d(!1),className:"px-4 py-2 text-sm text-gray-500 dark:text-slate-400 hover:text-gray-700 dark:hover:text-white transition-colors duration-200",children:l("securitySettings.cancel")})]})]}):A.jsx("div",{children:n?A.jsxs("div",{className:"flex items-center justify-between",children:[A.jsxs("span",{className:"text-sm text-green-600 font-medium flex items-center",children:[A.jsx("svg",{className:"w-4 h-4 mr-1",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),l("securitySettings.twoFAActive")]}),A.jsx("button",{onClick:()=>re(null,null,function*(){const e=prompt(l("securitySettings.disablePrompt"));if(e){y(""),p(!0);try{yield a.disable2FA(e),i(!1),k(l("securitySettings.disabledSuccess")),setTimeout(()=>k(""),5e3)}catch(t){y(t.message||"Failed to disable 2FA")}finally{p(!1)}}}),disabled:b,className:"text-sm text-red-600 hover:text-red-500 font-medium",children:l("securitySettings.disable")})]}):A.jsx("button",{onClick:()=>re(null,null,function*(){y(""),p(!0);try{const e=yield a.setup2FA();e.qrCode&&(u(e.qrCode),m(e.secret),d(!0))}catch(e){y(e.message||"Failed to initiate 2FA setup")}finally{p(!0),p(!1)}}),disabled:b,className:"inline-flex items-center px-4 py-2 border border-gray-300 dark:border-slate-700 shadow-sm text-sm font-medium rounded-md text-gray-700 dark:text-slate-200 bg-white dark:bg-slate-800 hover:bg-gray-50 dark:hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors duration-200",children:l(b?"securitySettings.loading":"securitySettings.enable2FA")})})]})},le=({isActive:e,onComplete:t})=>{const s=S.useRef(null),r=S.useRef(null),a=S.useRef([]);return S.useEffect(()=>{if(!e)return;const l=s.current,n=l.getContext("2d"),i=()=>{l.width=window.innerWidth,l.height=window.innerHeight};i(),window.addEventListener("resize",i);class o{constructor(){this.x=Math.random()*l.width,this.y=-10,this.vx=8*(Math.random()-.5),this.vy=3*Math.random()+4,this.rotation=360*Math.random(),this.rotationSpeed=10*(Math.random()-.5),this.size=8*Math.random()+4,this.color=["#FF6B6B","#4ECDC4","#45B7D1","#96CEB4","#FFEAA7","#DDA0DD","#98D8C8","#F7DC6F","#BB8FCE","#85C1E9"][Math.floor(10*Math.random())],this.shape=Math.random()>.5?"square":"circle",this.opacity=1,this.fadeSpeed=.03*Math.random()+.01}update(){this.x+=this.vx,this.y+=this.vy,this.rotation+=this.rotationSpeed,this.vy+=.15,this.opacity-=this.fadeSpeed,this.vx+=.5*(Math.random()-.5)}draw(){n.save(),n.globalAlpha=this.opacity,n.translate(this.x,this.y),n.rotate(this.rotation*Math.PI/180),n.fillStyle=this.color,"square"===this.shape?n.fillRect(-this.size/2,-this.size/2,this.size,this.size):(n.beginPath(),n.arc(0,0,this.size/2,0,2*Math.PI),n.fill()),n.restore(
2)}isDead(){return this.opacity<=0||this.y>l.height+50}}const d=()=>{if(n.clearRect(0,0,l.width,l.height),a.current=a.current.filter(e=>(e.update(),e.draw(),!e.isDead())),a.current.length<30&&Date.now()-c<1e3)for(let e=0;e<3;e++)a.current.push(new o);a.current.length>0?r.current=requestAnimationFrame(d):t&&t()},c=Date.now();(()=>{for(let e=0;e<80;e++)a.current.push(new o)})(),d();const u=setTimeout(()=>{r.current&&(cancelAnimationFrame(r.current),a.current=[],t&&t())},3e3);return()=>{window.removeEventListener("resize",i),r.current&&cancelAnimationFrame(r.current),clearTimeout(u)}},[e,t]),e?A.jsx("canvas",{ref:s,style:{position:"fixed",top:0,left:0,pointerEvents:"none",zIndex:9999}}):null};var ne=Object.defineProperty,ie=Object.defineProperties,oe=Object.getOwnPropertyDescriptors,de=Object.getOwnPropertySymbols,ce=Object.prototype.hasOwnProperty,ue=Object.prototype.propertyIsEnumerable,he=(e,t,s)=>t in e?ne(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,me=(e,t)=>{for(var s in t||(t={}))ce.call(t,s)&&he(e,s,t[s]);if(de)for(var s of de(t))ue.call(t,s)&&he(e,s,t[s]);return e},ge=(e,t)=>ie(e,oe(t)),xe=(e,t,s)=>new Promise((r,a)=>{var l=e=>{try{i(s.next(e))}catch(t){a(t)}},n=e=>{try{i(s.throw(e))}catch(t){a(t)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);i((s=s.apply(e,t)).next())});const be=(e={})=>{const t=n();return me(me({},e),t?{Authorization:`Bearer ${t}`}:{})},pe=({courseId:e,courseTitle:t})=>{const[s,r]=S.useState([]),[a,n]=S.useState(null),[i,o]=S.useState(!0),[d,c]=S.useState(null),[u,h]=S.useState(!1),[m,g]=S.useState(!1),[x,b]=S.useState(0),[p,f]=S.useState([]),[y,v]=S.useState(null),[k,w]=S.useState(null),[j,N]=S.useState(!1),[C,D]=S.useState({leadName:"",leadEmail:"",ageAppropriateMode:!0}),[I,R]=S.useState(!1),[E,M]=S.useState({}),[O,P]=S.useState(null),[T,L]=S.useState(null);S.useEffect(()=>{B()},[e,x]);const z=[{status:"acknowledged",label:"Acknowledge",hint:"Seen — still being handled",needsNote:!1},{status:"actioned",label:"Action taken",hint:"Handled under school safeguarding procedures",needsNote:!0},{status:"dismissed",label:"No concern",hint:"e.g. curriculum false positive",needsNote:!0}],B=()=>xe(null,null,function*(){o(!0);try{const t=Date.now(),s=`${l}/api/courses/${e}/student-progress?t=${t}`,a=yield fetch(s,{credentials:"include",headers:be({"Content-Type":"application/json","Cache-Control":"no-cache, no-store, must-revalidate"})});if(a.ok){const e=yield a.json();r(e.students||[]),n(e.stats||null)}const i=`${l}/api/courses/${e}/security-alerts?t=${t}`,o=yield fetch(i,{credentials:"include",headers:be({"Cache-Control":"no-cache"})});if(o.ok){const e=yield o.json();f(e||[])}const d=yield fetch(`${l}/api/courses/${e}/tutor-transcripts?t=${t}`,{credentials:"include",headers:be({"Cache-Control":"no-cache"})});d.ok&&v(yield d.json());const c=yield fetch(`${l}/api/user/safeguarding-settings?t=${t}`,{credentials:"include",headers:be({"Cache-Control":"no-cache"})});c.ok&&D(yield c.json())}catch(t){}finally{o(!1)}}),$=e=>e?new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"N/A",F=e=>"number"!=typeof e||Number.isNaN(e)?0:Math.max(0,Math.min(100,Math.round(e/5*100))),_=(e,t)=>t&&0!==t?Math.round(e/t*100):0,H=e=>e.isCompleted?{color:"bg-green-500",text:"Completed"}:e.completedLessons>0?{color:"bg-blue-500",text:"In Progress"}:{color:"bg-gray-400",text:"Not Started"},U=e=>{const t=_(e.completedLessons,e.totalLessons),s=F(e.averageQuizScore),r=Object.keys(e.misconceptions||{}).length,a=e.lastActivity?new Date(e.lastActivity).getTime():0,l=a?Math.floor((Date.now()-a)/864e5):999;let n=0;const i=[];return s>0&&s<60?(n+=3,i.push("low quiz performance")):s>=60&&s<80&&(n+=1,i.push("inconsistent quiz performance")),r>=3?(n+=3,i.push("repeated misconceptions")):r>0&&(n+=1,i.push("concept gaps detected")),l>=7?(n+=2,i.push("inactive for 7+ days")):l>=3&&(n+=1,i.push("inactive for 3+ days")),t>0&&t<25&&(n+=2,i.push("early-stage stall")),t>=25&&t<70&&s<80&&(n+=1,i.push("mid-course intervention opportunity")),n>=5?{level:"High",badgeClass:"bg-red-500 text-white",panelClass:"border-red-200 bg-red-50 dark:border-red-900/40 dark:bg-red-950/20",reasons:i,nextAction:"Review misconceptions and assign a targeted reteach task.",score:n,progress:t,quizPercentage:s,misconceptionCount:r,inactiveDays:l}:n>=3?{level:"Medium",badgeClass:"bg-amber-500 text-white",panelClass:"border-amber-200 bg-amber-50 dark:border-amber-900/40 dark:bg-amber-950/20",reasons:i,nextAction:"Check in and assign retrieval practice on the weakest lesson.",score:n,progress:t,quizPercentage:s,misconceptionCount:r,inactiveDays:l}:{level:"On Track",badgeClass:"bg-emerald-500 text-white",panelClass:"border-emerald-200 bg-emerald-50 dark:border-emerald-900/40 dark:bg-emerald-950/20",reasons:i.length>0?i:["steady progress"],nextAction:"Maintain pace and extend with challenge work.",score:n,progress:t,quizPercentage:s,misconceptionCount:r,inactiveDays:l}},W=s.map(e=>ge(me({},e),{insight:U(e)})).sort((e,t)=>
2t.insight.score-e.insight.score||e.insight.progress-t.insight.progress),V=W.filter(e=>"On Track"!==e.insight.level),G=V.filter(e=>"High"===e.insight.level),Q=W.filter(e=>e.insight.misconceptionCount>0).length,Y=W.filter(e=>e.insight.inactiveDays>=3).length,q=[{title:"Reteach now",description:G[0]?`${G[0].username} needs immediate review on recent misconceptions.`:"No urgent reteach cases right now."},{title:"Target retrieval practice",description:Q>0?`${Q} learner${1===Q?"":"s"} showed answer patterns worth revisiting.`:"No active concept-gap clusters detected."},{title:"Re-engage inactive learners",description:Y>0?`${Y} learner${1===Y?"":"s"} have been inactive for at least 3 days.`:"Recent activity looks healthy across the cohort."}];return i?A.jsx("div",{className:"p-8 text-center text-gray-500 dark:text-slate-400",children:"Loading student progress..."}):A.jsxs("div",{className:"p-6 max-w-7xl mx-auto dark:text-white",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"flex justify-between items-center mb-8",children:[A.jsxs("div",{children:[A.jsx("h2",{className:"text-2xl font-bold text-gray-800 dark:text-white",children:"Student Progress Dashboard"}),A.jsxs("p",{className:"text-gray-500 dark:text-slate-400",children:["Course: ",t]})]}),A.jsxs("div",{className:"flex gap-3",children:[A.jsx("button",{onClick:()=>b(e=>e+1),className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:"🔄 Refresh"}),A.jsx("button",{onClick:()=>N(!0),className:"px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors",title:"Safeguarding settings: designated safeguarding lead and age-appropriate mode",children:"🛡️ Safeguarding"}),s.length>0&&A.jsxs(A.Fragment,{children:[A.jsx("button",{onClick:()=>{var r,l,n;const i=e=>{const t=null==e?"":String(e);return/[",\n]/.test(t)?`"${t.replace(/"/g,'""')}"`:t},o=W.filter(e=>"On Track"!==e.insight.level).length,d=[...[["Discourse AI Impact Report"],["Course",t],["Generated",(new Date).toISOString()],["Standard","DfE-Privacy-Preserving-Insights-V1 (no pupil-identifiable data)"],[],["Total learners",null!=(r=null==a?void 0:a.totalStudents)?r:s.length],["Completed course",null!=(l=null==a?void 0:a.completedStudents)?l:0],["Completion rate (%)",null!=(n=null==a?void 0:a.completionRate)?n:0],["Average quiz performance (%)",F(null==a?void 0:a.averageQuizScore)],["Learners flagged for intervention",o],["Learners with concept gaps",Q],["Learners inactive 3+ days",Y],[]],["Learner","Status","Progress (%)","Lessons completed","Total lessons","Modules completed","Total modules","Quiz performance (%)","Quizzes correct","Quizzes taken","Concept gaps","Days since last activity","Risk level","Signals"],...W.map((e,t)=>{var s,r;return[`Learner ${t+1}`,H(e).text,e.insight.progress,e.completedLessons,e.totalLessons,e.completedModules,e.totalModules,e.insight.quizPercentage,null!=(s=e.correctQuizzes)?s:"",null!=(r=e.totalQuizzes)?r:"",e.insight.misconceptionCount,999===e.insight.inactiveDays?""
2:e.insight.inactiveDays,e.insight.level,e.insight.reasons.join("; ")]})].map(e=>e.map(i).join(",")).join("\r\n"),c=new Blob([String.fromCharCode(65279)+d],{type:"text/csv;charset=utf-8"}),u=URL.createObjectURL(c),h=document.createElement("a");h.href=u,h.download=`impact_report_${e}.csv`,document.body.appendChild(h),h.click(),document.body.removeChild(h),URL.revokeObjectURL(u)},className:"px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors flex items-center gap-2",title:"Download an anonymised usage and impact summary as CSV — opens in Excel. Share with your budget holder at renewal.",children:"📊 Impact Report (CSV)"}),A.jsx("button",{onClick:()=>{const r=s.map((e,t)=>({studentId:`student_${t+1}`,progress:_(e.completedLessons,e.totalLessons),isCompleted:e.isCompleted,averageQuizScore:e.averageQuizScore,misconceptions:e.misconceptions||{}})),l={courseId:e,courseTitle:t,exportTimestamp:(new Date).toISOString(),standard:"DfE-Privacy-Preserving-Insights-V1",aggregateStats:a,studentInsights:r},n=new Blob([JSON.stringify(l,null,2)],{type:"application/json"}),i=URL.createObjectURL(n),o=document.createElement("a");o.href=i,o.download=`anonymized_insights_${e}.json`,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(i)},className:"px-4 py-2 bg-emerald-700 text-white rounded-lg hover:bg-emerald-800 transition-colors flex items-center gap-2",title:"Export Anonymized Insights as JSON (DfE Compliant)",children:"🗂 JSON"}),A.jsx("button",{onClick:()=>h(!0),className:"px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition-colors",children:"🗑️ Clear Data"})]})]})]}),a&&A.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-6 mb-10",children:[{label:"Total Students",value:a.totalStudents},{label:"Completed",value:a.completedStudents},{label:"Completion Rate",value:`${a.completionRate}%`},{label:"Quiz Performance",value:`${F(a.averageQuizScore)}%`}].map((e,t)=>A.jsxs("div",{className:"bg-white dark:bg-slate-900 p-6 rounded-xl shadow-sm border border-gray-100 dark:border-slate-800 text-center",children:[A.jsx("div",{className:"text-3xl font-bold text-gray-800 dark:text-white mb-1",children:e.value}),A.jsx("div",{className:"text-sm text-gray-500 dark:text-slate-400",children:e.label})]},t))}),A.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6 mb-10",children:[A.jsxs("div",{className:"lg:col-span-2 bg-white dark:bg-slate-900 p-6 rounded-xl shadow-sm border border-gray-100 dark:border-slate-800",children:[A.jsxs("div",{className:"flex items-center justify-between mb-4 gap-4",children:[A.jsxs("div",{children:[A.jsx("h3",{className:"text-lg font-bold text-gray-800 dark:text-white",children:"Intervention Priorities"}),A.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:"Focus on learners who are stalling, inactive, or showing repeated misconceptions."})]}),A.jsxs("div",{className:"text-sm font-semibold text-gray-600 dark:text-slate-300",children:[V.length," flagged"]})]}),0===V.length?A.jsx("div",{className:"rounded-xl border border-emerald-200 bg-emerald-50 dark:border-emerald-900/40 dark:bg-emerald-950/20 p-4 text-sm text-emerald-800 dark:text-emerald-200",children:"No students currently need intervention based on progress, activity, and quiz signals."}):A.jsx("div",{className:"space-y-3",children:V.slice(0,5).map(e=>
2A.jsxs("div",{className:`rounded-xl border p-4 ${e.insight.panelClass}`,children:[A.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-3",children:[A.jsxs("div",{children:[A.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[A.jsx("h4",{className:"font-semibold text-gray-800 dark:text-slate-100",children:e.username}),A.jsx("span",{className:`px-2 py-1 rounded text-[10px] font-bold uppercase ${e.insight.badgeClass}`,children:e.insight.level})]}),A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-300 mt-1",children:e.insight.reasons.join(" • ")})]}),A.jsx("button",{onClick:()=>c(e),className:"text-xs px-3 py-1 bg-white/80 dark:bg-slate-900/70 text-gray-700 dark:text-slate-200 rounded hover:bg-white dark:hover:bg-slate-900 transition-colors",children:"Review details"})]}),A.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3 mt-4 text-xs",children:[A.jsxs("div",{children:[A.jsx("div",{className:"text-gray-500 dark:text-slate-400",children:"Progress"}),A.jsxs("div",{className:"font-semibold text-gray-800 dark:text-slate-100",children:[e.insight.progress,"%"]})]}),A.jsxs("div",{children:[A.jsx("div",{className:"text-gray-500 dark:text-slate-400",children:"Quiz score"}),A.jsxs("div",{className:"font-semibold text-gray-800 dark:text-slate-100",children:[e.insight.quizPercentage,"%"]})]}),A.jsxs("div",{children:[A.jsx("div",{className:"text-gray-500 dark:text-slate-400",children:"Concept gaps"}),A.jsx("div",{className:"font-semibold text-gray-800 dark:text-slate-100",children:e.insight.misconceptionCount})]}),A.jsxs("div",{children:[A.jsx("div",{className:"text-gray-500 dark:text-slate-400",children:"Inactive"}),A.jsxs("div",{className:"font-semibold text-gray-800 dark:text-slate-100",children:[e.insight.inactiveDays,"d"]})]})]}),A.jsxs("div",{className:"mt-3 text-sm text-gray-700 dark:text-slate-200",children:[A.jsx("span",{className:"font-semibold",children:"Recommended next step:"})," ",e.insight.nextAction]})]},e.sessionId))})]}),A.jsxs("div",{className:"bg-white dark:bg-slate-900 p-6 rounded-xl shadow-sm border border-gray-100 dark:border-slate-800",children:[A.jsx("h3",{className:"text-lg font-bold text-gray-800 dark:text-white mb-4",children:"Teacher Playbook"}),A.jsx("div",{className:"space-y-3",children:q.map(e=>A.jsxs("div",{className:"rounded-xl border border-gray-100 dark:border-slate-800 p-4 bg-gray-50 dark:bg-slate-950/40",children:[A.jsx("div",{className:"font-semibold text-gray-800 dark:text-slate-100 mb-1",children:e.title}),A.jsx("div",{className:"text-sm text-gray-600 dark:text-slate-300",children:e.description})]},e.title))})]})]}),p.length>0&&A.jsxs("div",{className:"mb-10 animate-in slide-in-from-top-4 duration-500",children:[A.jsxs("h3",{className:"text-lg font-bold text-red-600 dark:text-red-400 mb-4 flex items-center gap-2",children:["🚨 Security Alerts (",p.length,")"]}),A.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[p.map(t=>{var s,r,a;return A.jsxs("div",{className:"p-4 rounded-xl border "+("critical"===t.severity?"bg-red-50 border-red-200 dark:bg-red-950/20 dark:border-red-900/50":"bg-orange-50 border-orange-200 dark:bg-orange-950/20 dark:border-orange-900/50"),children:[A.jsxs("div",{className:"flex justify-between items-start mb-2",children:[A.jsx("span",{className:"text-[10px] font-bold uppercase px-2 py-0.5 rounded "+("critical"===t.severity?"bg-red-500 text-white":"bg-orange-500 text-white"),children:t.type}),A.jsx("span",{className:"text-[10px] text-gray-500 dark:text-slate-400 font-mono",children:$(t.timestamp)})]}),A.jsx("p",{className:"text-sm font-medium text-gray-800 dark:text-slate-200 mb-1",children:t.detail}),A.jsxs("div",{className:"text-[10px] text-gray-500 dark:text-slate-400",children:["User: ",t.userEmail," (",null==(s=t.userId)?void 0:s.slice(-8),")"]}),"failed"===(null==(r=t.notification)?void 0:r.state)&&A.jsxs("div",{className:"mt-2 p-2 rounded-lg bg-red-100 dark:bg-red-900/40 border border-red-300 dark:border-red-800",role:"alert",children:[A.jsx("p",{className:"text-xs font-semibold text-red-800 dark:text-red-200",children:"Not delivered — no email reached a safeguarding contact."}),A.jsx("p",{className:"text-[10px] text-red-700 dark:text-red-300",children:"Check the safeguarding lead address in settings. This alert has not been seen by anyone who was not told in person."})]}),A.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-200 dark:border-slate-700",children:[A.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2",children:[A.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wide text-gray-600 dark:text-slate-300",children:"new"===t.status?"Awaiting review":"acknowledged"===t.status?"Seen — being handled":"actioned"===t.status?"Action taken":"dismissed"===t.status?"No safeguarding concern":"resolved"===t.status?"Closed":t.status}),t.closedBy&&A.jsxs("span",{className:"text-[10px] text-gray-500 dark:text-slate-400",children:["by ",t.closedBy," · ",$(t.closedAt)]})]}),(null==(a=t.history)?void 0:a.length)>0&&A.jsx("ul",{className:"mb-2 space-y-1","aria-label":"Alert history",children:t.history.map((e,t)=>A.jsxs("li",{className:"text-[10px] text-gray-600 dark:text-slate-400",children:[$(e.at)," — ",e.by," marked ",A.jsx("strong",{children:e.to}),e.note?`: ${e.note}`:""]},t))}),A.jsx("label",{className:"sr-only",htmlFor:`note-${t.id}`,children:"Decision note for this safeguarding alert"}),A.jsx("textarea",{id:`note-${t.id}`,rows:2,value:E[t.id]||"",onChange:e=>M(s=>ge(me({},s),{[t.id]:e.target.value})),placeholder:"What was decided, and why? (required to close)",className:"w-full text-xs p-2 rounded-lg border border-gray-300 dark:border-slate-600 bg-white dark:bg-slate-900 text-gray-900 dark:text-slate-100 mb-2"}),A.jsx("div",{className:"flex flex-wrap gap-2",children:z.map(s=>A.jsx("button",{type:"button",title:s.hint,disabled:O===t.id||t.status===s.status,onClick:()=>{return r=t.id,a=s.status,n=s.needsNote,xe(null,null,function*(){const t=(E[r]||"").trim();if(!n||t){L(null),P(r);try{const s=yield fetch(`${l}/api/courses/${e}/security-alerts/${r}/status`,{method:"POST",credentials:"include",headers:be({"Content-Type":"application/json"}),body:JSON.stringify({status:a,note:t})});if(!s.ok){const e=yield s.json().catch(()=>({}));throw new Error(e.error||`Update failed (${s.status})`)}const n=yield s.json();f(e=>e.map(e=>e.id===r?me(me({},e),n):e)),M(e=>ge(me({},e),{[r]:""}))}catch(s){L(s.message)}finally{P(null)}}else L("Please record what was decided and why before closing this alert.")});var r,a,n},className:"px-3 py-1 text-xs font-medium rounded-lg border border-gray-300 dark:border-slate-600 text-gray-700 dark:text-slate-200 hover:bg-gray-100 dark:hover:bg-slate-800 disabled:opacity-40 disabled:cursor-not-allowed",children:O===t.id?"Saving…":s.label},s.status))}),A.jsx("p",{className:"mt-2 text-[10px] text-gray-500 dark:text-slate-400",children:"Alerts cannot be deleted or edited — only the decision about them is recorded."})]})]},t.id)}),T&&A.jsx("p",{className:"text-xs text-red-600 dark:text-red-400",role:"alert",children:T})]})]}),y&&y.sessions&&y.sessions.length>0&&A.jsxs("div",{className:"mb-10 bg-white dark:bg-slate-900 p-6 rounded-xl shadow-sm border border-gray-100 dark:border-slate-800",children:[A.jsxs("div",{className:"flex items-center justify-between mb-4 gap-4",children:[A.jsxs("div",{children:[A.jsx("h3",{className:"text-lg font-bold text-gray-800 dark:text-white",children:"🛡️ AI Tutor Chat Transcripts"}),A.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:["Every pupil conversation with the Socratic tutor is recorded and visible here.",y.flaggedMessages>0&&A.jsxs("span",{className:"ml-1 font-semibold text-red-600 dark:text-red-400",children:[y.flaggedMessages," flagged message",1===y.flaggedMessages?"":"s"," need review."]})]})]}),A.jsxs("div",{className:"text-sm font-semibold text-gray-600 dark:text-slate-300",children:[y.totalMessages," messages"]})]}),A.jsx("div",{className:"space-y-2",children:y.sessions.map(e=>A.jsx("div",{className:"rounded-xl border p-4 "+(e.flaggedCount>0?"critical"===e.highestSeverity?"border-red-200 bg-red-50 dark:border-red-900/40 dark:bg-red-950/20":"border-amber-200 bg-amber-50 dark:border-amber-900/40 dark:bg-amber-950/20":"border-gray-100 dark:border-slate-800 bg-gray-50 dark:bg-slate-950/40"),children:A.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2",children:[A.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[A.jsx("span",{className:"font-semibold text-gray-800 dark:text-slate-100",children:e.studentName}),A.jsxs("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:[e.messageCount," messages · last active ",$(e.lastActivity)]}),e.flaggedCount>0&&A.jsxs("span",{className:"px-2 py-0.5 rounded text-[10px] font-bold uppercase text-white "+("critical"===e.highestSeverity?"bg-red-500":"bg-amber-500"),
2children:[e.flaggedCount," flagged"]})]}),A.jsx("button",{onClick:()=>w(e),className:"text-xs px-3 py-1 bg-white/80 dark:bg-slate-900/70 text-gray-700 dark:text-slate-200 rounded hover:bg-white dark:hover:bg-slate-900 transition-colors self-start sm:self-auto",children:"Read transcript"})]})},e.sessionKey))})]}),A.jsx("div",{className:"bg-white dark:bg-slate-900 rounded-xl shadow-sm border border-gray-100 dark:border-slate-800 overflow-hidden",children:A.jsx("div",{className:"overflow-x-auto",children:A.jsxs("table",{className:"w-full text-left border-collapse",children:[A.jsx("thead",{children:A.jsxs("tr",{className:"bg-gray-50 dark:bg-slate-800/50 text-gray-600 dark:text-slate-300 font-bold uppercase text-xs",children:[A.jsx("th",{className:"p-4 border-b dark:border-slate-800",children:"Student"}),A.jsx("th",{className:"p-4 border-b dark:border-slate-800",children:"Progress"}),A.jsx("th",{className:"p-4 border-b dark:border-slate-800 text-center",children:"Status"}),A.jsx("th",{className:"p-4 border-b dark:border-slate-800 text-center",children:"Quiz Score"}),A.jsx("th",{className:"p-4 border-b dark:border-slate-800",children:"Last Activity"}),A.jsx("th",{className:"p-4 border-b dark:border-slate-800 text-right",children:"Actions"})]})}),A.jsx("tbody",{children:0===s.length?A.jsx("tr",{children:A.jsx("td",{colSpan:"6",className:"p-12 text-center text-gray-500 dark:text-slate-400 italic",children:"No students have started this course yet."})}):W.map(e=>{var t;const s=H(e),r=_(e.completedLessons,e.totalLessons);return A.jsxs("tr",{className:"hover:bg-gray-50 dark:hover:bg-slate-800/30 transition-colors",children:[A.jsxs("td",{className:"p-4 border-b dark:border-slate-800",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx("div",{className:"font-semibold text-gray-800 dark:text-slate-200",children:e.username}),p.some(t=>t.userId===e.sessionId)&&A.jsx("span",{className:"text-sm",title:"Security Alert Flagged",children:"🚩"})]}),A.jsxs("div",{className:"text-[10px] font-mono text-gray-400 uppercase tracking-tighter",children:["ID: ",null==(t=e.sessionId)?void 0:t.slice(-8)]})]}),A.jsxs("td",{className:"p-4 border-b dark:border-slate-800 min-w-[150px]",children:[A.jsx("div",{className:"w-full h-2 bg-gray-100 dark:bg-slate-800 rounded-full overflow-hidden mb-1",children:A.jsx("div",{className:`h-full ${s.color} transition-all duration-500`,style:{width:`${r}%`}})}),A.jsxs("div",{className:"text-[11px] text-gray-500 dark:text-slate-400",children:[e.completedLessons,"/",e.totalLessons," lessons (",r,"%)"]})]}),A.jsx("td",{className:"p-4 border-b dark:border-slate-800 text-center",children:A.jsx("span",{className:`px-2 py-1 rounded text-[10px] font-bold text-white uppercase ${s.color}`,children:s.text})}),A.jsx("td",{className:"p-4 border-b dark:border-slate-800 text-center font-mono text-sm",children:e.totalQuizzes>0?A.jsxs("span",{className:e.insight.quizPercentage>=80?"text-green-600":e.insight.quizPercentage>=60?"text-amber-600":"text-red-600",children:[e.insight.quizPercentage,"%"]}):"—"}),A.jsx("td",{className:"p-4 border-b dark:border-slate-800 text-sm text-gray-600 dark:text-slate-400",children:$(e.lastActivity)}),A.jsx("td",{className:"p-4 border-b dark:border-slate-800 text-right",children:A.jsx("button",{onClick:()=>c(e),className:"text-xs px-3 py-1 bg-gray-100 dark:bg-slate-800 text-gray-600 dark:text-slate-300 rounded hover:bg-gray-200 dark:hover:bg-slate-700 transition-colors",children:"Details"})})]},e.sessionId)})})]})})}),d&&A.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-[100] p-4",onClick:()=>c(null),children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-2xl max-w-md w-full shadow-2xl overflow-hidden animate-in fade-in zoom-in duration-200",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"p-6 border-b dark:border-slate-800 flex justify-between items-center",children:[A.jsx("h3",{className:"text-xl font-bold",children:"Student Details"}),A.jsx("button",{onClick:()=>c(null),className:"text-gray-400 hover:text-gray-600 text-2xl",children:"×"})]}),A.jsxs("div",{className:"p-6 space-y-4",children:[[{label:"Username",value:d.username},{label:"Session ID",value:d.sessionId,mono:!0},{label:"Joined",value:$(d.startTime)},{label:"Last Active",value:$(d.lastActivity)},{label:"Lessons",value:`${d.completedLessons}/${d.totalLessons}`},{label:"Modules",value:`${d.completedModules}/${d.totalModules}`},{label:"Avg Quiz Score",value:`${d.averageQuizScore}%`},{label:"Completed",value:d.isCompleted?"✅ Yes":"❌ No"}].map((e,t)=>A.jsxs("div",{className:"flex justify-between items-center py-2 border-b border-gray-50 dark:border-slate-800 last:border-0",children:[A.jsx("span",{className:"text-sm text-gray-500 dark:text-slate-400 font-medium",children:e.label}),A.jsx("span",{className:"text-sm font-semibold "+(e.mono?"font-mono text-[10px]":""),children:e.value})]},t)),d.misconceptions&&Object.keys(d.misconceptions).length>0&&A.jsxs("div",{className:"mt-4 pt-4 border-t dark:border-slate-800 max-h-60 overflow-y-auto",children:[A.jsx("h4",{className:"text-sm font-bold text-orange-600 dar
2k:text-orange-400 mb-2 flex items-center gap-1",children:"⚠️ Misconceptions Detected"}),A.jsx("div",{className:"space-y-3",children:Object.entries(d.misconceptions).map(([e,t])=>{var s;return A.jsxs("div",{className:"bg-orange-50 dark:bg-orange-950/20 p-3 rounded-lg border border-orange-100 dark:border-orange-900/30",children:[A.jsxs("p",{className:"text-[10px] font-bold text-orange-800 dark:text-orange-300 uppercase mb-1",children:["Lesson ID: ",(null==(s=null==e?void 0:e.split("_"))?void 0:s.pop())||e]}),A.jsx("ul",{className:"space-y-1",children:Object.entries(t.answers||{}).map(([e,t])=>A.jsxs("li",{className:"text-[11px] text-gray-700 dark:text-slate-300",children:[A.jsxs("span",{className:"font-semibold text-orange-700 dark:text-orange-400",children:["Error Q",parseInt(e)+1,":"]}),' Selected "',t,'"']},e))})]},e)})})]})]})]})}),k&&A.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-[100] p-4",onClick:()=>w(null),children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-2xl max-w-2xl w-full shadow-2xl overflow-hidden animate-in fade-in zoom-in duration-200",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"p-6 border-b dark:border-slate-800 flex justify-between items-center",children:[A.jsxs("div",{children:[A.jsx("h3",{className:"text-xl font-bold",children:"Tutor Chat Transcript"}),A.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:k.studentName})]}),A.jsx("button",{onClick:()=>w(null),className:"text-gray-400 hover:text-gray-600 text-2xl",children:"×"})]}),A.jsx("div",{className:"p-6 space-y-3 max-h-[60vh] overflow-y-auto",children:k.messages.map(e=>{var t;return A.jsxs("div",{className:`p-3 rounded-xl text-sm ${"student"===e.role?"bg-blue-50 dark:bg-blue-950/30 ml-6":"bg-gray-50 dark:bg-slate-800/60 mr-6"} ${e.flagged?"border-2 border-red-400 dark:border-red-600":""}`,children:[A.jsxs("div",{className:"flex justify-between items-center mb-1 gap-2",children:[A.jsxs("span",{className:"text-[10px] font-bold uppercase text-gray-500 dark:text-slate-400",children:["student"===e.role?k.studentName:"AI Tutor",e.lessonTitle?` · ${e.lessonTitle}`:""]}),A.jsx("span",{className:"text-[10px] text-gray-400 font-mono",children:$(e.timestamp)})]}),A.jsx("p",{className:"text-gray-800 dark:text-slate-200 whitespace-pre-wrap",children:e.content}),e.flagged&&A.jsxs("div",{className:"mt-2 text-[11px] font-semibold text-red-600 dark:text-red-400",children:["🚩 Flagged",(null==(t=e.categories)?void 0:t.length)?`: ${e.categories.join(", ")}`:"",e.blocked?" — message was not sent to the AI":""]})]},e.id)})})]})}),j&&A.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-[100] p-4",onClick:()=>N(!1),children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-2xl max-w-md w-full shadow-2xl overflow-hidden animate-in fade-in zoom-in duration-200",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"p-6 border-b dark:border-slate-800 flex justify-between items-center",children:[A.jsx("h3",{className:"text-xl font-bold",children:"🛡️ Safeguarding Settings"}),A.jsx("button",{onClick:()=>N(!1),className:"text-gray-400 hover:text-gray-600 text-2xl",children:"×"})]}),A.jsxs("div",{className:"p-6 space-y-5",children:[A.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:"Flagged tutor-chat messages are emailed to your designated safeguarding lead (DSL). If none is set, alerts go to your account email."}),A.jsxs("div",{children:[A.jsx("label",{className:"block text-sm font-semibold text-gray-700 dark:text-slate-300 mb-1",children:"Safeguarding lead name"}),A.jsx("input",{type:"text",value:C.leadName,onChange:e=>D(t=>ge(me({},t),{leadName:e.target.value})),placeholder:"e.g. Jane Smith (DSL)",className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm"})]}),A.jsxs("div",{children:[A.jsx("label",{className:"block text-sm font-semibold text-gray-700 dark:text-slate-300 mb-1",children:"Safeguarding lead email"}),A.jsx("input",{type:"email",value:C.leadEmail,onChange:e=>D(t=>ge(me({},t),{leadEmail:e.target.value})),placeholder:"[email protected]",className:"w-full px-3 py-2 rounded-lg border border-gray-200 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm"})]}),A.jsxs("label",{className:"flex items-start gap-3 cursor-pointer",children:[A.jsx("input",{type:"checkbox",checked:C.ageAppropriateMode,onChange:e=>D(t=>ge(me({},t),{ageAppropriateMode:e.target.checked})),className:"mt-1"}),A.jsxs("span",{className:"text-sm text-gray-700 dark:text-slate-300",children:[A.jsx("span",{className:"font-semibold",children:"Age-appropriate mode"})," — the AI tutor uses child-safe language, refuses adult topics, and signposts pupils to trusted adults. Recommended on for all school 
2courses."]})]}),A.jsxs("div",{className:"flex gap-3 pt-2",children:[A.jsx("button",{onClick:()=>N(!1),className:"flex-1 px-4 py-2 bg-gray-100 dark:bg-slate-800 rounded-lg font-semibold",children:"Cancel"}),A.jsx("button",{onClick:()=>xe(null,null,function*(){R(!0);try{const e=yield fetch(`${l}/api/user/safeguarding-settings`,{method:"PUT",credentials:"include",headers:be({"Content-Type":"application/json"}),body:JSON.stringify(C)});if(e.ok)N(!1);else{const t=yield e.json().catch(()=>({}));alert(t.error||"Failed to save safeguarding settings")}}catch(e){alert("Failed to save safeguarding settings")}finally{R(!1)}}),disabled:I,className:"flex-1 px-4 py-2 bg-indigo-600 text-white rounded-lg font-semibold hover:bg-indigo-700",children:I?"Saving...":"Save"})]})]})]})}),u&&A.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[100] p-4",children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 p-8 rounded-2xl max-w-sm w-full shadow-2xl text-center",children:[A.jsx("div",{className:"text-4xl mb-4",children:"⚠️"}),A.jsx("h3",{className:"text-xl font-bold mb-2",children:"Clear Student Data?"}),A.jsx("p",{className:"text-gray-500 dark:text-slate-400 text-sm mb-6",children:"This will permanently delete all tracking and progress for this course. This action cannot be undone."}),A.jsxs("div",{className:"flex gap-3",children:[A.jsx("button",{onClick:()=>h(!1),className:"flex-1 px-4 py-2 bg-gray-100 dark:bg-slate-800 rounded-lg font-semibold",children:"Cancel"}),A.jsx("button",{onClick:()=>xe(null,null,function*(){g(!0);try{(yield fetch(`${l}/api/courses/${e}/clear-student-progress`,{method:"DELETE",credentials:"include",headers:be({"Content-Type":"application/json"})})).ok&&(r([]),n(null),h(!1),b(e=>e+1))}catch(t){alert("Failed to clear data")}finally{g(!1)}}),disabled:m,className:"flex-1 px-4 py-2 bg-red-500 text-white rounded-lg font-semibold hover:bg-red-600",children:m?"Clearing...":"Yes, Delete"})]})]})})]})};var fe=Object.defineProperty,ye=Object.defineProperties,ve=Object.getOwnPropertyDescriptors,ke=Object.getOwnPropertySymbols,we=Object.prototype.hasOwnProperty,je=Object.prototype.propertyIsEnumerable,Ne=(e,t,s)=>t in e?fe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,Ce=(e,t)=>{for(var s in t||(t={}))we.call(t,s)&&Ne(e,s,t[s]);if(ke)for(var s of ke(t))je.call(t,s)&&Ne(e,s,t[s]);return e},Se=(e,t)=>ye(e,ve(t)),Ae=(e,t,s)=>new Promise((r,a)=>{var l=e=>{try{i(s.next(e))}catch(t){a(t)}},n=e=>{try{i(s.throw(e))}catch(t){a(t)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);i((s=s.apply(e,t)).next())});const De=["January","February","March","April","May","June","July","August","September","October","November","December"],Ie=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],Re=[15,30,45,60,90,120];function Ee(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}const Me={type:"live_session",title:"",description:"",date:Ee(new Date),time:"10:00",durationMinutes:30,lessonId:""},Oe=({course:e,onLaunchLive:t})=>{const[s,r]=S.useState([]),[l,n]=S.useState(!0),[o,d]=S.useState(null),[c,u]=S.useState(()=>new Date),[h,m]=S.useState(null),[g,x]=S.useState(!1),[b,p]=S.useState(null),f=S.useMemo(()=>{const t=[];return((null==e?void 0:e.modules)||[]).forEach(e=>{((null==e?void 0:e.lessons)||[]).forEach(s=>{(null==s?void 0:s.id)&&t.push({lessonId:s.id,moduleId:e.id,label:`${e.title} — ${s.title}`})})}),t},[e]),y=S.useCallback(()=>Ae(null,null,function*(){if(null==e?void 0:e.id)try{const t=yield a.getCourseSchedule(e.id);r(Array.isArray(t)?t:[]),d(null)}catch(t){i.error("[CourseCalendar] Failed to load schedule:",t),d("Failed to load the schedule. Please try again.")}finally{n(!1)}}),[null==e?void 0:e.id]);S.useEffect(()=>{y()},[y]);const v=S.useMemo(()=>{const e=c.getFullYear(),t=c.getMonth(),s=new Date(e,t,1),r=new Date(e,t+1,0).getDate(),a=(s.getDay()+6)%7,l=Array(a).fill(null);for(let i=1;i<=r;i++)l.push(new Date(e,t,i));for(;l.length%7!=0;)l.push(null);const n=[];for(let i=0;i<l.length;i+=7)n.push(l.slice(i,i+7));return n},[c]),k=S.useMemo(()=>{const e={};
2return s.forEach(t=>{const s=Ee(new Date(t.startTime));(e[s]=e[s]||[]).push(t)}),e},[s]),w=S.useMemo(()=>{const e=Date.now();return[...s].filter(t=>"live"===t.status||new Date(t.startTime).getTime()>e-36e5).sort((e,t)=>new Date(e.startTime)-new Date(t.startTime)).slice(0,8)},[s]),j=e=>{m(Se(Ce({},Me),{date:e?Ee(e):Me.date}))},N=e=>{const t=new Date(e.startTime);m({editingId:e.id,type:e.type,title:e.title,description:e.description||"",date:Ee(t),time:`${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`,durationMinutes:e.durationMinutes||30,lessonId:e.lessonId||""})},C=Ee(new Date),D=e=>"live"===e.status?"bg-red-100 dark:bg-red-900/50 text-red-700 dark:text-red-300 border border-red-300 dark:border-red-700":"live_session"===e.type?"bg-blue-100 dark:bg-blue-900/50 text-blue-700 dark:text-blue-300":"bg-amber-100 dark:bg-amber-900/50 text-amber-700 dark:text-amber-300";return A.jsxs("div",{className:"p-4 sm:p-6 text-gray-900 dark:text-slate-100",children:[A.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 mb-4",children:[A.jsxs("div",{className:"flex items-center gap-2",children:[A.jsx("button",{onClick:()=>u(new Date(c.getFullYear(),c.getMonth()-1,1)),className:"w-8 h-8 rounded-full bg-gray-100 dark:bg-slate-800 hover:bg-gray-200 dark:hover:bg-slate-700 flex items-center justify-center",title:"Previous month",children:"‹"}),A.jsxs("h3",{className:"text-lg font-bold w-44 text-center",children:[De[c.getMonth()]," ",c.getFullYear()]}),A.jsx("button",{onClick:()=>u(new Date(c.getFullYear(),c.getMonth()+1,1)),className:"w-8 h-8 rounded-full bg-gray-100 dark:bg-slate-800 hover:bg-gray-200 dark:hover:bg-slate-700 flex items-center justify-center",title:"Next month",children:"›"}),A.jsx("button",{onClick:()=>u(new Date),className:"ml-1 text-xs px-2 py-1 rounded-md bg-gray-100 dark:bg-slate-800 hover:bg-gray-200 dark:hover:bg-slate-700",children:"Today"})]}),A.jsx("button",{onClick:()=>j(null),className:"px-4 py-2 rounded-lg bg-blue-600 text-white text-sm font-bold hover:bg-blue-700 shadow-sm active:scale-95",children:"+ New event"})]}),o&&A.jsx("div",{className:"mb-3 px-3 py-2 rounded-lg bg-red-50 dark:bg-red-900/30 text-red-700 dark:text-red-300 text-sm",children:o}),A.jsxs("div",{className:"grid grid-cols-7 gap-px bg-gray-200 dark:bg-slate-800 rounded-lg overflow-hidden border border-gray-200 dark:border-slate-800",children:[Ie.map(e=>A.jsx("div",{className:"bg-gray-50 dark:bg-slate-900 text-center text-xs font-semibold py-2 text-gray-500 dark:text-slate-400",children:e},e)),v.flat().map((e,t)=>{const s=e?Ee(e):`blank-${t}`,r=e&&k[s]||[];return A.jsx("div",{onClick:()=>e&&j(e),className:"min-h-[72px] p-1.5 text-left align-top "+(e?"bg-white dark:bg-slate-950 hover:bg-blue-50 dark:hover:bg-slate-900 cursor-pointer":"bg-gray-50 dark:bg-slate-900/50"),children:e&&A.jsxs(A.Fragment,{children:[A.jsx("span",{className:"text-xs font-semibold inline-flex items-center justify-center w-5 h-5 rounded-full "+(s===C?"bg-blue-600 text-white":"text-gray-500 dark:text-slate-400"),children:e.getDate()}),A.jsxs("div",{className:"mt-1 space-y-0.5",children:[r.slice(0,3).map(e=>A.jsxs("button",{onClick:t=>{t.stopPropagation(),N(e)},className:`block w-full truncate text-left text-[11px] px-1.5 py-0.5 rounded ${D(e)}`,title:e.title,children:["live"===e.status?"🔴 ":"live_session"===e.type?"🎥 ":"📝 ",e.title]},e.id)),r.length>3&&A.jsxs("span",{className:"text-[10px] text-gray-400",children:["+",r.length-3," more"]})]})]})},s)})]}),A.jsxs("div",{className:"mt-5",children:[A.jsx("h4",{className:"text-sm font-bold text-gray-700 dark:text-slate-300 mb-2",children:"Upcoming & live"}),l?A.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:"Loading schedule…"}):0===w.length?A.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:"Nothing scheduled yet. Click a day on the calendar to plan a live check-in or an assessment."}):A.jsx("ul",{className:"space-y-2",children:w.map(s=>{var r,l;return A.jsxs("li",{className:"flex flex-wrap items-center gap-2 px-3 py-2 rounded-lg border border-gray-200 dark:border-slate-800 bg-gray-50 dark:bg-slate-900",children:[A.jsx("span",{className:"text-lg",children:"live_session"===s.type?"🎥":"📝"}),A.jsxs("div",{className:"flex-1 min-w-[150px]",children:[A.jsxs("p",{className:"text-sm font-semibold truncate",children:[s.title,"live"===s.status&&A.jsx("span",{className:"ml-2 text-xs px-2 py-0.5 rounded-full bg-red-100 dark:bg-red-900/50 text-red-700 dark:text-red-300 font-bold animate-pulse",children:"LIVE"})]}),A.jsxs("p",{className:"text-xs text-gray-500 dark:text-slate-400",children:[(l=s.startTime,new Date(l).toLocaleStr
2ing(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}))," · ",s.durationMinutes," min","assessment"===s.type&&s.lessonId&&A.jsxs(A.Fragment,{children:[" · ",(null==(r=f.find(e=>e.lessonId===s.lessonId))?void 0:r.label)||"Linked lesson"]})]})]}),"live_session"===s.type&&"ended"!==s.status&&("live"===s.status?A.jsxs(A.Fragment,{children:[A.jsx("button",{onClick:()=>null==t?void 0:t(s),className:"px-3 py-1.5 rounded-lg bg-blue-600 text-white text-xs font-bold hover:bg-blue-700",children:"Join room"}),A.jsx("button",{onClick:()=>(t=>Ae(null,null,function*(){p(t.id);try{yield a.endLiveSession(e.id,t.id),yield y()}catch(s){i.error("[CourseCalendar] Failed to end live session:",s),d("Failed to end the live session.")}finally{p(null)}}))(s),disabled:b===s.id,className:"px-3 py-1.5 rounded-lg bg-red-600 text-white text-xs font-bold hover:bg-red-700 disabled:opacity-50",children:"End session"})]}):A.jsx("button",{onClick:()=>(s=>Ae(null,null,function*(){p(s.id),d(null);try{const r=yield a.startLiveSession(e.id,s.id);yield y(),null==t||t(r)}catch(r){i.error("[CourseCalendar] Failed to start live session:",r),d("Failed to start the live session.")}finally{p(null)}}))(s),disabled:b===s.id,className:"px-3 py-1.5 rounded-lg bg-green-600 text-white text-xs font-bold hover:bg-green-700 disabled:opacity-50",title:"Start the webcam session now — students on the shared course get a Join banner",children:b===s.id?"Starting…":"🔴 Go live"})),A.jsx("button",{onClick:()=>N(s),className:"px-2 py-1.5 rounded-lg bg-gray-200 dark:bg-slate-700 text-xs hover:bg-gray-300 dark:hover:bg-slate-600",children:"Edit"})]},s.id)})})]}),h&&A.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[60] p-4",onClick:()=>m(null),children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg w-full max-w-md 
2shadow-xl",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"flex justify-between items-center px-4 py-3 border-b border-gray-200 dark:border-slate-800",children:[A.jsx("h3",{className:"font-bold",children:h.editingId?"Edit event":"New event"}),A.jsx("button",{onClick:()=>m(null),className:"text-gray-500 hover:text-gray-700 dark:hover:text-slate-300 text-2xl leading-none",children:"×"})]}),A.jsxs("div",{className:"p-4 space-y-3",children:[A.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[A.jsx("button",{onClick:()=>m(Se(Ce({},h),{type:"live_session"})),className:"px-3 py-2 rounded-lg text-sm font-semibold border "+("live_session"===h.type?"bg-blue-600 text-white border-blue-600":"bg-white dark:bg-slate-800 border-gray-300 dark:border-slate-700"),children:"🎥 Live check-in"}),A.jsx("button",{onClick:()=>m(Se(Ce({},h),{type:"assessment"})),className:"px-3 py-2 rounded-lg text-sm font-semibold border "+("assessment"===h.type?"bg-amber-600 text-white border-amber-600":"bg-white dark:bg-slate-800 border-gray-300 dark:border-slate-700"),children:"📝 Assessment"})]}),A.jsx("input",{type:"text",value:h.title,onChange:e=>m(Se(Ce({},h),{title:e.target.value})),placeholder:"live_session"===h.type?"e.g. Week 2 progress check-in":"e.g. Module 1 assessment",className:"w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm",maxLength:200}),A.jsx("textarea",{value:h.description,onChange:e=>m(Se(Ce({},h),{description:e.target.value})),placeholder:"Notes for students (optional)",rows:2,className:"w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm",maxLength:1e3}),A.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[A.jsx("input",{type:"date",value:h.date,onChange:e=>m(Se(Ce({},h),{date:e.target.value})),className:"col-span-1 px-2 py-2 rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm"}),A.jsx("input",{type:"time",value:h.time,onChange:e=>m(Se(Ce({},h),{time:e.target.value})),className:"col-span-1 px-2 py-2 rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm"}),A.jsx("select",{value:h.durationMinutes,onChange:e=>m(Se(Ce({},h),{durationMinutes:Number(e.target.value)})),className:"col-span-1 px-2 py-2 rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm",children:Re.map(e=>A.jsxs("option",{value:e,children:[e," min"]},e))})]}),"assessment"===h.type&&A.jsxs("select",{value:h.lessonId,onChange:e=>m(Se(Ce({},h),{lessonId:e.target.value})),className:"w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 text-sm",children:[A.jsx("option",{value:"",children:"Whole course (no specific lesson)"}),f.map(e=>A.jsx("option",{value:e.lessonId,children:e.label},e.lessonId))]}),"assessment"===h.type&&h.lessonId&&A.jsx("p",{className:"text-xs text-gray-500 dark:text-slate-400",children:"The quiz for this lesson stays locked on the shared course until the scheduled time."})]}),A.jsxs("div",{className:"flex justify-between items-center px-4 py-3 border-t border-gray-200 dark:border-slate-800",children:[h.editingId?A.jsx("button",{onClick:()=>{return t=s.find(e=>e.id===h.editingId),Ae(null,null,function*(){if(window.confirm(`Delete "${t.title}"?`)){p(t.id);try{yield a.deleteScheduleEvent(e.id,t.id),m(null),yield y()}catch(s){i.error("[CourseCalendar] Failed to delete event:",s),d("Failed to delete the event.")}finally{p(null)}}});var t},disabled:b===h.editingId,className:"px-3 py-2 rounded-lg text-sm text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50",children:"Delete"}):A.jsx("span",{}),A.jsxs("div",{className:"flex gap-2",children:[A.jsx("button",{onClick:()=>m(null),className:"px-4 py-2 rounded-lg text-sm bg-gray-100 dark:bg-slate-800 hover:bg-gray-200 dark:hover:bg-slate-700",children:"Cancel"}),A.jsx("button",{onClick:()=>Ae(null,null,function*(){var t;if(!(null==(t=null==h?void 0:h.title)?void 0:t.trim()))return void d("Please enter a title for the event.");const s=new Date(`${h.date}T${h.time}`);if(isNaN(s.getTime()))return void d("Please pick a valid date and time.");const r=f.find(e=>e.lessonId===h.lessonId),l={type:h.type,title:h.title.trim(),description:h.description,startTime:s.toISOString(),durationMinutes:Number(h.durationMinutes)||30,lessonId:"assessment"===h.type&&h.lessonId||null,moduleId:"assessment"===h.type&&(null==r?void 0:r.moduleId)||null};x(!0),d(null);try{h.editingId?yield a.updateScheduleEvent(e.id,h.editingId,l):yield a.createScheduleEvent(e.id,l),m(null),yield y()}catch(n){i.error("[CourseCalendar] Failed to save event:",n),d("Failed to save the event. Please try again.")}finally{x(!1)}}),disabled:g,className:"px-4 py-2 rounded-lg text-sm font-bold bg-blue-600 text-white hover:bg-blue-700 disabled:opacity-50",children:g?"Saving…":h.editingId?"Save changes":"Create event"})]})]})]})})]})},Pe=({title:e,children:t,defaultOpen:s=!1})=>{const[r,a]=S.useState(s);return A.jsxs("div",{className:"help-menu bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg mb-4 shadow-sm overflow-hidden transition-colors duration-300",children:[A.jsxs("div",{className:"help-menu-header flex justify-between items-center p-4 cursor-pointer hover:bg-slate-50 dark:hover:bg-slate-700/50 transition-colors duration-200",onClick:()=>a(!r),children:[A.jsxs("div",{className:"help-menu-title flex items-center gap-2",children:[A.jsx("span",{className:"help-icon text-lg",children:"💡"}),A.jsx("span",{className:"help-title font-semibold text-slate-700 dark:text-slate-200 text-base",children:e})]}),A.jsx("div",{className:"help-menu-toggle font-bold text-slate-500 dark:text-slate-400 w-6 h-6 flex items-center justify-center rounded transition-colors duration-200",children:r?"−":"+"})]}),r&&A.jsx("div",{className:"help-menu-content p-5 pt-0 border-t border-slate-100 dar
2k:border-slate-700 bg-slate-50/30 dark:bg-slate-900/10",children:A.jsx("div",{className:"pt-4",children:t})})]})},Te=()=>A.jsxs("div",{className:"help-section bg-slate-50 dark:bg-slate-900 border border-slate-200 dark:border-slate-800 rounded-xl p-6 mb-6 transition-colors duration-300",children:[A.jsxs("div",{className:"help-section-header text-center mb-6",children:[A.jsx("h3",{className:"text-2xl font-bold text-slate-900 dark:text-white mb-2",children:"📚 Quick Help Guide"}),A.jsx("p",{className:"text-slate-600 dark:text-slate-400",children:"Need help getting started? Check out these guides below."})]}),A.jsx(Pe,{title:"How to Generate Your First Course",defaultOpen:!0,children:A.jsxs("div",{className:"help-content text-slate-700 dark:text-slate-300 leading-relaxed",children:[A.jsx("p",{children:"Creating a custom course with Discourse AI is simple:"}),A.jsxs("ol",{className:"list-decimal my-4 pl-6 space-y-2",children:[A.jsxs("li",{children:[A.jsx("strong",{children:'Click "Generate New Course"'})," - Located at the top of your dashboard"]}),A.jsxs("li",{children:[A.jsx("strong",{children:"Describe what you want to learn"})," - Be specific about your interests and goals"]}),A.jsxs("li",{children:[A.jsx("strong",{children:"Choose your preferences"})," - Select difficulty level and course structure"]}),A.jsxs("li",{children:[A.jsx("strong",{children:"Wait for generation"})," - Our AI will create your course in 2-5 minutes"]}),A.jsxs("li",{children:[A.jsx("strong",{children:"Start learning!"})," - Your course will appear on your dashboard"]})]}),A.jsxs("div",{className:"help-tips bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-900/30 rounded-lg p-4 mt-4",children:[A.jsx("h4",{className:"font-bold text-amber-900 dark:text-amber-400 mb-3",children:"💡 Tips for Better Results:"}),A.jsxs("ul",{className:"list-disc pl-6 space-y-1",children:[A.jsx("li",{children:"Be specific about your interests and goals"}),A.jsx("li",{children:"Mention any prerequisites or background knowledge"}),A.jsx("li",{children:"Include examples of what you want to learn"}),A.jsx("li",{children:"Specify if you prefer practical or theoretical content"})]})]})]})}),A.jsx(Pe,{title:"Course Generation Examples",children:A.jsxs("div",{className:"help-content text-slate-700 dark:text-slate-300 leading-relaxed",children:[A.jsx("p",{children:"Here are some example prompts to get you started:"}),A.jsxs("div",{className:"example-prompts grid gap-5 mt-4",children:[A.jsxs("div",{className:"example-category bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-3 text-base",children:"📚 Academic Subjects"}),A.jsxs("ul",{className:"list-disc pl-6 space-y-1 text-sm italic text-slate-500 dark:text-slate-400",children:[A.jsx("li",{children:'"Create a course about the history of ancient Rome from 753 BCE to 476 CE"'}),A.jsx("li",{children:'"Teach me about machine learning basics for beginners"'}),A.jsx("li",{children:'"Generate a course on organic chemistry fundamentals"'})]})]}),A.jsxs("div",{className:"example-category bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-3 text-base",children:"🎨 Creative Skills"}),A.jsxs("ul",{className:"list-disc pl-6 space-y-1 text-sm italic text-slate-500 dark:text-slate-400",children:[A.jsx("li",{children:'"I want to learn how to write science fiction stories"'}),A.jsx("li",{children:'"Create a course on digital photography techniques"'}),A.jsx("li",{children:'"Teach me about graphic design principles"'})]})]}),A.jsxs("div",{className:"example-category bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-3 text-base",children:"💼 Professional Development"}),A.jsxs("ul",{className:"list-disc pl-6 space-y-1 text-sm italic text-slate-500 dark:text-slate-400",children:[A.jsx("li",{children:'"Generate a course on project management fundamentals"'}),A.jsx("li",{children:'"Teach me about effective leadership strategies"'}),A.jsx("li",{children:'"Create a course on public speaking skills"'})]})]})]})]})}),A.jsx(Pe,{title:"Navigating Your Courses",children:A.jsxs("div",{className:"help-content text-slate-700 dark:text-slate-300 leading-relaxed",children:[A.jsx("p",{children:"Once you have courses, here's how to make the most of them:"}),A.jsxs("div",{className:"navigation-tips grid gap-4 mt-4",children:[A.jsxs("div",{className:"tip-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"📖 Reading Lessons"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Click on any lesson to start reading. Use the navigation arrows to move between lessons."})]}),A.jsxs("div",{className:"tip-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"🧠 Taking Quizzes"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Complete quizzes at the end of each lesson to test your knowledge and reinforce learning."})]}),A.jsxs("div",{className:"tip-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"📊 Tracking Progress"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Your progress is automatically saved. Return to any course anytime to continue where you left off."})]}),A.jsxs("div",{className:"tip-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"🔄 Course Management"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Use the course actions menu to edit, duplicate, or delete courses as needed."})]})]})]})}),A.jsx(Pe,{title:"Advanced Features",children:A.jsxs("div",{className:"help-content text-slate-700 dark:text-slate-300 leading-relaxed",children:[A.jsx("p",{children:"Explore these advanced features to enhance your learning experience:"}),A.jsxs("div",{className:"advanced-features grid gap-4 mt-4",children:[A.jsxs("div",{className:"feature-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"📤 Publishing Courses"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Make your courses public so others can learn from them. Great for sharing knowledge!"})]}),A.jsxs("div",{className:"feature-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"📊 Student Analytics"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"For published courses, track student progress and engagement with detailed analytics."})]}),A.jsxs("div",{className:"feature-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"🏆 Certificates"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Students can earn certificates upon completing your published courses."})]}),A.jsxs("div",{className:"feature-item bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 rounded-lg p-4 transition-colors",children:[A.jsx("h4",{className:"font-bold text-slate-900 dark:text-white mb-2 text-base",children:"🔄 Course Duplication"}),A.jsx("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:"Duplicate existing courses to create variations or build upon successful content."})]})]})]})})]});var Le,ze;(ze=Le||(Le={})).Default="DEFAULT",ze.Destructive="DESTRUCTIVE",ze.Cancel="CANCEL";const Be=Le,$e=o("ActionSheet",{web:()=>d(()=>import("./web-Cc7o-ryu.js"),__vite__mapDeps([0,1,2,3,4])).then(e=>new e.ActionSheetWeb)}),Fe=o("Dialog",{web:()=>d(()=>import("./web-BQesvTZ3.js"),__vite__mapDeps([5,1,2,3,4])).then(e=>new e.DialogWeb)});function _e(){const{t:e}=s(),[t,r]=S.useState({loading:!0,due:[],summary:null,failed:!1}),l=S.useCallback(()=>{return e=null,t=null,s=function*(){try{const e=yield a.getReviewQueue(20);r({loading:!1,due:(null==e?void 0:e.due)||[],summary:(null==e?void 0:e.summary)||null,failed:!1})}catch(e){r({loading:!1,due:[],summary:null,failed:!0})}},new Promise((r,a)=>{var l=e=>{try{i(s.next(e))}catch(t){a(t)}},n=e=>{try{i(s.throw(e))}catch(t){a(t)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);i((s=s.apply(e,t)).next())});var e,t,s},[]);if(S.useEffect(()=>{l()},[l]),t.loading||t.failed)return null;const n=t.summary||{};if(!((n.total||0)>0))return null;const i=t.due.length,o=t.due.reduce((e,t)=>
2{const s=t.courseId||"unknown";return e[s]||(e[s]={courseId:t.courseId,courseTitle:t.courseTitle,items:[]}),e[s].items.push(t),e},{});return A.jsxs("div",{"data-tour":"review-queue",className:"bg-white dark:bg-slate-900 rounded-lg shadow-sm border border-gray-200 dark:border-slate-800 p-6 mb-6",children:[A.jsxs("div",{className:"flex items-start justify-between gap-4 mb-4",children:[A.jsxs("div",{children:[A.jsx("h2",{className:"text-lg font-bold text-gray-900 dark:text-white",children:e("review.title")}),A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mt-1",children:e(i>0?"review.subtitleDue":"review.subtitleClear")})]}),i>0&&A.jsx("span",{className:"shrink-0 px-3 py-1 rounded-full bg-blue-600 text-white text-sm font-bold",children:i})]}),0===i?A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400",children:n.nextDueAt?`${e("review.nextReview")}: ${new Date(n.nextDueAt).toLocaleDateString()}`:e("review.allClear")}):A.jsx("ul",{className:"space-y-2",children:Object.values(o).map(t=>A.jsx("li",{children:A.jsxs(I,{to:`/course/${t.courseId}`,className:"flex items-center justify-between p-3 rounded-lg bg-gray-50 dark:bg-slate-800 hover:bg-gray-100 dark:hover:bg-slate-700 transition-colors",children:[A.jsx("span",{className:"text-sm font-medium text-gray-900 dark:text-white truncate mr-3",children:t.courseTitle||e("review.untitledCourse")}),A.jsxs("span",{className:"shrink-0 text-xs text-blue-700 dark:text-blue-300",children:[t.items.length," ",e("review.itemsDue")]})]})},t.courseId||"unknown"))}),A.jsxs("div",{className:"mt-4 pt-4 border-t border-gray-100 dark:border-slate-800 flex flex-wrap gap-x-6 gap-y-1 text-xs text-gray-500 dark:text-slate-400",children:[A.jsxs("span",{children:[e("review.tracked"),": ",n.total||0]}),A.jsxs("span",{children:[e("review.secure"),": ",n.secure||0]}),(n.confidentWrong||0)>0&&A.jsxs("span",{className:"text-amber-600 dark:text-amber-400",children:[e("review.calibrationGaps"),": ",n.confidentWrong]})]})]})}var He=Object.defineProperty,Ue=Object.defineProperties,We=Object.getOwnPropertyDescriptors,Ve=Object.getOwnPropertySymbols,Ge=Object.prototype.hasOwnProperty,Qe=Object.prototype.propertyIsEnumerable,Ye=(e,t,s)=>t in e?He(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s,qe=(e,t)=>{for(var s in t||(t={}))Ge.call(t,s)&&Ye(e,s,t[s]);if(Ve)for(var s of Ve(t))Qe.call(t,s)&&Ye(e,s,t[s]);return e},Je=(e,t)=>Ue(e,We(t)),Ke=(e,t,s)=>new Promise((r,a)=>{var l=e=>{try{i(s.next(e))}catch(t){a(t)}},n=e=>{try{i(s.throw(e))}catch(t){a(t)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(l,n);i((s=s.apply(e,t)).next())});const Xe=()=>{var a,n,o,D,I,L,z;const B=S.useCallback(e=>e&&Array.isArray(e.modules)?e.modules.reduce((e,t)=>e+(Array.isArray(null==t?void 0:t.lessons)?t.lessons:[]).reduce((e,t)=>{var s;const r=Array.isArray(null==t?void 0:t.quiz)&&t.quiz.length>0,a=Array.isArray(null==(s=null==t?void 0:t.content)?void 0:s.quiz)&&t.content.quiz.length>0;return e+(r||a?1:0)},0),0):0,[]),$=S.useCallback(e=>B(e)>=1,[B]),{hapticImpactLight:F,hapticSuccess:_,showActionSheet:H,isNative:U}=(()=>{const t=r.isNativePlatform();return{hapticImpactLight:()=>e(null,null,function*(){t&&(yield c.impact({style:h.Light}).catch(()=>{}))}),hapticImpactMedium:()=>e(null,null,function*(){t&&(yield c.impact({style:h.Medium}).catch(()=>{}))}),hapticSuccess:()=>e(null,null,function*(){t&&(yield c.notification({type:u.Success}).catch(()=>{}))}),hapticError:()=>e(null,null,function*(){t&&(yield c.notification({type:u.Error}).catch(()=>{}))}),hapticSelection:()=>e(null,null,function*(){t&&(yield c.selectionStart().catch(()=>{}))}),nativeAlert:(s,r,a="OK")=>e(null,null,function*(){t?yield Fe.alert({title:s,message:r,buttonTitle:a}):window.alert(`${s?s+"\n":""}${r}`)}),nativeConfirm:(s,r,a="OK",l="Cancel")=>e(null,null,function*(){if(t){const{value:e}=yield Fe.confirm({title:s,message:r,okButtonTitle:a,cancelButtonTitle:l});return e}return window.confirm(`${s?s+"\n":""}${r}`)}),showActionSheet:(s,r)=>e(null,null,function*(){if(t){const e=r.map(e=>({title:e.title,style:e.style||Be.Default}));e.find(e=>e.style===Be.Cancel)||e.push({title:"Cancel",style:Be.Cancel});const{index:t}
2=yield $e.showActions({title:s,options:e}),a=e[t];return a.style===Be.Cancel?null:r.findIndex(e=>e.title===a.title)}{const e=r.find(e=>"DESTRUCTIVE"===e.style||e.style===Be.Destructive);return e&&window.confirm(s)?r.indexOf(e):null}}),isNative:t}})(),{user:W,logout:V,authToken:G}=t(),Q=R(),[Y,q]=S.useState(()=>{try{if(null==W?void 0:W.id){const e=localStorage.getItem(`savedCourses_${W.id}`);if(e)return JSON.parse(e)}else{const e=localStorage.getItem("user");if(e){const t=JSON.parse(e);if(null==t?void 0:t.id){const e=localStorage.getItem(`savedCourses_${t.id}`);if(e)return JSON.parse(e)}}}}catch(e){}return[]}),[J,K]=S.useState(""),[X,Z]=S.useState(null),[ee,te]=S.useState(!1),[se]=S.useState(()=>{const e=m();return e&&g(),e}),[re,ne]=S.useState(!1),[ie,oe]=S.useState(!1),[de,ce]=S.useState(null),[ue,he]=S.useState(!1),[me,ge]=S.useState(null),[xe,be]=S.useState(null),fe=S.useRef(!1),ye=S.useRef(0),ve=S.useRef([]),ke=S.useRef(!1),[we,je]=S.useState(!1),Ne=j(),[Ce,Se]=S.useState(!1),Ae=new URLSearchParams(window.location.search),[De,Ie]=S.useState(()=>{try{if(null==W?void 0:W.id){return"true"===localStorage.getItem(`onboardingCompleted_${W.id}`)}{const e=localStorage.getItem("user");if(e){const t=JSON.parse(e);if(null==t?void 0:t.id){return"true"===localStorage.getItem(`onboardingCompleted_${t.id}`)}}}}catch(e){}return!1}),[Re,Ee]=S.useState(!1),[Me,Pe]=S.useState(!1),[Le,ze]=S.useState(""),[He,Ue]=S.useState(null),[We,Ve]=S.useState(!1),[Ge,Qe]=S.useState(!1),[Ye,Xe]=S.useState(""),[Ze,et]=S.useState(!1),[tt,st]=S.useState(!1),[rt,at]=S.useState(null),[lt,nt]=S.useState(!1),[it,ot]=S.useState(!1),[dt,ct]=S.useState(null),[ut,ht]=S.useState(null),[mt,gt]=S.useState([]),[xt,bt]=S.useState(!1),[pt,ft]=S.useState(!1),[yt,vt]=S.useState(""),[kt,wt]=S.useState(""),[jt,Nt]=S.useState(""),[Ct,St]=S.useState(null),[At,Dt]=S.useState(!1),[It,Rt]=S.useState([]),[Et,Mt]=S.useState(""),[Ot,Pt]=S.useState(""),[Tt,Lt]=S.useState(""),[zt,Bt]=S.useState("sandbox"),[$t,Ft]=S.useState(""),[_t,Ht]=S.useState(""),[Ut,Wt]=S.useState(!1),[Vt,Gt]=S.useState(null),[Qt,Yt]=S.useState(!1),[qt,Jt]=S.useState(null),[Kt,Xt]=S.useState(null),[Zt,es]=S.useState(null),[ts,ss]=S.useState(0),[rs,as]=S.useState(0),[ls,ns]=S.useState(0),[is,os]=S.useState(null),[ds,cs]=S.useState(null),[us,hs]=S.useState(!1),ms=S.useRef(null),[gs,xs]=S.useState(null),[bs,ps]=S.useState(!1),[fs,ys]=S.useState("neutral"),{status:vs}=x(),{t:ks,translateDynamic:ws,isEnglish:js}=s(),[Ns,Cs]=S.useState({});S.useEffect(()=>{ys(re||ie?"thinking":Me?"success":de?"worried":"neutral")},[re,ie,Me,de]);const[Ss,As]=S.useState(null),[Ds,Is]=S.useState(!1),[Rs,Es]=S.useState(!1),[Ms,Os]=S.useState(!1),Ps=S.useCallback(()=>Ke(null,null,function*(){try{i.debug("👤 [DASHBOARD] Fetching user profile from backend...");const t=yield Ne.getCurrentUser();if(t){if(i.debug("✅ [DASHBOARD] User profile fetched:",{id:t.id,name:t.name,email:t.email,courseCredits:t.courseCredits,hasCredits:void 0!==t.courseCredits&&null!==t.courseCredits}),void 0===t.courseCredits||null===t.courseCredits){i.debug("⚠️ [DASHBOARD] courseCredits missing from profile, fetching separately...");try{const e=yield Ne.getUserCredits();e&&void 0!==e.credits&&(t.courseCredits=e.credits,i.debug("✅ [DASHBOARD] Credits fetched separately:",e.credits))}catch(e){i.warn("⚠️ [DASHBOARD] Failed to fetch credits separately:",e)}}As(t)}}catch(t){i.error("❌ [DASHBOARD] Error fetching user profile:",t)}}),[Ne]),Ts=S.useCallback(()=>Ke(null,null,function*(){var e,t,s,r,a;try{bt(!0),vt("");const l=yield Ne.getMISSchoolStatus();ht(l),gt(Array.isArray(null==l?void 0:l.syncLogs)?l.syncLogs:[]);const n=(null==(e=null==l?void 0:l.defaults)?void 0:e.arbor)||{},i=(null==(s=null==(t=null==l?void 0:l.school)?void 0:t.mis)?void 0:s.mode)||n.mode||"sandbox";Bt(i),Ft((null==(a=null==(r=null==l?void 0:l.school)?void 0:r.mis)?void 0:a.apiBaseUrl)||n.apiBaseUrl||"")}catch(l){vt((null==l?void 0:l.message)||"Failed to load MIS status")}finally{bt(!1)}}),[Ne]),Ls=S.useCallback(()=>Ke(null,null,function*(){var e,t;try{if(!(null==(e=null==ut?void 0:ut.school)?void 0:e.id)||"school_admin"!==(null==(t=null==ut?void 0:ut.user)?void 0:t.schoolRole))return void Rt([]);const s=yield Ne.getSchoolTeachers();Rt(Array.isArray(null==s?void 0:s.teachers)?s.teachers:[])}catch(s){i.warn("⚠️ [DASHBOARD] Failed to load school teachers:",(null==s?void 0:s.message)||s),Rt([])}}),[Ne,null==(a=null==ut?void 0:ut.school)?void 0:a.id,null==(n=null==ut?void 0:ut.user)?void 0:n.schoolRole]);S.useCallback(()=>Ke(null,null,function*(){const e=kt.trim();if(e)try{ft(!0),vt(""),yield Ne.createSchoolTenant(e),wt(""),yield Ts(),ze(ks("dashboardSettings.toastSchoolCreated")),Pe(!0)}catch(t){vt((null==t?void 0:t.message)||"Failed to create school tenant")}finally{ft(!1)}else vt("Please enter a school name.")}),[Ne,kt,Ts]),S.useCallback(()=>Ke(null,null,function*(){const e=jt.trim().toUpperCase();if(e)try{ft(!0),vt(""),yield Ne.redeemSchoolConnectionCode(e),Nt(""),yield Promise.all([Ts(),Ps()]),ze(ks("dashboardSettings.toastCodeRedeemed")),Pe(!0)}catch(t){vt((null==t?void 0:t.message)||"Failed to redeem connection code")}finally{ft(!1)}else vt("Please enter a connection code.")}),[Ne,jt,Ts,Ps]),S.useCallback(()=>Ke(null,null,function*(){var e;try{const t=null==(e=null==ut?void 0:ut.school)?void 0:e.id;if(!t)return void vt("School not found for this user.");ft(!0),vt("");const s=yield Ne.generateSchoolConnectionCode(t);St(s),yield Ts()}catch(t){vt((null==t?void 0:t.message)||"Failed to generate connection code")}finally{ft(!1)}}),[Ne,null==(o=null==ut?void 0:ut.school)?void 0:o.id,Ts]),S.useCallback(()=>Ke(null,null,function*(){try{Dt(!0),vt("");const e=yield Ne.createSchoolPackageCheckoutSession();if(null==e?void 0:e.url)return void(window.location.href=e.url);throw new Error((null==e?void 0:e.error)||"Failed to create school package checkout session")}catch(e){vt((null==e?void 0:e.message)||"Failed to start school package checkout")}finally{Dt(!1)}}),[Ne]),S.useCallback(()=>Ke(null,null,function*(){const e=Et.trim().toLowerCase(),t=Ot.trim();if(e)try{Dt(!0),Lt(""),yield Ne.inviteSchoolTeacher({email:e,name:t}),Mt(""),Pt(""),yield Promise.all([Ts(),Ls()]),ze(ks("dashboardSettings.toastTeacherInvited")),Pe(!0)}catch(s){Lt((null==s?void 0:s.message)||"Failed to invite teacher")}finally{Dt(!1)}else Lt("Please enter a teacher email address.")}),[Ne,Et,Ot,Ts,Ls]),S.useCallback(e=>Ke(null,null,function*(){try{Dt(!0),Lt(""),yield Ne.resetSchoolTeacherPassword(e),yield Ls(),ze(ks("dashboardSettings.toastTeacherReset")),Pe(!0)}catch(t){Lt((null==t?void 0:t.message)||"Failed to reset teacher password")}finally{Dt(!1)}}),[Ne,Ls]),S.useCallback(()=>Ke(null,null,function*(){try{ft(!0),vt(""),yield Ne.connectArborMIS({mode:zt,apiBaseUrl:$t.trim(),apiKey:_t.trim()}),Ht(""),yield Ts(),ze(ks("dashboardSettings.toastArborConnected")),Pe(!0)}catch(e){vt((null==e?void 0:e.message)||"Failed to connect Arbor")}finally{ft(!1)}}),[Ne,zt,$t,_t,Ts]),S.useCallback(()=>Ke(null,null,function*(){try{ft(!0),vt(""),yield Ne.syncArborMIS(),yield Ts(),ze(ks("dashboardSettings.toastArborSynced")),Pe(!0)}catch(e){vt((null==e?void 0:e.message)||"Arbor sync failed")}finally{ft(!1)}}),[Ne,Ts]),S.useCallback(()=>Ke(null,null,function*(){try{ft(!0),vt(""),yield Ne.disconnectArborMIS(),yield Ts(),ze(ks("dashboardSettings.toastArborDisconnected")),Pe(!0)}catch(e){vt((null==e?void 0:e.message)||"Failed to disconnect Arbor")}finally{ft(!1)}}),[Ne,Ts]);const zs=()=>Ke(null,null,function*(){var e;try{if(Os(!0),F(),b("checkout_started",{product:"credits",platform:w()?"ios_iap":"stripe",credits_remaining:null!=(e=null==Ss?void 0:Ss.courseCredits)?e:null},{send_instantly:!0}),w()){(yield N.purchaseCredits()).success&&(ze("10 credits added to your account!"),Pe(!0),yield Ps())}else{const e=yield Ne.createCheckoutSession();if(!e||!e.url)throw new Error((null==e?void 0:e.error)||"Failed to create checkout session");window.location.href=e.url}}catch(t){ce("Purchase failed: "+(t.message||"Unknown error"))}finally{Os(!1)}}),Bs=()=>Ke(null,null,function*(){var e;try{if(ot(!0),F(),b("checkout_started",{product:"subscription",platform:w()?"ios_iap":"stripe",credits_remaining:null!=(e=null==Ss?void 0:Ss.courseCredits)?e:null},{send_instantly:!0}),!w()){const e=yield Ne.createSubscriptionCheckoutSession();if(e&&e.url)return void(window.location.href=e.url);throw new Error((null==e?void 0:e.error)||"Failed to create subscription checkout session")}const t=yield N.purchaseSubscription();t.success&&t.hasPro&&(ze("Subscription activated! You now have Pro access."),Pe(!0),_(),yield Ps())}catch(t){ce("Subscription failed: "+(t.message||"Unknown error"))}finally{ot(!1)}}),$s=S.useCallback((e,t=5e3)=>{ze(e),Pe(!0),window.successToastTimeout&&clearTimeout(window.successToastTimeout),window.successToastTimeout=setTimeout(()=>{Pe(!1),window.successToastTimeout=null},t)},[]),Fs=S.useCallback(()=>Ke(null,null,function*(){if(window.confirm("Are you sure you want to clear the entire image search cache? This will force the AI to re-search images for all c
2ourses.")){Es(!0);try{const e=yield Ne.clearCache(null,"all");if(!e.success)throw new Error(e.error||"Failed to clear cache");$s(`Cache cleared successfully! ${e.clearedCount||0} entries removed.`,6e3)}catch(e){ce(e.message||"Failed to clear cache. Please try again.")}finally{Es(!1)}}}),[Ne,$s]),_s=S.useCallback(()=>{Pe(!1),ze(""),window.successToastTimeout&&(clearTimeout(window.successToastTimeout),window.successToastTimeout=null)},[]),Hs=S.useCallback(()=>Ke(null,null,function*(){try{const e=yield Ne.getUserCredits();e&&void 0!==e.credits&&As(t=>Je(qe({},t||{}),{courseCredits:e.credits}))}catch(e){i.warn("⚠️ [DASHBOARD] Failed to refresh credits:",(null==e?void 0:e.message)||e)}}),[Ne]),Us=((e,t)=>{if(t&&t.trim())return t.split(" ").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ");if(e&&e.includes("@")){const t=e.split("@")[0];return t.includes(".")?t.split(".").map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" "):t.charAt(0).toUpperCase()+t.slice(1).toLowerCase()}return"Guest"})(null==W?void 0:W.email,(null==Ss?void 0:Ss.name)||(null==W?void 0:W.name));if(i.debug("👤 [DASHBOARD] User data:",{user:W,userProfile:Ss,userName:Us,originalName:(null==Ss?void 0:Ss.name)||(null==W?void 0:W.name),originalEmail:null==W?void 0:W.email,hasName:!!(null==Ss?void 0:Ss.name),hasEmail:!!(null==W?void 0:W.email),timestamp:(new Date).toISOString()}),i.debug("👤 [DASHBOARD] Name formatting:",{inputName:(null==Ss?void 0:Ss.name)||(null==W?void 0:W.name),inputEmail:null==W?void 0:W.email,formattedName:Us,formatFunction:"formatUserName called"}),S.useEffect(()=>{ve.current=Y},[Y]),S.useEffect(()=>{ke.current=we},[we]),!W)return A.jsx("div",{className:"text-center mt-10 text-gray-500",children:"Loading user..."});const Ws=e=>{const t=((null==e?void 0:e.title)||"").toLowerCase(),s=String((null==e?void 0:e.id)||"");return t.includes("welcome to discourse ai")||t.includes("onboarding")||s.includes("discourse-ai-onboarding")||s.startsWith("onboarding_")},Vs=Array.isArray(Y)?Y.filter(e=>!(Ws(e)&&De)&&$(e)):[],Gs=J.trim().toLowerCase(),Qs=Gs?Vs.filter(e=>[null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.subject].filter(
2Boolean).join(" ").toLowerCase().includes(Gs)):Vs,Ys=S.useCallback((e=!1)=>Ke(null,null,function*(){if(ke.current&&!e)return void i.debug("🔄 [DASHBOARD] Skipping fetch - already loading courses");fe.current=!0;const t=ye.current+1;let s;ye.current=t,je(!0),ce(null);try{const e=new Promise((e,t)=>{s=setTimeout(()=>t(new Error("Request timeout")),1e4)});i.debug("📡 [DASHBOARD] Making API call to getSavedCourses...");const a=Ne.getSavedCourses(),l=yield Promise.race([a,e]);if(t!==ye.current)return void i.debug("🔄 [DASHBOARD] Ignoring stale saved courses response");i.debug("✅ [DASHBOARD] Successfully fetched saved courses",{coursesCount:Array.isArray(l)?l.length:0,courses:Array.isArray(l)?l.map(e=>({id:e.id,title:e.title,published:e.published,publishedType:typeof e.published})):[],timestamp:(new Date).toISOString()});const n=Array.isArray(l)?l:[],o=n.filter(e=>$(e)),d=ve.current;if(i.info("🔄 [DASHBOARD] Main course fetch comparison:",{previousCount:d.length,newCount:n.length,previousCourses:d.map(e=>({id:e.id,title:e.title})),newCourses:n.map(e=>({id:e.id,title:e.title})),timestamp:(new Date).toISOString()}),q(o),null==W?void 0:W.id)try{localStorage.setItem(`savedCourses_${W.id}`,JSON.stringify(o))}catch(r){i.error("Failed to cache saved courses in localStorage:",r)}ce(null);const c=o.filter(e=>{if(!e.createdAt)return!1;return new Date(e.createdAt)>new Date(Date.now()-3e5)});c.length>0&&(i.info("🎉 [DASHBOARD] Found recent courses, showing success message:",c.map(e=>e.title)),$s(`Found ${c.length} recently generated course${c.length>1?"s":""}!`,3e3))}catch(a){if(i.error("❌ [DASHBOARD] Error fetching saved courses:",{error:a.message,stack:a.stack,timestamp:(new Date).toISOString()}),t!==ye.current)return void i.debug("🔄 [DASHBOARD] Ignoring stale saved courses error");if(ve.current.length>0)return void i.warn("⚠️ [DASHBOARD] Saved courses refresh failed, keeping existing courses visible");ce("Failed to load courses. Please try refreshing the page.")}finally{clearTimeout(s),t===ye.current&&je(!1)}}),[Ne,$s]);S.useEffect(()=>()=>{Se(!1)},[]),S.useEffect(()=>()=>{window.successToastTimeout&&(clearTimeout(window.successToastTimeout),window.successToastTimeout=null),Pe(!1),ze("")},[null==W?void 0:W.id]),S.useEffect(()=>{W&&(i.debug("🔗 [DASHBOARD] SSE notifications disabled, using standard course fetching"),i.debug("🔗 [DASHBOARD] Course generation notifications disabled, using standard course fetching"))},[W,Ne,Ce]),S.useEffect(()=>{let e=null;if(ie&&ms.current){const t=ms.current;i.info(`🔍 [DASHBOARD] Starting generation polling for ${t}`);const s=Date.now(),r=9e5;e=setInterval(()=>Ke(null,null,function*(){var a,l,n;try{if(Date.now()-s>r){i.warn("⚠️ [DASHBOARD] Max monitoring time reached"),clearInterval(e),oe(!1),ne(!1),os(null),ms.current=null,ce("Course generation is taking longer than expected. If it completed, it will appear in your courses shortly — refresh to check. If not, your credit has been returned and you can try again."),te(!0);try{yield Hs()}catch(o){}return}const n=yield Ne.getGenerationStatus(t);if(i.debug("📊 [DASHBOARD] Generation status:",null==n?void 0:n.status,null==(a=null==n?void 0:n.progress)?void 0:a.message),(null==n?void 0:n.progress)&&os(n.progress),"completed"===(null==n?void 0:n.status)){i.info("🎉 [DASHBOARD] Course generation completed!"),clearInterval(e);try{const e=yield Ne.getSavedCourses();Array.isArray(e)&&q(e.filter(e=>$(e)))}catch(o){}try{yield Hs()}catch(o){}ce(null),ne(!1),oe(!1),te(!1),os(null),ms.current=null,$s((null==(l=n.progress)?void 0:l.message)||"Course generated successfully!",6e3)}else if("failed"===(null==n?void 0:n.status)){i.error("❌ [DASHBOARD] Generation failed:",n.error),clearInterval(e),ce(n.error||"Course generation failed. Your credit has been refunded."),ne(!1),oe(!1),te(!0),os(null),ms.current=null;try{yield Hs()}catch(o){}}}catch(d){if(404===(null==d?void 0:d.status)||"GENERATION_SESSION_UNKNOWN"===(null==(n=null==d?void 0:d.data)?void 0:n.code)){i.error("❌ [DASHBOARD] Generation session is gone; stopping poll"),clearInterval(e),oe(!1),ne(!1),os(null),ms.current=null,ce("We lost track of this course generation, most likely because the server restarted. Your credit has been returned — please try again."),te(!0);try{yield Hs()}catch(o){}return}i.warn("⚠️ [DASHBOARD] Poll error (will retry):",null==d?void 0:d.message)}}),3e3)}return()=>{e&&(clearInterval(e),i.info("🛑 [DASHBOARD] Stopped generation polling"))}},[ie,Ne]),S.useEffect(()=>{if(W&&Y.length>0){const e=Y.filter(e=>{if(!e.createdAt)return!1;return new Date(e.createdAt)>new Date(Date.now()-6e5)});if(e.length>0&&!Me){const t=`welcomeBackShown_${W.id}`,s=localStorage.getItem(t),r=Date.now()-18e5;if(!s||parseInt(s)<r){i.info("🎉 [DASHBOARD] Found recently generated courses on dashboard load:",e.map(e=>
2e.title)),ze(`Welcome back! You have ${e.length} recently generated course${e.length>1?"s":""} available.`),Pe(!0),localStorage.setItem(t,Date.now().toString());const s=setTimeout(()=>{Pe(!1)},5e3);return()=>{clearTimeout(s),window.successToastTimeout&&(clearTimeout(window.successToastTimeout),window.successToastTimeout=null)}}i.debug("🔄 [DASHBOARD] Welcome back message already shown recently, skipping")}}},[W,Y]),S.useEffect(()=>{Ke(null,null,function*(){if(v.isNative()){const e=yield v.getDeviceInfo();ct(e)}})},[]),S.useEffect(()=>{!js&&Y&&0!==Y.length?Ke(null,null,function*(){const e={};for(const s of Y)try{const[t,r]=yield Promise.all([s.title?ws(s.title):Promise.resolve(s.title),s.description?ws(s.description):Promise.resolve(s.description)]);e[s.id]={title:t,description:r}}catch(t){i.warn(`Failed to translate course ${s.id}:`,t)}Cs(e)}):Cs({})},[Y,js,ws]);const qs=S.useCallback(e=>Ke(null,null,function*(){var t,s;i.debug("🎯 [COURSE GENERATION] Starting course generation",{params:e,timestamp:(new Date).toISOString(),user:null==W?void 0:W.id}),ne(!0),ce(null),he(!1),os(null);try{yield Ys(!0)}catch(n){}const r=e.numModules||3,a=e.numLessonsPerModule||3,l=Math.min(600,Math.max(60,r*a*15+30));ss(l),as(Date.now()),ns(l);try{const t=yield Ne.generateCourse(e.prompt,e.difficultyLevel||"intermediate",r,a,e.isProgrammingCourse);if(i.info("✅ [COURSE GENERATION] Generation accepted:",t),null==t?void 0:t.generationId)ms.current=t.generationId,b("course_generation_started",{modules:r,lessons:a,difficulty:e.difficultyLevel||"intermediate",isProgrammingCourse:!!e.isProgrammingCourse}),g(),te(!1),oe(!0),os({stage:"starting",message:"Initialising course generation...",currentModule:0,totalModules:r,currentLesson:0,totalLessons:a});else if(null==t?void 0:t.course){i.info("✅ [COURSE GENERATION] Course returned directly");try{const e=yield Ne.getSavedCourses();Array.isArray(e)&&q(e.filter(e=>$(e)))}catch(n){}try{yield Hs()}catch(n){}ne(!1),te(!1),$s("Course generated successfully!",6e3)}}catch(o){i.error("💥 [COURSE GENERATION] API call failed:",o.message),400===o.status&&(null==(t=o.message)?void 0:t.includes("content policy"))?ce("Inappropriate content please try again"):402===o.status?"SUBSCRIPTION_REQUIRED"===(null==(s=o.data)?void 0:s.code)?(he(!0),ce(o.message||"A paid £20/month subscription is required before you can generate courses.")):ce("Insufficient course credits. Please purchase more credits to generate courses."):ce(o.message||"Failed to start course generation. Please try again."),te(!0),ne(!1),oe(!1),os(null),ms.current=null,ss(0),ns(0)}}),[Ne,null==W?void 0:W.id,Ys]);S.useEffect(()=>{if(!W)return;const e=setInterval(()=>{try{Hs()}catch(e){}},6e4);return()=>clearInterval(e)},[W,Hs]),S.useEffect(()=>{if(!re||!rs||!ts)return;const e=()=>{const e=Math.floor((Date.now()-rs)/1e3),t=Math.max(0,ts-e);ns(t)};e();const t=setInterval(e,1e3);return()=>clearInterval(t)},[re,rs,ts]);const Js=S.useCallback(e=>Ke(null,null,function*(){try{hs(!0),F(),i.debug("🧹 [DASHBOARD] Clearing sessions for course:",e);const t=yield Ne.clearStudentProgress(e);i.debug("✅ [DASHBOARD] Session clearing completed:",t),t.success&&(cs(null),$s(`Successfully cleared sessions and progress! (${t.clearedSessions||0} entries removed)`),Ps())}catch(t){i.error("❌ [DASHBOARD] Error clearing sessions:",t),cs(null),alert("Failed to clear sessions: "+(t.message||"Unknown error"))}finally{hs(!1)}}),[Ne,F,$s,Ps]),Ks=S.useCallback(e=>Ke(null,null,function*(){if(!He){Ue(e.id),ce(null);try{const t=yield Ne.exportCourseScorm(e.id);i.debug("📦 [DASHBOARD] SCORM package downloaded:",t),ze(ks("dashboard.scormExportReady",{defaultValue:"SCORM package downloaded."})),Pe(!0),setTimeout(()=>Pe(!1),3e3)}catch(t){i.error("❌ [DASHBOARD] SCORM export failed:",t),ce(402===(null==t?void 0:t.status)?"A paid subscription is required to export courses to SCORM.":(null==t?void 0:t.message)||"Failed to export this course to SCORM.")}finally{Ue(null)}}}),[He,ks]),Xs=S.useCallback(e=>Ke(null,null,function*(){try{ce(null),i.debug("🗑️ [DASHBOARD] Deleting course:",e);const s=yield Ne.deleteCourse(e);i.debug("✅ [DASHBOARD] Course deletion API call completed:",s);try{yield Ys(!0)}catch(t){i.warn("⚠️ [DASHBOARD] Immediate post-delete refresh failed:",null==t?void 0:t.message)}ge(null)}catch(s){i.error("❌ [DASHBOARD] Error deleting course:",s),ge(null),s.message&&!s.message.includes("Course not found")?ce(s.message||"Failed to delete course"):Ys(!0)}}),[Ne,Ys]),[Zs,er]=S.useState(null),[tr,sr]=S.useState(()=>{try{return!!(null==W?void 0:W.id)&&"true"===localStorage.getItem(`academyBannerDismissed_${W.id}`)}catch(e){return!1}});S.useEffect(()=>{let e=!1;return Ne.getAcademyStatus().then(t=>{e||er(t)}).catch(()=>{}),()=>{e=!0}},[Ne]);const rr=S.useCallback(()=>Ke(null,null,function*(){try{const e=yield Ne.getOnboardingStatus(),t=!!(null==e?void 0:e.completed);Ie(t),(null==W?void 0:W.id)&&localStorage.setItem(`onboardingCompleted_${W.id}`,String(t))}catch(e){const t=(null==W?void 0:W.id)?localStorage.getItem(`onboardingCompleted_${W.id}`):localStorage.getItem("onboardingCompleted");Ie("true"===t)}}),[Ne,null==W?void 0:W.id]);S.useEffect(()=>{try{const e=new URLSearchParams(window.location.search);if("success"===e.get("payment")||"success"===e.get("subscription")){"success"===e.get("subscription")&&(he(!1),ce(null),$s("Subscription activated! You can keep generating courses.",6e3)),"function"==typeof Hs&&Hs();const t=window.location.pathname;window.history.replaceState({},document.title,t),ze("Payment successful! Your credits are updated."),Pe(!0),setTimeout(()=>Pe(!1),5e3)}}catch(e){}if(W){const e=setTimeout(()=>{Ps(),rr()},300);return()=>clearTimeout(e)}},[W,Ps,rr]),S.useEffect(()=>{if(null==W?void 0:W.id)try{const e=localStorage.getItem(`onboardingCompleted_${W.id}`);null!==e&&Ie("true"===e);const t=localStorage.getItem(`savedCourses_${W.id}`);t&&q(JSON.parse(t))}catch(e){}},[null==W?void 0:W.id]),S.useEffect(()=>{if(W)try{ce(null);const e=setTimeout(()=>{if(Ys(!0),"completed"===Ae.get("onboarding")){const e=window.location.pathname;window.history.replaceState({},document.title,e);(()=>Ke(null,null,function*(){try{yield rr(),yield Ys(!0),b("onboarding_completed"),ze("🎉 Congratulations! You have completed the onboarding course. Welcome to Discourse AI!"),Pe(!0),setTimeout(()=>Pe(!1),8e3)}catch(e){}}))()}},500);return()=>clearTimeout(e)}catch(e){i.error("❌ [DASHBOARD] Error in initial data fetch:",e)}},[W,Ys]),S.useEffect(()=>{var e,t;
2Ge&&"school_admin"===(null==(e=null==ut?void 0:ut.user)?void 0:e.schoolRole)&&(null==(t=null==ut?void 0:ut.school)?void 0:t.id)&&Ls()},[Ge,null==(D=null==ut?void 0:ut.user)?void 0:D.schoolRole,null==(I=null==ut?void 0:ut.school)?void 0:I.id,Ls]),S.useEffect(()=>{if(!W)return;const e="1"===Ae.get("create");(se||e)&&(te(!0),e&&window.history.replaceState({},document.title,window.location.pathname))},[null==W?void 0:W.id]);const ar=()=>Ke(null,null,function*(){try{i.debug("🎓 [ONBOARDING] Starting onboarding course"),b("onboarding_started"),ce(null),he(!1);const e=yield Ne.getOnboardingCourse();i.debug("🎓 [ONBOARDING] Onboarding course fetched successfully:",e.id),localStorage.setItem("currentCourseId",e.id),Q(`/course/${e.id}`)}catch(e){if(i.error("🎓 [ONBOARDING] Error starting onboarding course:",e),404===(null==e?void 0:e.status))return void ce("Onboarding is not available for this account (it may already be completed).");ce("Could not start the onboarding course: "+(e.message||"please try again."))}});return A.jsxs("div",{className:"min-h-screen bg-gray-100 dark:bg-slate-950 transition-colors duration-300",children:[A.jsx(le,{isActive:Re,onComplete:()=>{Ee(!1),setTimeout(()=>{q(e=>[...e])},100)}}),A.jsx("nav",{className:`sticky top-0 z-40 transition-all duration-300 ${U?"pt-[env(safe-area-inset-top)]":""} bg-white/80 dark:bg-slate-900/80 backdrop-blur-md border-b border-gray-200 dark:border-slate-800 shadow-sm`,children:A.jsx("div",{className:"max-w-7xl mx-auto px-4 sm:px-6 lg:px-8",children:A.jsxs("div",{className:"flex justify-between items-center h-16",children:[A.jsx("div",{className:"flex items-center",children:A.jsx("h1",{className:"text-lg sm:text-xl font-bold text-blue-600 dark:text-blue-400",children:"Dashboard"})}),A.jsxs("div",{className:"flex items-center space-x-1 sm:space-x-3",children:[A.jsxs("span",{className:"hidden md:block text-sm text-gray-600 dark:text-slate-400 mr-2",children:[ks("dashboard.welcome"),", ",Us,"!"]}),A.jsx(p,{}),A.jsx("button",{className:"p-2 text-gray-600 dark:text-slate-400 hover:bg-gray-100 dark:hover:bg-slate-800 rounded-full transition-colors",onClick:()=>Q("/inclusivity-settings"),title:"Inclusivity Settings","aria-label":"Inclusivity Settings",children:A.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"})})}),A.jsx("button",{onClick:()=>Qe(!0),className:"p-2 text-gray-600 dark:text-slate-400 hover:bg-gray-100 dark:hover:bg-slate-800 rounded-full transition-colors",title:"Account Settings",children:A.jsxs("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:[A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"}),A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"})]})}),A.jsxs("button",{onClick:()=>{V(),Q("/login")},"aria-label":ks("dashboard.logout"),title:ks("dashboard.logout"),className:"flex items-center gap-1.5 p-2 sm:px-3 sm:py-1.5 text-sm font-medium text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 rounded-lg transition-colors",children:[A.jsx("svg",{className:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"})}),A.jsx("span",{className:"hidden sm:inline",children:ks("dashboard.logout")})]})]})]})})}),A.jsxs("main",{className:"max-w-7xl mx-auto py-2 sm:px-6 lg:px-8",children:[Me&&A.jsx("div",{className:"fixed top-4 right-4 z-50 bg-green-500 text-white px-6 py-3 rounded-lg shadow-lg transform transition-all duration-300 ease-in-out",children:A.jsxs("div",{className:"flex items-center space-x-2",children:[A.jsx("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),A.jsx("span",{className:"font-medium",children:Le}),A.jsx("button",{onClick:_s,className:"ml-2 text-white hover:text-green-100 transition-colors duration-200",title:"Dismiss notification",children:A.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M6 18L18 6M6 6l12 12"})})})]})}),A.jsx(P,{tourId:"dashboard",userId:null==W?void 0:W.id,autoStart:!we&&0===Y.filter(e=>!Ws(e)).length}),A.jsxs("div",{className:"flex items-center justify-between mb-6 bg-white dark:bg-slate-900 p-3 sm:p-4 roun
2ded-lg shadow-sm border border-gray-200 dark:border-slate-800 wrap-on-mobile transition-colors",children:[A.jsxs("div",{className:"flex items-center space-x-2 sm:space-x-4 wrap-on-mobile",children:[A.jsxs("div",{"data-tour":"credits",className:"text-sm sm:text-lg font-semibold text-gray-700 dark:text-slate-200",children:[ks("dashboard.tokens"),": ",A.jsx("span",{className:0===(null!=(L=null==Ss?void 0:Ss.courseCredits)?L:0)?"text-red-500":"text-green-600",children:null!=(z=null==Ss?void 0:Ss.courseCredits)?z:ks("dashboard.loading")})]}),A.jsxs("button",{onClick:Ps,className:"text-xs sm:text-sm text-gray-500 dark:text-slate-400 hover:text-gray-700 dark:hover:text-slate-200 transition-colors duration-200 flex items-center space-x-1",title:"Refresh user data and token count",children:[A.jsx("svg",{className:"h-3 w-3 sm:h-4 sm:w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),A.jsx("span",{className:"hidden sm:inline",children:ks("dashboard.refresh")})]}),A.jsx("div",{className:"h-8 w-px bg-gray-200 dark:bg-slate-700 mx-2"}),A.jsx("div",{"data-tour":"gamification",className:"flex-1 max-w-xs",children:A.jsx(E,{})}),A.jsxs("button",{onClick:zs,disabled:Ms,className:"text-xs sm:text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 px-3 py-1 rounded-md transition-colors duration-200 flex items-center space-x-1 shadow-sm",title:"Purchase 10 additional course credits",children:[A.jsx("svg",{className:"h-3 w-3 sm:h-4 sm:w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})}),A.jsx("span",{children:ks(Ms?"dashboard.processing":"dashboard.buyCredits")})]}),"[email protected]"===(null==W?void 0:W.email)&&A.jsxs("button",{onClick:Fs,disabled:Rs,className:"text-xs sm:text-sm transition-colors duration-200 flex items-center space-x-1 "+(Rs?"text-gray-400":"text-red-500 hover:text-red-700"),title:"Admin Tool: Clear the entire image search cache",children:[A.jsx("svg",{className:"h-3 w-3 sm:h-4 sm:w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),A.jsx("span",{className:"hidden sm:inline",children:Rs?"Clearing...":"Clear Cache"})]})]}),void 0===(null==Ss?void 0:Ss.courseCredits)&&A.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400",children:"Token count loading..."})]}),A.jsx(_e,{}),(()=>{const e=null==W?void 0:W.id,t=!!e&&"true"===localStorage.getItem(`onboardingCompleted_${e}`),s=De||t,r=e?localStorage.getItem(`savedCourses_${e}`):null;let a=[];if(r)try{a=JSON.parse(r)}catch(l){}return(Y.length>0?Y:a).length>0||s?null:A.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 text-blue-800 dark:text-blue-200 px-4 py-3 rounded-lg mb-4",children:A.jsxs("div",{className:"flex items-start",children:[A.jsx("div",{className:"flex-shrink-0",children:A.jsx("svg",{className:"h-5 w-5 text-blue-400",viewBox:"0 0 20 20",fill:"currentColor",children:A.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})}),A.jsxs("div",{className:"ml-3",children:[A.jsxs("h3",{className:"text-sm font-medium text-blue-800 dark:text-blue-200",children:["Welcome to Discourse AI, ",Us,"! 🎓"]}),A.jsx("div",{className:"mt-2 text-sm text-blue-700 dark:text-blue-300",children:A.jsx("p",{children:"Let's get your first course built. This short onboarding walks you through it step by step — by the end you'll have created a real course you can teach from."})}),A.jsx("div",{className:"mt-3",children:A.jsx("button",{onClick:ar,className:"inline-flex items-center px-3 py-2 border border-transparent text-sm font-medium rounded-md text-blue-700 dark:text-blue-300 bg-blue-100 dar
2k:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",title:"Complete onboarding to unlock the full dashboard experience",children:"🎓 Start Onboarding Course"})})]})]})})})(),(()=>{const e=null==W?void 0:W.id,t=!!e&&"true"===localStorage.getItem(`onboardingCompleted_${e}`),s=De||t,r=e?localStorage.getItem(`savedCourses_${e}`):null;let a=[];if(r)try{a=JSON.parse(r)}catch(h){}const l=Y.length>0?Y:a,n=Array.isArray(l)?l.filter(e=>!Ws(e)).length:0,i=s||n>0,o=e&&"true"===localStorage.getItem(`onboardingChecklistDismissed_${e}`);if(i||We||o)return null;const d=[{label:"Create your account",done:!0,action:null,cta:null},{label:"Complete the onboarding course",done:s,action:ar,cta:"Start"},{label:"Create your first course",done:n>0,action:()=>te(!0),cta:"Create"}],c=d.filter(e=>e.done).length,u=d.find(e=>!e.done);return A.jsxs("div",{"data-tour":"checklist",className:"bg-white dark:bg-slate-900 border border-gray-200 dark:border-slate-800 rounded-lg p-5 mb-4",children:[A.jsxs("div",{className:"flex items-center justify-between mb-1",children:[A.jsx("h3",{className:"text-sm font-semibold text-gray-800 dark:text-slate-100",children:"Get started with Discourse AI"}),A.jsxs("div",{className:"flex items-center gap-3",children:[A.jsxs("span",{className:"text-xs text-gray-500 dark:text-slate-400",children:[c,"/",d.length," complete"]}),A.jsx("button",{onClick:()=>{Ve(!0),(null==W?void 0:W.id)&&localStorage.setItem(`onboardingChecklistDismissed_${W.id}`,"true")},className:"text-xs text-gray-400 hover:text-gray-600 dark:hover:text-slate-200","aria-label":"Dismiss checklist",children:"Dismiss"})]})]}),A.jsx("div",{className:"w-full h-1.5 bg-gray-100 dark:bg-slate-800 rounded-full mb-4",children:A.jsx("div",{className:"h-1.5 bg-blue-600 rounded-full transition-all duration-300",style:{width:c/d.length*100+"%"}})}),A.jsx("ul",{className:"space-y-2",children:d.map((e,t)=>{const s=u&&e.label===u.label;return A.jsxs("li",{className:"flex items-center justify-between",children:[A.jsxs("span",{className:"flex items-center gap-2 text-sm "+(e.done?"text-gray-400 line-through":"text-gray-700 dark:text-slate-200"),children:[A.jsx("span",{className:"inline-flex items-center justify-center w-5 h-5 rounded-full text-xs "+(e.done?"bg-green-500 text-white":"bg-gray-200 dark:bg-slate-700 text-gray-500 dark:text-slate-300"),children:e.done?"✓":t+1}),e.label,s&&A.jsx("span",{className:"ml-1 text-xs font-medium text-blue-600 dark:text-blue-400",children:"— do this next"})]}),!e.done&&e.action&&A.jsx("button",{onClick:e.action,className:"text-xs font-medium px-3 py-1 rounded-md transition-colors "+(s?"bg-blue-600 text-white hover:bg-blue-700":"text-blue-600 hover:bg-blue-50 dark:hover:bg-slate-800"),children:e.cta})]},t)})})]})})(),De&&!tr&&!(null==Zs?void 0:Zs.certificate)&&A.jsxs("div",{className:"bg-gradient-to-r from-blue-50 to-indigo-50 dark:from-blue-900/20 dark:to-indigo-900/20 border border-blue-200 dark:border-blue-800 rounded-lg px-5 py-4 mb-4 flex flex-col sm:flex-row sm:items-center gap-3",children:[A.jsxs("div",{className:"flex-1",children:[A.jsxs("h3",{className:"text-sm font-semibold text-blue-900 dark:text-blue-200",children:["🎓 ",(null==Zs?void 0:Zs.enrolled)?"Finish your Trainer certification":"Become a Discourse Certified Trainer"]}),A.jsx("p",{className:"text-sm text-blue-700 dark:text-blue-300 mt-1",children:(null==Zs?void 0:Zs.enrolled)?`You're ${Zs.quizzesPassed}/${Zs.quizzesTotal} quizzes in — finish the free Teacher Academy course to claim your LinkedIn-ready certificate.`:"Free certification for heads of department and subject leaders — earn a verifiable, LinkedIn-ready credential with CPD hours."})]}),A.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[A.jsx("button",{onClick:()=>Q("/academy"),className:"text-sm font-medium px-4 py-2 rounded-md bg-blue-600 text-white hover:bg-blue-700 transition-colors",children:(null==Zs?void 0:Zs.enrolled)?"Continue":"Get certified"}),A.jsx("button",{onClick:()=>{sr(!0),(null==W?void 0:W.id)&&localStorage.setItem(`academyBannerDismissed_${W.id}`,"true")}
2,className:"text-xs text-blue-400 hover:text-blue-600 dark:hover:text-blue-200","aria-label":"Dismiss Teacher Academy banner",children:"Dismiss"})]})]}),0===Vs.length&&De&&A.jsx(Te,{}),Vs.length>0&&De&&A.jsx("div",{className:"mb-6",children:A.jsxs("details",{className:"bg-gray-50 dark:bg-slate-900 border border-gray-200 dark:border-slate-800 rounded-lg transition-colors",children:[A.jsxs("summary",{className:"px-4 py-3 cursor-pointer text-gray-700 dark:text-slate-300 font-medium hover:bg-gray-100 dark:hover:bg-slate-800 transition-colors",children:["💡 ",ks("dashboard.needHelp")]}),A.jsx("div",{className:"px-4 pb-4",children:A.jsx(Te,{})})]})}),!1,!1,ee?A.jsx("div",{className:"bg-white dark:bg-slate-900 shadow sm:rounded-lg border border-gray-200 dark:border-slate-800",children:A.jsxs("div",{className:"px-4 py-5 sm:p-6",children:[A.jsx("div",{className:"flex items-center justify-between mb-4",children:A.jsxs("div",{className:"flex items-center space-x-3",children:[A.jsxs("button",{onClick:()=>te(!1),className:"inline-flex items-center px-3 py-2 border border-gray-300 dark:border-slate-700 shadow-sm text-sm leading-4 font-medium rounded-md text-gray-700 dark:text-slate-200 bg-white dark:bg-slate-800 hover:bg-gray-50 dark:hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-colors",disabled:re,children:[A.jsx("svg",{className:"w-4 h-4 mr-2",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M10 19l-7-7m0 0l7-7m-7 7h18"})}),ks("dashboard.backToDashboard")]}),A.jsx("h3",{className:"text-lg leading-6 font-medium text-gray-900 dark:text-white",children:ks("dashboard.generateNewCourse")})]})}),A.jsxs("div",{className:"mt-4",children:[de&&A.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 px-4 py-3 rounded-lg mb-4",children:[de,ue&&A.jsxs("div",{className:"mt-2",children:[A.jsx("p",{className:"text-sm mb-2",children:"Your course is one click away — unlock generation with a subscription, or top up credits (1 credit = 1 full course)."}),A.jsxs("div",{className:"flex flex-wrap gap-2",children:[A.jsx("button",{onClick:Bs,disabled:it,className:"text-sm bg-blue-600 text-white px-3 py-1 rounded-md hover:bg-blue-700",children:it?"Processing...":"Subscribe now"}),A.jsx("button",{onClick:zs,disabled:Ms,className:"text-sm bg-white dark:bg-slate-800 text-blue-700 dark:text-blue-300 border border-blue-600 dark:border-blue-500 px-3 py-1 rounded-md hover:bg-blue-50 dark:hover:bg-slate-700",children:Ms?"Processing...":"Buy credits"})]})]})]}),A.jsx(k,{onGenerateCourse:qs,onCancel:()=>te(!1),isGenerating:re,error:de,initialPrompt:se||""})]})]})}):A.jsxs("div",{className:"space-y-6",children:[A.jsxs("div",{className:"flex flex-col md:flex-row md:items-center md:justify-between gap-4",children:[A.jsxs("div",{className:"flex items-center space-x-4",children:[A.jsx(f,{mood:fs,size:"sm",level:(null==vs?void 0:vs.level)||1}),A.jsx("h2",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:ks("dashboard.savedCourses")}),A.jsx("button",{onClick:()=>{i.debug("🔄 [DASHBOARD] Manual refresh triggered by user"),Ys(!0)},disabled:we,className:"text-sm text-gray-500 dark:text-slate-400 hover:text-gray-700 dark:hover:text-slate-200 disabled:opacity-50 transition-colors duration-200",title:"Refresh courses",children:A.jsx("svg",{className:"h-5 w-5 "+(we?"animate-spin":""),fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})})})]}),A.jsx("button",{"data-tour":"new-course",onClick:()=>{F(),te(!0)},className:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:ks("dashboard.generateNewCourse")})]}),de&&A.jsxs("div",{className:"bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 text-red-700 dark:text-red-300 px-4 py-3 rounded-lg mb-4",children:[de,ue&&A.jsxs("div",{className:"mt-2",children:[A.jsx("p",{className:"text-sm mb-2",children:"Your course is one click away — unlock generation with a subscription, or top up credits (1 credit = 1 full course)."}),A.jsxs("div",{className:"flex flex-wrap gap-2",children:[A.jsx("button",{onClick:Bs,disabled:it,className:"text-sm bg-blue-600 text-white px-3 py-1 rounded-md hover:bg-blue-700",children:it?"Processing...":"Subscribe now"}),A.jsx("button",{onClick:zs,disabled:Ms,className:"text-sm bg-white dark:bg-slate-800 text-blue-700 dark:text-blue-300 border border-blue-600 dar
2k:border-blue-500 px-3 py-1 rounded-md hover:bg-blue-50 dark:hover:bg-slate-700",children:Ms?"Processing...":"Buy credits"})]})]}),(de.includes("SSL")||de.includes("Mixed Content")||de.includes("Backend server is unreachable"))&&A.jsx("div",{className:"mt-2",children:A.jsx("button",{onClick:runConnectionDiagnostic,className:"text-sm bg-red-600 text-white px-3 py-1 rounded-md hover:bg-red-700",children:"Run Connection Diagnostic"})})]}),bs&&A.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50",children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 p-6 rounded-lg max-w-md w-full mx-4 border border-gray-200 dark:border-slate-800",children:[A.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Connection Diagnostic"}),gs&&A.jsxs("div",{className:"p-4 rounded-md mb-4 "+("success"===gs.status?"bg-green-100 dark:bg-green-900/40 text-green-700 dark:text-green-300":"error"===gs.status?"bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-300":"bg-blue-100 dark:bg-blue-900/40 text-blue-700 dark:text-blue-300"),children:[A.jsx("div",{className:"font-medium",children:gs.message}),gs.details&&A.jsx("div",{className:"text-sm mt-1",children:gs.details}),gs.suggestion&&A.jsxs("div",{className:"text-sm mt-2 font-medium",children:["Suggestion: ",gs.suggestion]})]}),A.jsxs("div",{className:"text-sm text-gray-600 dark:text-slate-400 mb-4",children:[A.jsxs("p",{children:[A.jsx("strong",{children:"Backend URL:"})," ",l]}),A.jsxs("p",{children:[A.jsx("strong",{children:"Frontend Protocol:"})," ",window.location.protocol]}),A.jsxs("p",{children:[A.jsx("strong",{children:"Mixed Content Risk:"})," ","https:"===window.location.protocol&&l.startsWith("http:")?"Yes":"No"]})]}),A.jsxs("div",{className:"flex space-x-3",children:[A.jsx("button",{onClick:runConnectionDiagnostic,className:"bg-blue-600 text-white px-4 py-2 rounded-md hover:bg-blue-700",disabled:"testing"===(null==gs?void 0:gs.status),children:"testing"===(null==gs?void 0:gs.status)?"Testing...":"Test Again"}),A.jsx("button",{onClick:()=>ps(!1),className:"bg-gray-100 dark:bg-slate-800 text-gray-700 dark:text-slate-300 px-4 py-2 rounded-md hover:bg-gray-200 dark:hover:bg-slate-700 transition-colors",children:"Close"})]})]})}),we?A.jsx(y,{count:6}):0===Vs.length?A.jsx("div",{className:"text-center py-12 bg-white dark:bg-slate-900 rounded-lg shadow-sm border-2 border-dashed border-gray-300 dark:border-slate-700 transition-colors duration-300",children:A.jsxs("div",{className:"max-w-md mx-auto",children:[A.jsx("svg",{className:"mx-auto h-12 w-12 text-gray-400 dark:text-slate-500",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 6.253v13m0-13C10.832 5.477 9.246 5 7.5 5S4.168 5.477 3 6.253v13C4.168 18.477 5.754 18 7.5 18s3.332.477 4.5 1.253m0-13C13.168 5.477 14.754 5 16.5 5c1.746 0 3.332.477 4.5 1.253v13C19.832 18.477 18.246 18 16.5 18c-1.746 0-3.332.477-4.5 1.253"})}),A.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900 dark:text-white",children:ks("dashboard.noCourses")}),A.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-slate-400",children:ks("dashboard.noCoursesDesc")}),A.jsx("div",{className:"mt-6 space-y-3",children:A.jsx("button",{onClick:()=>te(!0),className:"inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500",children:ks("dashboard.generateFirstCourse")})})]})}):A.jsx("div",{className:"bg-white dark:bg-slate-900 shadow overflow-hidden sm:rounded-md border border-gray-200 dark:border-slate-800 transition-colors duration-300",children:A.jsxs("div",{className:"px-4 py-5 sm:p-6",children:[A.jsxs("div",{className:"mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[A.jsxs("div",{children:[A.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:ks("dashboard.yourCourses")}),A.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:[Qs.length," ",ks("dashboard.of")," ",Vs.length," ",1===Vs.length?ks("dashboard.courseShownSingular"):ks("dashboard.courseShownPlural")]})]}),A.jsxs("div",{className:"w-full sm:max-w-sm",children:[A.jsx("label",{htmlFor:"course-search",className:"sr-only",children:ks("dashboard.searchCourses")}),A.jsxs("div",{className:"relative",children:[A.jsx("span",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3 text-gray-400 dark:text-slate-500",children:A.jsx("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M21 21l-4.35-4.35m1.85-5.15a7 7 0 11-14 0 7 7 0 0114 0z"})})}),A.jsx("input",{id:"course-search",type:"search",value:J,onChange:e=>K(e.target.value),placeholder:ks("dashboard.searchCourses"),className:"w-full rounded-lg border border-gray-300 dark:border-slate-700 bg-white dark:bg-slate-800 py-2.5 pl-10 pr-4 text-sm text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-slate-500 shadow-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]})]})]}),v.isNative()&&dt&&A.jsxs("div",{className:"mt-8 pt-8 border-t border-gray-200 dark:border-slate-800",children:[A.jsx("h4",{className:"text-sm font-medium text-gray-500 dark:text-slate-400 uppercase tracking-wider mb-4",children:"System Information"}),A.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[A.jsxs("div",{className:"bg-gray-50 dark:bg-slate-800/50 p-3 rounded-lg",children:[A.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400",children:"Device"}),A.jsxs("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:[dt.model," (",dt.platform,")"]})]}),A.jsxs("div",{className:"bg-gray-50 dark:bg-slate-800/50 p-3 rounded-lg",children:[A.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-400",children:"OS Version"}),A.jsx("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:dt.osVersion})]}),A.jsx("div",{className:"col-span-2 mt-2",children:A.jsxs("button",{onClick:()=>Ke(null,null,function*(){try{yield v.share({title:"Discourse AI",text:"Check out Discourse AI - The AI-powered learning platform!",url:"https://www.thediscourse.ai",dialogTitle:"Share Discourse AI"})}catch(e){i.error("Error sharing app:",e)}}),className:"w-full flex justify-center items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors",children:[A.jsx("svg",{className:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.3
216m0 0a3 3 0 100-2.684 3 3 0 000 2.684zm0 12.684a3 3 0 100-2.684 3 3 0 000 2.684z"})}),"Share the App"]})})]})]}),A.jsxs("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3",children:[0===Qs.length&&A.jsxs("div",{className:"col-span-full rounded-lg border border-dashed border-gray-300 dark:border-slate-700 bg-gray-50 dark:bg-slate-800/40 px-6 py-10 text-center",children:[A.jsx("h4",{className:"text-base font-medium text-gray-900 dark:text-white",children:"No matching courses"}),A.jsx("p",{className:"mt-2 text-sm text-gray-500 dark:text-slate-400",children:"Try a different title, subject, or keyword from your course description."})]}),Qs.map(e=>{var t,s,r,a,l,n,o,c;if(!e||"object"!=typeof e)return i.warn("⚠️ [DASHBOARD] Invalid course object:",e),null;const u=e.id||`course_${Date.now()}_${Math.random()}`,h=(null==(t=Ns[u])?void 0:t.title)||e.title||"Untitled Course",m=h.toLowerCase(),g=String(e.id||""),x=m.includes("welcome to discourse ai")||m.includes("onboarding")||g.includes("discourse-ai-onboarding")||g.startsWith("onboarding_");if(x&&De)return null;const b=(null==(s=Ns[u])?void 0:s.description)||e.description||"No description available",p=Array.isArray(e.modules)?e.modules.length:0,f=Array.isArray(e.modules)?e.modules.reduce((e,t)=>e+(Array.isArray(t.lessons)?t.lessons.length:0),0):0;return i.debug("🎯 [DASHBOARD] Rendering course card:",{courseId:e.id,courseTitle:e.title,published:e.published,publishedType:typeof e.published,courseIdType:typeof e.id,timestamp:(new Date).toISOString()}),A.jsx("div",{className:"bg-gray-50 dark:bg-slate-800 overflow-hidden shadow rounded-lg relative group hover:shadow-md transition-all duration-300 border border-gray-100 dark:border-slate-700",children:A.jsxs("div",{className:"px-4 py-5 sm:p-6",children:[A.jsxs("div",{className:"flex justify-between items-start",children:[A.jsxs("div",{className:"flex-1",children:[A.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:h}),A.jsx("p",{className:"mt-1 text-sm text-gray-500 dark:text-slate-400 mb-4 line-clamp-2",children:b}),A.jsxs("div",{className:"text-xs text-gray-400 dark:text-slate-500",children:[p," ",ks("dashboard.modules")," • ",f," ",ks("dashboard.lessons")]})]}),!x&&A.jsx("button",{onClick:()=>Ke(null,null,function*(){if(U){F();0===(yield H(`Delete "${h}"?`,[{title:"Delete",style:"DESTRUCTIVE"}]))&&Xs(e.id)}else ge(e)}),className:"p-2 -mr-2 text-gray-400 dark:text-slate-500 hover:text-red-500 dark:hover:text-red-400 transition-colors duration-200 "+(U?"opacity-100":"opacity-0 group-hover:opacity-100"),title:"Delete course",children:A.jsx("svg",{className:"h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:A.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})})})]}),A.jsxs("div",{className:"mt-4 flex flex-wrap gap-2 items-center",children:[A.jsxs("button",{onClick:()=>{try{F(),i.debug("🎯 [DASHBOARD] Continue Learning clicked for course:",{courseId:e.id,courseTitle:e.title,courseIdType:typeof e.id,timestamp:(new Date).toISOString()}),localStorage.setItem("currentCourseId",e.id),i.debug("📍 [DASHBOARD] Navigating to course:",`/course/${e.id}`),Q(`/course/${e.id}`)}catch(t){i.error("❌ [DASHBOARD] Error navigating to course:",t),alert("Error opening course. Please try again.")}},className:`flex-1 ${U?"text-base py-4 rounded-xl":"text-sm py-2.5 rounded-lg"} font-bold text-white bg-blue-600 hover:bg-blue-700 px-4 transition-all duration-200 shadow-sm active:scale-95 whitespace-nowrap`,children:[ks("dashboard.continueLearning")," →"]}),x&&!De&&A.jsx("span",{className:"text-xs text-gray-500 dark:text-slate-400 self-center",title:"Complete onboarding to unlock all features",children:ks("dashboard.onboardingTip")}),e.published&&!(null==(r=e.title)?void 0:r.toLowerCase().includes("welcome to discourse ai"))&&!(null==(a=e.title)?void 0:a.toLowerCase().includes("onboarding"))&&!(null==(l=e.id)?void 0:l.includes("discourse-ai-onboarding"))&&A.jsxs(A.Fragment,{children:[A.jsx("button",{className:`${U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 roun
2ded-lg"} font-bold ${X===e.id?"text-white bg-green-600 hover:bg-green-700":"text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70"} transition-all duration-200 shadow-sm active:scale-95 flex-1 text-center`,onClick:()=>Ke(null,null,function*(){F();const t=`${C}/public/course/${e.id}`;(yield v.share({title:`Check out my course: ${e.title}`,text:`I'm learning about ${e.subject} on Discourse AI. Check out this course!`,url:t,dialogTitle:"Share Course"}))&&!U&&(Z(e.id),setTimeout(()=>Z(null),2e3))}),title:"Copy public course link",children:X===e.id?"Copied!":"Share"}),A.jsx("button",{className:(U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 rounded-lg")+" font-bold text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70 transition-all duration-200 shadow-sm active:scale-95 flex-1 text-center",onClick:()=>Ke(null,null,function*(){F();const t=`${C}/public/course/${e.id}`;if(U){const{Browser:e}=yield d(()=>import("./index-CPsH98q0.js"),__vite__mapDeps([6,1,2,3,4]));yield e.open({url:t})}else window.open(t,"_blank")}),title:"View course as a student",children:"👁️ View"})]}),!(null==(n=e.title)?void 0:n.toLowerCase().includes("welcome to discourse ai"))&&!(null==(o=e.title)?void 0:o.toLowerCase().includes("onboarding"))&&!(null==(c=e.id)?void 0:c.includes("discourse-ai-onboarding"))&&A.jsx("button",{onClick:()=>Ke(null,null,function*(){if(!Ce)try{if(F(),!e.id)return void alert("This course cannot be published because it has no ID.");if(e.published){i.debug("Attempting to unpublish course:",e.id),Se(!0);const t=yield Ne.unpublishCourse(e.id);i.debug("✅ [DASHBOARD] Course unpublished successfully:",t),q(t=>{i.debug("🔄 [DASHBOARD] Updating local state for unpublish:",{courseId:e.id,prevCourses:t.map(e=>({id:e.id,published:e.published})),updatingTo:!1});const s=t.map(t=>{const s=String(t.id)===String(e.id);return s&&i.debug("🎯 [DASHBOARD] Found matching course for unpublish:",{courseId:e.id,courseIdType:typeof e.id,cId:t.id,cIdType:typeof t.id,currentPublished:t.published,updatingTo:!1}),s?Je(qe({},t),{published:!1}):t});i.debug("✅ [DASHBOARD] Local state updated:",{updatedCourses:s.map(e=>({id:e.id,published:e.published}))});const r=s.find(t=>String(t.id)===String(e.id));return r&&i.debug("🎯 [DASHBOARD] Updated course state:",{courseId:r.id,published:r.published,publishedType:typeof r.published}),s}),setTimeout(()=>{q(e=>[...e])},0),setTimeout(()=>{q(e=>[...e])},50),setTimeout(()=>{q(e=>[...e])},100),ze("Course unpublished successfully!"),Pe(!0),setTimeout(()=>Pe(!1),3e3),setTimeout(()=>{Se(!1)},500)}else{i.debug("Attempting to publish course:",e.id),Se(!0);const t=yield Ne.publishCourse(e.id);i.debug("✅ [DASHBOARD] Course published successfully:",t),q(t=>{i.debug("🔄 [DASHBOARD] Updating local state for publish:",{courseId:e.id,prevCourses:t.map(e=>({id:e.id,published:e.published})),updatingTo:!0});const s=t.map(t=>{const s=String(t.id)===String(e.id);return s&&i.debug("🎯 [DASHBOARD] Found matching course for publish:",{courseId:e.id,courseIdType:typeof e.id,cId:t.id,cIdType:typeof t.id,currentPublished:t.published,updatingTo:!0}),s?Je(qe({},t),{published:!0}):t});i.debug("✅ [DASHBOARD] Local state updated:",{updatedCourses:s.map(e=>({id:e.id,published:e.published}))});const r=s.find(t=>String(t.id)===String(e.id));return r&&i.debug("🎯 [DASHBOARD] Updated course state:",{courseId:r.id,published:r.published,publishedType:typeof r.published}),s}),setTimeout(()=>{q(e=>[...e])},0),setTimeout(()=>{q(e=>[...e])},50),setTimeout(()=>{q(e=>[...e])},100),Ee(!0),setTimeout(()=>Pe(!1),3e3),setTimeout(()=>{Se(!1)},2e3)}}catch(t){i.error("❌ [DASHBOARD] Error with course publish/unpublish:",t),Se(!1),setTimeout(()=>Ke(null,null,function*(){yield Ys(!0)}),100),alert("Failed to "+(e.published?"unpublish":"publish")+" course: "+(t.message||"Unknown error"))}}),onMouseEnter:()=>be(e.id),onMouseLeave:()=>be(null),disabled:!e.id||Ce,className:`${U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 rounded-lg"} font-bold transition-colors duration-200 whitespace-nowrap flex-shrink-0 ${Ce?"bg-gray-300 dark:bg-slate-700 text-gray-500 dark:text-slate-400 cursor-not-allowed":e.published?"bg-green-100 dark:bg-green-900/40 text-green-800 dark:text-green-300 border border-green-300 dark:border-green-800 hover:bg-green-200 dark:hover:bg-green-900/60":e.id?"bg-green-600 text-white hover:bg-green-700":"bg-gray-200 dark:bg-slate-700 text-gray-500 dark:text-slate-400 cursor-not-allowed"}`,title:Ce?"Updating...":e.published?"Click to unpublish this course":e.id?"Publish this course to share publicly":"Cannot publish: missing course ID",children:Ce?ks("dashboard.updating"):e.published?ks("dashboard.unpublish"):ks("dashboard.publish")}),A.jsxs("div",{className:"flex flex-wrap gap-2 w-full",children:[A.jsxs("button",{onClick:()=>{Jt(e),Yt(!0)},className:(U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 roun
2ded-lg")+" font-bold transition-all duration-200 text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70 shadow-sm active:scale-95 whitespace-nowrap flex-shrink-0",title:"Open practice studio for progress checks, games, debate, and writing",children:["⚔️ ",ks("dashboard.practiceStudio")]}),A.jsx("button",{onClick:()=>{F(),Xt(e)},className:(U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 rounded-lg")+" font-bold transition-all duration-200 text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70 shadow-sm active:scale-95 whitespace-nowrap flex-shrink-0",title:"Plan live webcam check-ins and schedule assessments on a calendar",children:"📅 Schedule"}),!x&&A.jsx("button",{onClick:()=>{F(),Ks(e)},disabled:He===e.id,className:`${U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 rounded-lg"} font-bold transition-all duration-200 shadow-sm active:scale-95 whitespace-nowrap flex-shrink-0 ${He===e.id?"bg-gray-300 dark:bg-slate-700 text-gray-500 dark:text-slate-400 cursor-not-allowed":"text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70"}`,title:"Download this course as a SCORM 1.2 package for Moodle, Canvas, Blackboard or any other LMS",children:He===e.id?"⏳ Packaging…":"📦 Export SCORM"}),A.jsx("button",{onClick:()=>{e.published&&(Gt(e),Wt(!0))},className:`${U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 rounded-lg"} font-bold transition-all duration-200 ${e.published?"text-blue-700 dark:text-blue-300 bg-blue-100 dark:bg-blue-900/50 hover:bg-blue-200 dark:hover:bg-blue-900/70 shadow-sm active:scale-95 cursor-pointer":"bg-gray-200 dark:bg-slate-700 text-gray-400 dark:text-slate-500 cursor-not-allowed"} whitespace-nowrap flex-shrink-0`,title:e.published?"View student progress and analytics":"Publish your course to view student progress",children:"📊 View Progress"}),e.published&&A.jsx("button",{onClick:()=>{cs(e)},className:(U?"text-base py-4 px-6 rounded-xl":"text-sm py-2.5 px-4 rounded-lg")+" font-bold transition-all duration-200 text-amber-700 dark:text-amber-300 bg-amber-100 dark:bg-amber-900/40 hover:bg-amber-200 dark:hover:bg-amber-900/60 shadow-sm active:scale-95 whitespace-nowrap flex-shrink-0",title:"Clear all student sessions and progress for this course",children:"🧹 Clear Sessions"})]})]})]})},`${u}-${e.published}-${Ce}`)})]})]})})]}),re&&(()=>{const e=Number.isFinite(null==is?void 0:is.percent)?is.percent:null,t=ts>0?Math.min(95,(ts-ls)/ts*100):0,s=Math.min(100,Math.max(0,null!==e?e:t)),r=rs?Math.floor((Date.now()-rs)/1e3):0,a=null!==e&&e>=10&&r>5?Math.round(r*(100-e)/e):ls;return A.jsx("div",{className:"fixed inset-0 bg-gray-500 bg-opacity-75 flex items-center justify-center p-4 z-50",children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-8 max-w-md w-full text-center border border-gray-200 dark:border-slate-800 shadow-2xl",children:[A.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-4 border-gray-200 dark:border-slate-700 border-t-blue-600 dark:border-t-blue-400 mx-auto mb-4"}),A.jsx("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-2",children:"Generating Your Course"}),(null==is?void 0:is.message)?A.jsx("p",{className:"text-sm text-blue-600 dark:text-blue-400 mb-2 font-medium",children:is.message}):A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-2",children:"Please wait while we create your course. This may take a few minutes."}),is&&"generating"===is.stage&&(is.totalLessonsOverall>0?A.jsxs("div",{className:"mt-2 mb-3 text-xs text-gray-500 dark:text-slate-500",children:[A.jsx("span",{className:"font-semibold text-gray-700 dark:text-slate-300",children:"Lessons completed"})," ",is.completedLessons||0,"/",is.totalLessonsOverall]}):is.totalModules>0?A.jsxs("div",{className:"mt-2 mb-3 text-xs text-gray-500 dark:text-slate-500",children:[A.jsx("span",{className:"font-semibold text-gray-700 dark:text-slate-300",children:"Module"})," ",is.currentModule||0,"/",is.totalModules]}):null),(null==is?void 0:is.stage)&&A.jsx("div",{className:"mb-3",children:A.jsxs("span",{className:"inline-block px-2 py-1 text-xs rounded-full "+("starting"===is.stage?"bg-amber-100 text-amber-800 dark:bg-amber-900 dark:text-amber-200":"generating"===is.stage?"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200":"completed"===is.stage?"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200":"bg-gray-100 text-gray-800 dark:bg-slate-700 dark:text-slate-300"),children:["starting"===is.stage&&"🚀 Starting","generating"===is.stage&&"⚙️ Building","completed"===is.stage&&"✅ Complete",!["starting","generating","completed"].includes(is.stage)&&is.stage]})}),(ts>0||null!==e)&&A.jsxs("div",{className:"mt-2 mb-4",children:[A.jsx("div",{className:"text-xs text-gray-500 dark:text-slate-500",children:"Estimated time remaining"}),A.jsxs("div",{className:"text-base font-semibold text-gray-900 dark:text-white",children:[String(Math.floor(a/60)).padStart(2,"0"),":",String(a%60).padStart(2,"0")]}),A.jsx("div",{className:"w-full bg-gray-200 dark:bg-slate-700 rounded-full h-2 mt-2",children:A.jsx("div",{className:"bg-blue-600 h-2 rounded-full transition-all duration-1000",style:{width:`${s}%`}})}),A.jsxs("div",{className:"text-xs text-gray-400 dark:text-slate-600 mt-1",children:[Math.round(s),"%"]})]}),A.jsx("button",{onClick:()=>{i.debug("🛑 [DASHBOARD] User closed generation modal"),ne(!1)},className:"px-4 py-2 text-sm font-medium text-gray-700 dark:text-slate-300 bg-gray-100 dark:bg-slate-800 hover:bg-gray-200 dark:hover:bg-slate-700 rounded-md transition-colors",children:"Hide (generation continues in background)"})]})})})(),me&&A.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4 z-50",children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-8 max-w-sm w-full shadow-2xl text-center border border-gray-200 dark:border-slate-800 animate-in fade-in zoom-in duration-200",children:[A.jsx("div",{className:"text-4xl mb-4",children:"⚠️"}),A.jsx("h3",{className:"text-xl font-bold text-gray-900 dark:text-white mb-2",children:"Delete Course?"}),A.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400 mb-6",children:['Are you sure you want to delete "',me.title,'"? This will permanently remove the course and all associated student progress. This action cannot be undone.']}),A.jsxs("div",{className:"flex gap-3",children:[A.jsx("button",{onClick:()=>ge(null),className:"flex-1 px-4 py-2 bg-gray-100 dark:bg-slate-800 text-gray-700 dark:text-slate-300 rounded-lg font-semibold hover:bg-gray-200 dark:hover:bg-slate-700 transition-colors",children:"Cancel"}),A.jsx("button",{onClick:()=>Xs(me.id),className:"flex-1 px-4 py-2 bg-red-600 text-white rounded-lg font-semibold hover:bg-red-700 transition-colors shadow-lg shadow-red-600/30",children:"Delete"})]})]})}),ds&&A.jsx("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center p-4 z-50",children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-8 max-w-sm w-full shadow-2xl text-center border border-gray-200 dark:border-slate-800 animate-in fade-in zoom-in duration-200",children:[A.jsx("div",{className:"text-4xl mb-4",children:"🧹"}),A.jsx("h3",{className:"text-xl font-bold text-gray-900 dark:text-white mb-2",children:"Clear All Sessions?"}),A.jsxs("p",{className:"text-sm text-gray-500 dark:text-slate-400 mb-6",children:['This will wipe all student progress, quiz scores, and active sessions for "',ds.title,'". Students will need to sign in again. This action cannot be undone.']}),A.jsxs("div",{className:"flex gap-3",children:[A.jsx("button",{onClick:()=>cs(null),className:"flex-1 px-4 py-2 bg-gray-100 dark:bg-slate-800 text-gray-700 dark:text-slate-300 rounded-lg font-semibold hover:bg-gray-200 dark:hover:bg-slate-700 transition-colors",children:"Cancel"}),A.jsx("button",{onClick:()=>Js(ds.id),disabled:us,className:"flex-1 px-4 py-2 bg-amber-600 text-white rounded-lg font-semibold hover:bg-amber-700 transition-colors shadow-lg shadow-amber-600/30 disabled:opacity-50",children:us?"Clearing...":"Clear All"})]})]})}),Ge&&A.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-start sm:items-center justify-center p-2 sm:p-4 z-50 pt-12 sm:pt-0",children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg p-3 sm:p-6 w-full max-w-[90vw] sm:max-w-sm md:max-w-lg lg:max-w-2xl max-h-[90vh] sm:max-h-[85vh] overflow-y-auto shadow-2xl border border-gray-200 dark:border-slate-800 mt-4 sm:mt-0",children:[A.jsxs("div",{className:"flex items-center justify-between mb-4",children:[A.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white",children:ks("dashboardSettings.title")}),A.jsx("button",{onClick:()=>Qe(!1),className:"text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-white",children:"✕"})]}),A.jsxs("div",{className:"space-y-6",children:[A.jsxs("div",{children:[A.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-2",children:ks("dashboardSettings.managePayments")}),A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-3",children:w()?ks("dashboardSettings.managePaymentsDescIOS"):ks("dashboardSettings.managePaymentsDesc")}),A.jsxs("div",{className:"flex flex-wrap gap-3",children:[A.jsx("button",{onClick:()=>{try{nt(!0),w()?window.location.href="https://apps.apple.com/account/subscriptions":window.location.href="https://billing.stripe.com/p/login/3cIaEWgNC6uZdzx2SJdby00"}catch(e){nt(!1),alert("Failed to open billing portal: "+((null==e?void 0:e.message)||"Unknown error"))}},disabled:lt,className:"inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-md shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50",children:lt?ks("dashboardSettings.opening"):w()?ks("dashboardSettings.manageAppStore"):ks("dashboardSettings.manageButton")}),w()&&A.jsx("button",{onClick:()=>Ke(null,null,function*(){try{ot(!0),F();const e=yield N.restorePurchases();if(!e.success)throw new Error(e.error||"Failed to restore purchases");e.hasPro?(ze("Purchases restored! Pro access active."),_()):ze("Restore complete. No active subscription found."),Pe(!0),yield Ps()}catch(e){ce("Restore failed: "+(e.message||"Unknown error"))}finally{ot(!1)}}),disabled:it,className:"inline-flex items-center px-4 py-2 border border-gray-300 dark:border-slate-700 text-sm font-medium rounded-md shadow-sm text-gray-700 dark:text-slate-200 bg-white dark:bg-slate-800 hover:bg-gray-50 dark:hover:bg-slate-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 disabled:opacity-50",children:ks(it?"dashboardSettings.restoring":"dashboardSettings.restorePurchases")})]})]}),A.jsx(ae,{}),A.jsxs("div",{className:"border-t border-gray-200 dark:border-slate-800 pt-4",children:[A.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-2",children:ks("dashboardSettings.exportData")}),A.jsx("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-3",children:ks("dashboardSettings.exportDataDescription")}),rt&&A.jsx("p",{className:"text-sm text-red-600 dark:text-red-400 mb-3",role:"alert",children:rt}),A.jsx("button",{type:"button",onClick:()=>Ke(null,null,function*(){at(null),st(!0);try{yield Ne.exportMyData()}catch(e){at(ks("dashboardSettings.exportDataFailed"))}finally{st(!1)}}),disabled:tt,className:"px-4 py-2 text-sm font-medium rounded-md border border-gray-300 dark:border-slate-600 text-gray-700 dark:text-slate-200 hover:bg-gray-50 dark:hover:bg-slate-800 disabled:opacity-50 disabled:cursor-not-allowed",children:ks(tt?"dashboardSettings.exportingData":"dashboardSettings.exportDataButton")})]}),A.jsxs("div",{className:"border-t border-gray-200 dark:border-slate-800 pt-4",children:[A.jsx("h4",{className:"text-sm font-medium text-gray-900 dark:text-white mb-2",children:ks("dashboardSettings.deleteAccount")}
2),it&&A.jsx("div",{className:"mb-4 p-4 bg-blue-50 border border-blue-200 rounded-md",children:A.jsxs("div",{className:"flex items-center",children:[A.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-blue-600 mr-2"}),A.jsx("span",{className:"text-sm text-blue-700",children:ks("dashboardSettings.checkingSubscription")})]})}),!it&&A.jsxs(A.Fragment,{children:[(null==Ss?void 0:Ss.hasActiveSubscription)&&A.jsx("div",{className:"mb-4 p-4 bg-amber-50 border border-amber-200 rounded-md",children:A.jsxs("div",{className:"flex items-start",children:[A.jsx("div",{className:"flex-shrink-0",children:A.jsx("svg",{className:"h-5 w-5 text-amber-400",viewBox:"0 0 20 20",fill:"currentColor",children:A.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),A.jsxs("div",{className:"ml-3 flex-1",children:[A.jsx("h3",{className:"text-sm font-medium text-amber-800",children:ks("dashboardSettings.activeSubscriptionDetected")}),A.jsx("div",{className:"mt-2 text-sm text-amber-700",children:A.jsx("p",{children:ks("dashboardSettings.cannotDeleteActiveSub")})})]})]})}),A.jsx("div",{className:"mb-3",children:A.jsxs("p",{className:"text-sm text-gray-600 dark:text-slate-400 mb-2",children:[ks("dashboardSettings.deleteConfirmType")," ",A.jsx("span",{className:"font-semibold dark:text-white",children:ks("dashboardSettings.deleteConfirmDelete")})," ",ks("dashboardSettings.deleteConfirmInstruction"),(null==Ss?void 0:Ss.hasActiveSubscription)&&A.jsx("span",{className:"block mt-2 text-amber-600 dark:text-amber-500 font-medium",children:ks("dashboardSettings.deleteBlockedWarning")})]})}),A.jsx("input",{type:"text",value:Ye,onChange:e=>Xe(e.target.value),placeholder:ks("dashboardSettings.deleteConfirmPlaceholder"),className:"w-full px-3 py-2 border border-gray-300 dark:border-slate-600 rounded-md mb-3 bg-white dark:bg-slate-700 text-gray-900 dark:text-white placeholder-gray-400 dark:placeholder-slate-500 focus:ring-red-500 focus:border-red-500 outline-none transition-colors duration-200",disabled:null==Ss?void 0:Ss.hasActiveSubscription}),A.jsxs("div",{className:"flex justify-end gap-3",children:[A.jsx("button",{onClick:()=>Qe(!1),className:"px-4 py-2 text-sm font-medium text-gray-700 dark:text-slate-300 bg-gray-100 dark:bg-slate-700 hover:bg-gray-200 dark:hover:bg-slate-600 rounded-md transition-colors duration-200",children:ks("dashboardSettings.cancel")}),A.jsx("button",{onClick:()=>Ke(null,null,function*(){var e,t;if("Delete"===Ye)if(it)alert("Please wait while we check your subscription status.");else if(null==Ss?void 0:Ss.hasActiveSubscription)alert("Cannot delete account with active subscription. Please cancel your subscription first.");else try{et(!0),yield Ne.deleteAccount("Delete"),yield V(),Q("/login")}catch(s){if(403!==(null==s?void 0:s.status)||"Cannot delete account with active subscription"!==(null==(e=null==s?void 0:s.data)?void 0:e.error)&&!(null==(t=null==s?void 0:s.message)?void 0:t.includes("active subscription")))alert("Failed to delete account: "+((null==s?void 0:s.message)||"Unknown error"));else{const e=(null==s?void 0:s.data)||s;alert(`⚠️ Cannot delete account with active subscription!\n\nYou have an active subscription (${e.status||"active"}). Please cancel your subscription first through the "Manage Payments & Subscription" button above.\n\nAfter canceling your subscription, you can delete your account.`)}}finally{et(!1)}else alert("Please type 'Delete' to confirm.")}),disabled:"Delete"!==Ye||Ze||(null==Ss?void 0:Ss.hasActiveSubscription)||it,className:"px-4 py-2 text-sm font-medium text-white bg-red-600 hover:bg-red-700 rounded-md disabled:opacity-50",children:ks(Ze?"dashboardSettings.deletingAccount":it?"dashboardSettings.checkingSubscription":"dashboardSettings.deleteAccountButton")})]})]})]})]})]})}),A.jsx(T,{isOpen:Ds,onClose:()=>Is(!1),onSuccess:()=>{}}),Ut&&Vt&&A.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",onClick:()=>{Wt(!1),Gt(null)},children:A.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-lg max-w-6xl w-full max-h-[90vh] overflow-hidden border border-gray-200 dark:border-slate-800",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"flex justify-between items-center p-4 border-b border-gray-200 dark:border-slate-800",children:[A.jsx("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white",children:"Student Progress Dashboard"}),A.jsx("button",{onClick:()=>{Wt(!1),Gt(null)},className:"text-gray-500 hover:text-gray-700 dark:text-slate-400 dark:hover:text-white text-2xl",children:"×"})]}),A.jsx("div",{className:"overflow-y-auto max-h-[calc(90vh-80px)]",children:A.jsx(pe,{courseId:Vt.id,courseTitle:Vt.title})})]})}),Kt&&A.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 p-4",onClick:()=>Xt(null),children:A.jsxs("div",{className:"bg-white dark:bg-slate-950 rounded-lg max-w-4xl w-full max-h-[90vh] overflow-hidden",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"flex justify-between items-center p-4 border-b dark:border-slate-800",children:[A.jsxs("div",{children:[A.jsx("h2",{className:"text-xl font-semibold dark:text-white",children:"Course Schedule"}),A.jsx("p",{className:"text-sm text-gray-500 dark:text-slate-400",children:Kt.title})]}),A.jsx("button",{onClick:()=>Xt(null),className:"text-gray-500 hover:text-gray-700 dark:hover:text-slate-300 text-2xl",children:"×"})]}),A.jsx("div",{className:"overflow-y-auto max-h-[calc(90vh-88px)]",children:A.jsx(Oe,{course:Kt,onLaunchLive:e=>es(e)})})]})}),(null==Zt?void 0:Zt.roomName)&&A.jsx(O,{roomName:Zt.roomName,subject:Zt.title,displayName:(null==W?void 0:W.name)||(null==W?void 0:W.firstName)||"Tutor",isModerator:!0,onClose:()=>es(null)}),Qt&&qt&&A.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4",onClick:()=>{Yt(!1),Jt(null)},children:A.jsxs("div",{className:"bg-slate-950 rounded-lg max-w-7xl w-full max-h-[92vh] overflow-hidden border border-slate-800",onClick:e=>e.stopPropagation(),children:[A.jsxs("div",{className:"flex justify-between items-center p-4 border-b border-slate-800 bg-slate-900 text-white",children:[A.jsxs("div",{children:[A.jsx("h2",{className:"text-xl font-semibold",children:ks("dashboard.practiceStudio")}
2),A.jsx("p",{className:"text-sm text-slate-400",children:qt.title})]}),A.jsx("button",{onClick:()=>{Yt(!1),Jt(null)},className:"text-slate-400 hover:text-slate-200 text-2xl",children:"×"})]}),A.jsx("div",{className:"overflow-y-auto max-h-[calc(92vh-88px)]",children:A.jsx(M,{course:qt,onBack:()=>{Yt(!1),Jt(null)}})})]})})]})]})};export{Xe as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.