1import{r as s,j as e}from"./vendor-ui-Cy6CJHCw.js";import{aG as Ne,aC as Se,u as Ie,A as Ae,as as Te,aW as Me,X as Ce,j as Re,aX as Ee,a4 as Ue,B as z,az as _e,V as $e,b as Pe,e as q,aY as ee}from"./index-C2geSD2I.js";import{B as Oe}from"./badge-zD2jkCzY.js";import{U as ze,s as De}from"./UpgradePrompt-jvD-misL.js";import{b as Be,U as te,a as Fe}from"./UsageMeter-BwQKC3qu.js";import{c as Ye}from"./HandGrabbing.es-COJlc8Zt.js";import{m as ae}from"./ListChecks.es-CPXumM1S.js";import{l as We,a as Le}from"./Navbar-CXBvdlAC.js";import{u as He}from"./useAiAllowance-BQ591WC8.js";import{a as Je}from"./guestLimits-C8rVi03X.js";import"./vendor-supabase-CoxeBSpk.js";import"./vendor-react-QIbCqikf.js";import"./graduation-cap-BXwZC40E.js";import"./loader-circle-xINpDhy3.js";import"./sparkles-CQgj_GmY.js";import"./Sparkle.es-_HGX4TBG.js";import"./card-BAYyGEw1.js";import"./scroll-area-arwZhZKj.js";import"./MathMarkdown-CkOKv7bb.js";import"./vendor-markdown-B_M0Zyj-.js";import"./vendor-katex-G9EdgA5J.js";import"./List.es-CdTdM0vV.js";import"./SignOut.es-EVhrBHzU.js";import"./Users.es-DHEBiOW9.js";import"./ThemeToggle-DptW4UaM.js";import"./alert-dialog-BYZQkM2q.js";import"./Crosshair.es-BNVkLhq3.js";const Ge="https://kdcqlpijamnpojvcclxl.supabase.co",re="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtkY3FscGlqYW1ucG9qdmNjbHhsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Njg0NTUwNjcsImV4cCI6MjA4NDAzMTA2N30.Ex7J-2ZjEizIE7UjKYPuO5wJ6HvYLU8f7bZWQbOuBDk",se=a=>a!=null&&a.startsWith("http")?a:`${window.location.origin}${a}`,D=Fe.green;function yt({question:a,onExit:ne}){const B=Ne(),{promptSignup:oe}=Se(),ie=Ie(),S=He(),F=[a.exam==="LC"?"Leaving Cert":a.exam==="JC"?"Junior Cycle":"",a.year,a.level,a.paper_label,`Q${a.question_number}`].filter(Boolean).join(" "),h=s.useRef(null),Y=s.useRef(null),[le,ce]=s.useState(!1),[he,me]=s.useState(0),[m,E]=s.useState("pen"),ue=m!=="scroll",[I,W]=s.useState(!1),L=s.useRef(null),H=()=>{W(!0),window.setTimeout(()=>{var t;return(t=L.current)==null?void 0:t.scrollIntoView({behavior:"smooth",block:"start"})},80)},U=`mathmate-exam-ink-${a.id}`,[de]=s.useState(()=>{try{return localStorage.getItem(U)}catch{return null}}),A=()=>{const t=h.current;if(t)try{const r=t.snapshot();r?localStorage.setItem(U,r):t.hasInk()||localStorage.removeItem(U)}catch{}},j=s.useRef(null),_=()=>{j.current&&window.clearTimeout(j.current),j.current=window.setTimeout(A,150)};s.useEffect(()=>()=>{j.current&&window.clearTimeout(j.current),A()},[]);const ge=async()=>{var d,x,b;const t=Y.current;if(!t||!t.complete||!t.naturalWidth)return null;const r=t.getBoundingClientRect();if(!r.width||!r.height)return null;const u=Math.min(2,Math.max(1,1100/r.width)),l=Math.round(r.width*u),g=Math.round(r.height*u),o=document.createElement("canvas");o.width=l,o.height=g;const p=o.getContext("2d");if(!p)return null;p.fillStyle="#FFFFFF",p.fillRect(0,0,l,g);try{p.drawImage(t,0,0,l,g)}catch{return((d=h.current)==null?void 0:d.exportImage())??null}const n=(x=h.current)==null?void 0:x.snapshot();n&&await new Promise(w=>{const i=new window.Image;i.onload=()=>{p.drawImage(i,0,0,l,g),w()},i.onerror=()=>w(),i.src=n});try{return await ee(o.toDataURL("image/png"))}catch{return((b=h.current)==null?void 0:b.exportImage())??null}},y=s.useRef(void 0),pe=async()=>{if(y.current!==void 0)return y.current;if(!a.marking_scheme_image)return y.current=null,null;try{const r=await(await fetch(a.marking_scheme_image)).blob(),u=await new Promise((l,g)=>{const o=new FileReader;o.onload=()=>l(o.result),o.onerror=g,o.readAsDataURL(r)});y.current=await ee(u)}catch{y.current=null}return y.current},[N,T]=s.useState(!0),[$,f]=s.useState([{role:"assistant",content:"Write your answer straight onto the paper, the way you would in the exam. Ask me for a hint any time. When you're done, press **Check My Answer** under the paper to see the official marking scheme, or ask me to mark your work."}]),[we,J]=s.useState(""),[M,C]=s.useState(!1),[fe,G]=s.useState(!1),[xe,be]=s.useState(!1),ke=s.useRef(`exam-focus-${a.id}-${Date.now()}`),V="mathmate-exam-tutor-width",K=t=>Math.min(640,Math.max(320,t)),[Q,X]=s.useState(()=>{try{const t=parseInt(localStorage.getItem(V)||"",10);return Number.isFinite(t)?K(t):400}catch{return 400}}),R=s.useRef(null),ye=t=>{R.current={x:t.clientX,w:Q},t.currentTarget.setPointerCapture(t.pointerId),t.preventDefault()},ve=t=>{const r=R.current;r&&X(K(r.w+(r.x-t.clientX)))},Z=()=>{R.current&&(R.current=null,X(t=>{try{localStorage.setItem(V,String(t))}catch{}return t}))},P=async(t,r)=>{var p;const u=t.trim();if(!u||M)return;const{data:{session:l}}=await Pe.auth.getSession(),g=$.filter(n=>n.role==="user").length;if((B||!l)&&g>=Je){oe({title:"Create a free account to keep going",description:"You've used your free MathMate messages for this question. A free account gets 15 helps a day, 60 a week, and keeps your work."});return}if(l&&!ie.canAskQuestion()){G(!0);return}if(l&&!B&&S.gate){T(!0);return}J("");const o=$;if(f(n=>[...n,{role:"user",content:u},{role:"assistant",content:""}]),C(!0),A(),l){const n=await ge();if(r!=null&&r.check&&(!n||!((p=h.current)!=null&&p.hasVisibleInk()))){f(c=>{const k=[...c];return k[k.length-1]={role:"assistant",content:"I can't see any writing on the paper yet! Write your answer on the paper first, then press **Check My Answer** and I'll mark it for you."},k}),C(!1);return}const d=r!=null&&r.check?await pe():null,x=o.map(c=>`${c.role==="user"?"Student":"MathMate"}: ${c.content}`).join(` 2 3`),b=r!=null&&r.check?` 4 5THE STUDENT PRESSED "CHECK MY ANSWER". Before any marking, look carefully at the paper image and start by briefly saying what handwritten work you can ACTUALLY SEE on it (one short line). Never invent, assume, or praise work that is not visibly on the paper. If the paper shows no student work beyond the printed question, say y
5ou can't see any written work yet, ask them to write their attempt on the paper, and do NOT assess or award any marks. Only if there IS visible handwritten work: ${d?"the LAST attached image is the official State Examinations Commission marking scheme for this question (check it matches this question; if it clearly doesn't, mark from your own careful working instead and say the official scheme wasn't available). Mark their handwritten attempt against it":"no official marking scheme is attached, so mark their handwritten attempt from your own careful working"}: start with something genuine they did well that you can actually see on the paper, then say exactly what is right, what is missing or wrong, and roughly how many of the ${a.marks} marks this would earn. Finish with the ONE next step that would improve it most.`:"",w=`You are MathMate, helping an Irish secondary school student practise a past state exam question by writing their answer on the exam paper itself. 6 7THE QUESTION: ${F}${a.strand?`, topic: ${a.strand}`:""}, worth ${a.marks} marks. The FIRST attached image is the exam paper; the student writes their answer directly onto it, so any handwriting on that image is their attempt. There may be little or none yet. 8 9RULES: 10- ONLY ever refer to work that is visibly on the attached paper. Never invent, assume, or praise work that is not visibly present â if you can't see any handwriting, say so plainly instead of guessing. 11- Be Socratic: guide with hints and questions, one step at a time. Do NOT hand over the full solution unless they explicitly ask for it after trying. 12- Keep responses SHORT (2-4 sentences). No greetings, get straight to it. 13- Handwriting is often messy and YOU MAY MISREAD IT. If what the student TYPES disagrees with what you think the paper shows, TRUST THEIR TYPED WORDS immediately and move on. Never argue about what is or is not written. 14- If the student states the correct final answer, confirm it warmly and move forward. 15- Use simple language. Keep mathematical terms in English.${b} 16 17${x?`CONVERSATION SO FAR: 18${x} 19 20`:""}STUDENT: ${u}
20`,i=[...n?[n]:[],...d?[d]:[]];let v="";await De({sessionId:`${ke.current}-${l.user.id}`,question:w,subject:"Mathematics",assistanceLevel:r!=null&&r.check?90:60,currentPageNumber:null,isFollowUp:o.some(c=>c.role==="user"),stream:!0,...i.length>0&&{workPhotos:i}},{onText:c=>{v+=c,f(k=>{const O=[...k];return O[O.length-1]={role:"assistant",content:v},O})},onDone:()=>{},onAllowance:c=>S.applyServer(c),onError:c=>{q.error(c.message||"The MathMate Tutor couldn't answer that, try again."),f(k=>k.slice(0,-2))}}),C(!1);return}try{const n=[...o,{role:"user",content:u}].filter(i=>i.content.trim()),d=n.findIndex(i=>i.role==="user"),x=d>=0?n.slice(d):n,b=await fetch(`${Ge}/functions/v1/exam-chat`,{method:"POST",headers:{"Content-Type":"application/json",apikey:re,Authorization:`Bearer ${re}`},body:JSON.stringify({messages:x,question:{exam:a.exam,year:a.year,level:a.level,paper_label:a.paper_label,question_number:a.question_number,strand:a.strand,marks:a.marks},questionImageUrl:se(a.image),markingSchemeText:"",markingSchemeImageUrl:a.marking_scheme_image?se(a.marking_scheme_image):void 0})}),w=await b.json();if(!b.ok||w.error)throw new Error(w.error||"Request failed");f(i=>{const v=[...i];return v[v.length-1]={role:"assistant",content:w.reply},v})}catch{q.error("The MathMate Tutor couldn't answer that, try again."),f(n=>n.slice(0,-2))}finally{C(!1)}},je=()=>{T(!0);const t=h.current;if(!(t!=null&&t.hasVisibleInk())||t.strokeCount()<3){f(r=>[...r,{role:"assistant",content:"Write your answer on the paper first, then I'll check it! Pick the pen in the toolbar, work through the question the way you would in the exam, and press **Check My Answer** when you're done."}]);return}be(!0),P("I've finished my answer, it's written on the paper. Check it against the official marking scheme for me.",{check:!0})};return e.jsxs("div",{className:"mt-1 flex flex-col lg:flex-row gap-4 items-start flex-1 min-h-0",children:[e.jsxs("div",{className:"flex-1 min-w-0
20w-full",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-3",children:[e.jsxs("button",{type:"button",onClick:()=>{A(),ne()},className:"inline-flex h-9 items-center gap-1.5 rounded-lg border border-border px-3 text-sm font-semibold text-foreground hover:bg-[#16A34A]/10 hover:border-[#16A34A]/50 transition-colors",children:[e.jsx(Ae,{className:"h-4 w-4",weight:"bold"}),"All questions"]}),e.jsx("span",{className:"font-bold text-sm",children:F}),a.strand&&e.jsx(Oe,{variant:"outline",className:"text-[10px] h-5",children:a.strand}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[a.marks," marks"]})]}),e.jsx("div",{className:"rounded-2xl border-2 border-[#16A34A]/70 bg-white dark:bg-white overflow-clip",children:e.jsxs("div",{className:"relative",onPointerUp:_,children:[e.jsx("div",{className:"sticky top-[4.5rem] z-30 h-0 flex items-start justify-end pr-2 pointer-events-none",children:e.jsxs("div",{className:"pointer-events-auto mt-2 flex items-center gap-1 rounded-xl border border-black/10 bg-white/95 p-1.5 shadow-md backdrop-blur",role:"toolbar","aria-label":"Drawing tools",children:[e.jsx("button",{type:"button",onClick:()=>E("pen"),"aria-pressed":m==="pen",title:"Pen","aria-label":"Pen",className:`inline-flex h-8 w-8 items-center justify-center rounded-md transition-colors ${m==="pen"?"bg-[#16A34A] text-white":"text-black/60 hover:bg-black/5"}`,children:e.jsx(Te,{weight:"bold",className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:()=>E("eraser"),"aria-pressed":m==="eraser",title:"Rubber","aria-label":"Rubber",className:`inline-flex h-8 w-8 items-center justify-center rounded-md transition-colors ${m==="eraser"?"bg-[#16A34A] text-white":"text-black/60 hover:bg-black/5"}`,children:e.jsx(Me,{weight:"bold",className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-4 w-px bg-black/10","aria-hidden":!0}),e.jsx("button",{type:"button",onClick:()=>{var t;(t=h.current)==null||t.undo(),_()},disabled:he===0,title:"Undo","aria-label":"Undo",className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-black/60 hover:bg-black/5 disabled:opacity-35 transition-colors",children:e.jsx(Ce,{weight:"bold",className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:()=>{var t;(t=h.current)==null||t.clear(),_()},disabled:!le,title:"Clear drawing","aria-label":"Clear drawing",className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-black/60 hover:bg-black/5 disabled:opacity-35 transition-colors",children:e.jsx(Re,{weight:"bold",className:"h-4 w-4"})}),e.jsx("span",{className:"mx-0.5 h-4 w-px bg-black/10","aria-hidden":!0}),e.jsx("button",{type:"button",onClick:()=>E(t=>t==="scroll"?"pen":"scroll"),"aria-pressed":m==="scroll",title:m==="scroll"?"Scrolling, tap to write again":"Scroll the page instead of drawing","aria-label":"Scroll the page",className:`inline-flex h-8 w-8 items-center justify-center rounded-md transition-colors ${m==="scroll"?"bg-[#16A34A] text-white":"text-black/60 hover:bg-black/5"}`,children:e.jsx(Ye,{weight:"bold",className:"h-4 w-4"})})]})}),e.jsx("img",{ref:Y,src:a.image,alt:`Question ${a.question_number}`,className:"w-full block bg-white select-none",draggable:!1}),e.jsx(Ee,{ref:h,active:ue,tool:m==="eraser"?"eraser":"pen",hideToolbar:!0,onInkChange:ce,onUndoCountChange:me,initialInk:de,invertInDark:!1,hideHint:!0})]})}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-3 gap-y-1.5",children:[e.jsxs("button",{type:"button",onClick:()=>I?W(!1):H(),title:"See the official marking scheme and mark your own answer",className:"inline-flex h-10 items-center gap-2 rounded-full bg-[#16A34A] px-5 text-sm font-bold text-white transition-all hover:bg-[#15803D] hover:-translate-y-px",children:[I?e.jsx(Ue,{className:"h-4 w-4",weight:"bold"}):e.jsx(ae,{className:"h-4 w-4",weight:"bold"}),I?"Hide marking scheme":"Check My Answer"]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"Reveals the official marking scheme so you can mark your own work. Want a hand? Ask the MathMate Tutor in the chat."})]}),I&&e.jsxs("div",{ref:L,className:"mt-3 border border-green-200 dark:border-green-800 rounded-xl overflow-hidden scroll-mt-20",children:[e.jsx("div",{className:"bg-green-50 dark:bg-green-900/20 px-4 py-2 border-b border-green-200 dark:border-green-800",children:e.jsx("p",{className:"text-xs font-semibold text-green-700 dark:text-green-300",children:"Marking Scheme"})}),a.marking_scheme_image?e.jsx("img",{src:a.marking_scheme_image,alt:`Marking scheme Q${a.question_number}`,className:"w-full bg-white",loading:"lazy"}):e.jsx("div",{className:"bg-white dark:bg-transparent px-4 py-6 text-sm text-muted-foreground",children:"The official marking scheme for this question isn't available yet. Ask the MathMate Tutor in the chat to mark your work instead."})]})]}),N&&e.jsx("div",{className:"hidden lg:flex shrink-0 items-center justify-center w-3 -mx-1.5 cursor-col-resize touch-none select-none lg:sticky lg:top-16 h-[calc(100vh-5.5rem)] group",role:"separator","aria-orientation":"vertical","aria-label":"Resize the tutor panel",onPointerDown:ye,onPointerMove:ve,onPointerUp:Z,onPointerCancel:Z,children:e.jsx("div",{className:"h-16 w-1 rounded-full bg-black/15 dark:bg-white/20 group-hover:bg-[#16A34A] transition-colors"})}),N?e.jsx("div",{className:"w-full lg:w-[var(--tutor-w)] shrink-0 flex flex-col h-[460px] lg:h-[c
20alc(100vh-5.5rem)] lg:sticky lg:top-16",style:{"--tutor-w":`${Q}px`},children:e.jsx(Be,{accent:"green",chat:$,isAsking:M,input:we,onInputChange:J,onSend:t=>void P(t),onClose:()=>T(!1),placeholder:"Ask the MathMate Tutor about this questionâ¦",inputAccessory:e.jsx(te,{variant:"ring",accent:"green",surface:"exam_focus",allowance:S}),aboveInput:e.jsxs(e.Fragment,{children:[e.jsx(te,{accent:"green",surface:"exam_focus",allowance:S}),e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsxs(z,{size:"sm",variant:"outline",className:`text-xs h-7 gap-1 ${D.solidBtn}`,disabled:M,onClick:()=>void P("Give me one small hint for my next step, don't solve it for me."),children:[e.jsx(_e,{className:"h-3.5 w-3.5"}),"Hint"]}),e.jsxs(z,{size:"sm",variant:"outline",className:`text-xs h-7 gap-1 ${D.outlineBtn}`,disabled:M,onClick:je,children:[e.jsx(ae,{className:"h-3.5 w-3.5"}),"Mark my work"]}),xe&&a.marking_scheme_image&&e.jsxs(z,{size:"sm",variant:"outline",className:`text-xs h-7 gap-1 ${D.outlineBtn}`,onClick:H,children:[e.jsx($e,{className:"h-3.5 w-3.5"}),"View marking scheme"]})]})]})})}):null,e.jsxs("button",{type:"button",onClick:()=>T(t=>!t),"aria-expanded":N,"aria-label":N?"Hide MathMate Tutor":"Ask MathMate Tutor",title:N?"Hide MathMate Tutor":"Ask MathMate Tutor",className:"fixed bottom-3 left-1/2 -translate-x-1/2 z-40 inline-flex h-14 w-14 items-center justify-center rounded-full border-2 border-[#16A34A] bg-white dark:bg-black shadow-lg hover:shadow-[0_0_0_5px_rgba(22,163,74,0.25)] active:scale-95 transition-all",children:[e.jsx("img",{src:We,alt:"",className:"h-8 w-8 object-contain dark:hidden"}),e.jsx("img",{src:Le,alt:"",className:"h-8 w-8 object-contain hidden dark:block"})]}),e.jsx(ze,{open:fe,onOpenChange:G,reason:"daily_limit"})]})}export{yt 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.