1import{j as e}from"./ui-Dqaq1iaa.js";import{u as t,r as s,f as a}from"./vendor-D_xiAuUj.js";import{S as r}from"./StudentHeader-D-GI6CqW.js";import{c as n,B as i,w as o,s as l}from"./index-BnJJh0He.js";import{C as c,a as d,b as m,c as u,d as h}from"./card-Bv8W4Zw2.js";import{e as p}from"./edgeError-TX0_vJhG.js";import{I as g}from"./input-CNqaEQ6A.js";import{L as f}from"./label-DFPm3HHT.js";import{S as x,a as j,b as y,c as w,d as b}from"./select-Eyq10n3w.js";import{u as v}from"./useUsageEnforcement-NjP6Y3Dy.js";import{u as N}from"./useUsageTracking-5jod-rZM.js";import{u as k}from"./useFamilySessionTracking-nRx_9CA7.js";import{A as S}from"./arrow-left-D11zA1iW.js";import{U as C}from"./upload-CjReBW5Y.js";import{F as P}from"./file-text-EmIGDVrR.js";import{L as z}from"./loader-circle-Cc0eb4Pc.js";import"./RobotIcon-t4AskJqO.js";import"./UsageHeaderIndicator-BGmgVUw5.js";import"./ChoosePlanDialog-Cgeha1ht.js";import"./supabase-XAR8dl0U.js";import"./chevron-down-Db1DtOG0.js";import"./chevron-up-CNf5mqZm.js"; 2/** 3 * @license lucide-react v0.462.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const q=n("FileCheck",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"m9 15 2 2 4-4",key:"1grp1n"}]]),F=n("Image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]]); 8/** 9 * @license lucide-react v0.462.0 - ISC 10 * 11 * This source code is licensed under the ISC license. 12 * See the LICENSE file in the root directory of this source tree. 13 */function _(){const n=t(),[_,E]=s.useState(null),[U,D]=s.useState(!1),[$,A]=s.useState(!1),[T,I]=s.useState(null),[L,M]=s.useState(""),[O,R]=s.useState(!1),[B,G]=s.useState(!1),[J,H]=s.useState(""),[K,Q]=s.useState(""),[W]=a();s.useEffect(()=>{const e=W.get("subject"),t=W.get("topic");if(e){["Math","Science","English","History","Languages","Art"].includes(e)?H(e):(H("Other"),Q(e))}t&&M(s=>s||`Make a focused practice set on ${t}${e?` (${e})`:""} â this is the exact area to work on. Include the key method/steps, 2â3 worked examples, and several practice problems specifically on ${t}.`)},[]);const{incrementUsage:V}=v(),{sessionData:Y}=k();N();const X=async e=>{var t,s,a,r;if(_&&T)if(J){A(!0);try{const{data:{user:a}}=await l.auth.getUser();if(!a)throw new Error("Not authenticated");const r=_.name.split(".").pop(),i=`${a.id}/${Date.now()}.${r}`,{data:c,error:d}=await l.storage.from("study-materials").upload(i,_);if(d)throw d;const{data:m,error:u}=await l.functions.invoke("generate-study-content",{body:{fileUrl:i,fileName:_.name,contentType:_.type,generationType:e,studentId:a.id}});if(null==m?void 0:m.generationLimit)return o.error(m.message||"You've made all 10 study sets for this month."),void A(!1);if(u)throw new Error(await p(u,"Something went wrong. Please try again."));const h=_.name.replace(/\.[^/.]+$/,""),g="custom"===J?K:J,{data:f,error:x}=await l.from("study_sets").insert({student_id:a.id,type:e,set_name:h,subject:g,file_url:i,total_items:"flashcard"===e?(null==(t=m.generatedContent.flashcards)?void 0:t.length)||0:(null==(s=m.generatedContent.questions)?void 0:s.length)||0}).select().single();if(x)throw x;if("flashcard"===e){const e="custom"===J?K:J,t=m.generatedContent.flashcards.map((t,s)=>({set_id:f.id,front:t.front,back:t.back,front_text:t.front,back_text:t.back,subject:e,card_order:s,mastered:!1})),{error:s}=await l.from("flashcards").insert(t);if(s)throw s;await V("flashcards"),o.success("Flashcards created successfully!"),n(`/studybuddi/flashcards/${f.id}`)}else{const e=m.generatedContent.questions.map((e,t)=>({set_id:f.id,question:e.question,question_type:e.type,options:e.options?JSON.parse(JSON.stringify(e.options)):null,correct_answer:e.correct_answer,explanation:e.explanation,question_order:t})),{error:t}=await l.from("quiz_questions").insert(e);if(t)throw t;await V("quizzes"),o.success("Quiz created successfully!"),n(`/studybuddi/quiz/${f.id}`)}}catch(i){(null==(a=i.message)?void 0:a.includes("Rate limit"))?o.error("Rate limit exceeded. Please try again in a moment."):(null==(r=i.message)?void 0:r.includes("Payment required"))?o.error("AI credits depleted. Please contact support."):o.error(i.message||"Failed to generate content"),A(!1)}}else o.error("Please select a subject before creating study materials")},Z=e=>e.replace(/<[^>]*>/g,""),ee=async()=>{var e,t;const s=Z(L.trim());if(s.length<2)o.error("Tell me what you want to work on â a topic or your notes.");else if(s.length>15e3)o.error("Text exceeds 15,000 character limit");else{R(!0),A(!0);try{const{data:{user:e}}=await l.auth.getUser();if(!e)throw new Error("Not authenticated");const{data:t,error:a}=await l.functions.invoke("generate-study-content",{body:{source:"manual_text",content:s,generationType:"analyze",studentId:e.id}});if(a)throw new Error(await p(a,"Something went wrong. Please try again."));I(t),A(!1),R(!1),o.success("Content analyzed successfully!")}catch(a){(null==(e=a.message)?void 0:e.includes("Rate limit"))?o.error("Rate limit exceeded. Please try again in a moment."):(null==(t=a.message)?void 0:t.includes("Payment required"))?o.error("AI credits depleted. Please contact support."):o.error(a.message||"Failed to analyze content"),A(!1),R(!1)}}},te=async e=>{var t,s,a,r;if(!L||!T)return;if(!J)return void o.error("Please select a subject before creating study materials");const i=Z(L.trim());A(!0);try{const{data:{user:a}}=await l.auth.getUser();if(!a)throw new Error("Not authenticated");const{data:r,error:c}=await l.functions.invoke("generate-study-content",{body:{source:"manual_text",content:i,generationType:e,studentId:a.id}});if(null==r?void 0:r.generationLimit)return o.error(r.message||"You've made all 10 study sets for this month."),void A(!1);if(c)throw new Error(await p(c,"Something went wrong. Please try again."));if(!r||!r.generatedContent)throw new Error("Invalid response from AI service");const d="custom"===J?K:J,m=(i.split(/[.\n!?]/)[0]||"").trim().replace(/[^\w\s'-]/g,"").trim(),u=m.length>=3?m.length>45?m.slice(0,45).trim()+"â¦":m:`${(null==T?void 0:T.detectedSubject)||d||"Study"} set`,{data:h,error:g}=await l.from("study_sets").insert({student_id:a.id,type:e,set_name:u,subject:d,total_items:"flashcard"===e?(null==(t=r.generatedContent.flashcards)?void 0:t.length)||0:(null==(s=r.generatedContent.questions)?void 0:s.length)||0}).select().single();if(g)throw g;if("flashcard"===e){if(!r.generatedContent.flashcards||!Array.isArray(r.generatedContent.flashcards))throw new Error("No flashcards generated. Please try again.");const e="custom"===J?K:J,t=r.generatedContent.flashcards.map((t,s)=>({set_id:h.id,front:t.front,back:t.back,front_text:t.front,back_text:t.back,subject:e,card_order:s,mastered:!1})),{error:s}=await l.from("flashcards").insert(t);if(s)throw s;await V("flashcards"),o.success("Flashcards created successfully!"),n(`/studybuddi/flashcards/${h.id}`)}else{if(!r.generatedContent.questions||!Array.isArray(r.generatedContent.questions))throw new Error("No quiz questions generated. Please try again.");const e=r.generatedContent.questions.map((e,t)=>({set_id:h.id,question:e.question,question_type:e.type,options:e.options?JSON.parse(JSON.stringify(e.options)):null,correct_answer:e.correct_answer,explanation:e.explanation,question_order:t})),{error:t}=await l.from("quiz_questions").insert(e);if(t)throw t;await V("quizzes"),o.success("Quiz created successfully!"),n(`/studybuddi/quiz/${h.id}`)}}catch(c){(null==(a=c.message)?void 0:a.includes("Rate limit"))?o.error("Rate limit exceeded. Please try again in a moment."):(null==(r=c.message)?void 0:r.includes("Payment required"))?o.error("AI credits depleted. Please contact support."):o.error(c.message||"Failed to generate content"),A(!1)}};return e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-background to-muted",children:[e.jsx(r,{}),e.jsxs("main",{className:"container mx-auto px-4 py-8 max-w-4xl",children:[e.jsxs(i,{variant:"ghost",onClick:()=>n("/studybuddi"),className:"mb-6",children:[e.jsx(S,{className:"w-4 h-4 mr-2"}),"Back to StudyBuddi"]}),e.jsxs(c,{children:[e.jsxs(d,{children:[e.jsxs(m,{className:"flex items-center gap-2 font-display",children:[e.jsx(C,{className:"w-6 h-6 text-primary"}),"Upload Study Material"]}),e.jsx(u,{children:"Upload a photo of your notes or paste text to create flashcards or practice quizzes"})]}),e.jsxs(h,{className:"space-y-6",children:[!_&&!T&&e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-6 sm:p-12 text-center transition-colors "+(B?"border-primary bg-primary/5":"border-muted-foreground
13/25 hover:border-primary/50"),onDragOver:e=>{e.preventDefault(),e.stopPropagation(),G(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),G(!1)},onDrop:e=>{var t;e.preventDefault(),e.stopPropagation(),G(!1);const s=null==(t=e.dataTransfer.files)?void 0:t[0];if(!s)return;if(s.size>10485760)return void o.error("File exceeds 10MB limit");["application/pdf","image/jpeg","image/png","image/webp","image/heic","text/plain","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document"].includes(s.type)||s.name.toLowerCase().endsWith(".heic")?(E(s),o.success(`Selected: ${s.name}`)):o.error("Unsupported file format. Please upload PDF, image, or document.")},children:[e.jsx(g,{type:"file",accept:".pdf,.jpg,.jpeg,.png,.webp,.heic,.txt,.doc,.docx",onChange:e=>{var t;const s=null==(t=e.target.files)?void 0:t[0];if(!s)return;if(s.size>10485760)return void o.error("File exceeds 10MB limit");["image/jpeg","image/png","image/webp","image/heic","text/plain"].includes(s.type)||s.name.toLowerCase().endsWith(".heic")?(E(s),o.success(`Selected: ${s.name}`)):o.error("Unsupported file format. Please upload an image (JPG, PNG) or a text file.")},className:"hidden",id:"file-upload"}),e.jsxs("label",{htmlFor:"file-upload",className:"cursor-pointer",children:[e.jsx(C,{className:"w-12 h-12 sm:w-16 sm:h-16 mx-auto mb-3 sm:mb-4 text-muted-foreground"}),e.jsx("h3",{className:"text-lg sm:text-xl font-semibold mb-2 font-display",children:"Drag & drop or click to browse"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"JPG ⢠PNG ⢠Images ⢠TXT"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Max 10MB per file"})]})]}),_&&!T&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-4 p-4 bg-muted rounded-lg",children:[_.type.startsWith("image/")?e.jsx(F,{className:"w-8 h-8 text-primary"}):e.jsx(P,{className:"w-8 h-8 text-primary"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"font-medium",children:_.name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[(_.size/1024).toFixed(0)," KB"]})]}),e.jsx(i,{variant:"ghost",size:"sm",onClick:()=>E(null),children:"Remove"})]}),e.jsx(i,{onClick:async()=>{if(_){D(!0),A(!1);try{const{data:{user:e}}=await l.auth.getUser();if(!e)throw new Error("Not authenticated");const t=_.name.split(".").pop(),s=`${e.id}/${Date.now()}.${t}`,{data:a,error:r}=await l.storage.from("study-materials").upload(s,_);if(r)throw r;o.success("File uploaded! Analyzing content..."),D(!1),A(!0);const{data:n,error:i}=await l.functions.invoke("generate-study-content",{body:{fileUrl:s,fileName:_.name,contentType:_.type,generationType:"analyze",studentId:e.id}});if(null==n?void 0:n.error)throw new Error(n.error);if(i)throw new Error(await p(i,"Something went wrong. Please try again."));I(n),A(!1)}catch(e){const t=e.message||"Failed to upload file";t.includes("PDF")?o.error("PDFs are not yet supported. Please upload images (JPG/PNG) or text files instead.",{duration:6e3}):o.error(t),D(!1),A(!1)}}},disabled:U||$,className:"w-full",size:"lg",children:U?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2 animate-spin"}),"Uploading..."]}):$?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2 animate-spin"}),"Analyzing content..."]}):e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-4 h-4 mr-2"}),"Upload & Analyze"]})})]}),!_&&!T&&e.jsxs("div",{className:"sb-manual-wrap mt-8 pt-8 border-t border-muted",children:[e.jsx("label",{htmlFor:"sb-manual-text",className:"block text-sm font-semibold mb-2",children:"Or type / paste your notes"}),e.jsx("textarea",{id:"sb-manual-text",name:"manualText",value:L,onChange:e=>M(e.target.value),onKeyDown:e=>{(e.ctrlKey||e.metaKey)&&"Enter"===e.key&&(e.preventDefault(),ee())},placeholder:"Paste your notes or textbook, OR tell me what you want to work on â like 'multiplication' or 'the water cycle.'",rows:6,maxLength:15e3,className:"w-full p-3 border border-input rounded-lg bg-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 resize-none"}),e.jsxs("div",{className:"flex items-center justify-between mt-2 gap-2",children:[e.jsxs("span",{className:"sb-char-count text-xs text-muted-foreground",children:[L.length," / 15,000 characters"]}),1===L.trim().length&&e.jsx("span",{className:"text-xs text-amber-600",children:"Add a topic or paste some notes"})]}),e.jsx(i,{id:"sb-submit-text",type:"button",onClick:ee,disabled:O||$||L.trim().length<2,className:"mt-3 w-full",size:"lg",children:O||$?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2 animate-spin"}),"Analyzing..."]}):"Generate Study Material"})]}),T&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-muted p-6 rounded-lg",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[e.jsx(q,{className:"w-6 h-6 text-green-500"}),e.jsx("h3",{className:"text-xl font-semibold font-display",children:"Analysis Complete!"})]}),e.jsxs("div",{className:"space-y-2 mb-4",children:[_&&e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"File:"})," ",_.name]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Detected Subject:"})," ",T.detectedSubject]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-medium",children:"Content length:"})," ",T.contentLength," characters"]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Preview: ",T.extractedText]})]}),e.jsxs("div",{className:"space-y-3 bg-primary/5 p-4 rounded-lg border-2 border-primary/20",children:[e.jsxs(f,{htmlFor:"subject-select",className:"text-base font-semibold",children:["Select Subject ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsxs(x,{value:J,onValueChange:e=>{H(e),"custom"!==e&&Q("")},children:[e.jsx(j,{id:"subject-select",className:"w-full bg-background",children:e.jsx(y,{placeholder:"Choose subject..."})}),e.jsxs(w,{children:[e.jsx(b,{value:"Mathematics",children:"ð Mathematics"}),e.jsx(b,{value:"Science",children:"ð¬ Science"}),e.jsx(b,{value:"English",children:"ð English"}),e.jsx(b,{value:"History",children:"ðï¸ History"}),e.jsx(b,{value:"Foreign Language",children:"ð Foreign Language"}),e.jsx(b,{value:"Other",children:"ð¦ Other"}),e.jsx(b,{value:"custom",children:"âï¸ Add Custom Subject"})]})]}),"custom"===J&&e.jsxs("div",{className:"space-y-2 animate-in fade-in slide-in-from-top-2",children:[e.jsx(f,{htmlFor:"custom-subject",children:"Custom Subject Name"}),e.jsx(g,{id:"custom-subject",placeholder:"Enter custom subject...",value:K,onChange:e=>Q(e.target.value),maxLength:50,className:"bg-background"})]}),J&&"custom"!==J&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["â Study materials will be tagged with: ",e.jsx("strong",{children:J})]}),"custom"===J&&K&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["â Study materials will be tagged with: ",e.jsx("strong",{children:K})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-1 font-display",children:"What would you like to create?"}),Y&&!Y.isPremium&&e.jsxs("p",{className:"text-xs text-muted-foreground mb-4",children:[Math.max(0,10-Y.generationsUsed)," of ",10," free study sets left this month"]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsxs(c,{className:"hover:shadow-lg transition-shadow cursor-pointer",onClick:()=>_?X("flashcard"):te("flashcard"),children:[e.jsxs(d,{children:[e.jsx(m,{className:"text-lg font-display",children:"ð Flashcards"}),e.jsx(u,{children:"Perfect for memorizing terms & definitions"})]}),e.jsx(h,{children:e.jsx(i,{className:"w-full",disabled:$,children:$?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2 animate-spin"}),"Creating..."]}):"Create Flashcards"})})]}),e.jsxs(c,{className:"hover:shadow-lg transition-shadow cursor-pointer",onClick:()=>_?X("quiz"):te("quiz"),children:[e.jsxs(d,{children:[e.jsx(m,{className:"text-lg font-display",children:"ð Practice Quiz"}),e.jsx(u,{children:"Test your knowledge with practice questions"})]}),e.jsx(h,{children:e.jsx(i,{className:"w-full",disabled:$,children:$?e.jsxs(e.Fragment,{children:[e.jsx(z,{className:"w-4 h-4 mr-2 animate-spin"}),"Creating..."]}):"Create Quiz"})})]})]})]}),e.jsx(i,{variant:"outline",onClick:()=>{E(null),M(""),I(null),H(""),Q("")}
13,className:"w-full",children:_?"Upload Different File":"Start Over"})]})]})]})]})]})}export{_ 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.