iamfebin commited on
Commit
59a8d26
·
1 Parent(s): 49e15af

feat: multi-solution active recall, dual solution views, and specification panel redesign

Browse files
Files changed (49) hide show
  1. algospaced-ui/dist/assets/CreateProblemForm-1KsGQ8w8.js +0 -11
  2. algospaced-ui/dist/assets/CreateProblemForm-Cu_hnDPM.js +11 -0
  3. algospaced-ui/dist/assets/GitHubSyncWindow-Ca288SgB.js +1 -0
  4. algospaced-ui/dist/assets/GitHubSyncWindow-DGw-FVNu.js +0 -1
  5. algospaced-ui/dist/assets/{JourneyPath-Dg9Be99S.js → JourneyPath-BXnxFEFy.js} +0 -0
  6. algospaced-ui/dist/assets/PrincessChamber-CXQLBBNW.js +1 -0
  7. algospaced-ui/dist/assets/PrincessChamber-Cu4RP8Ry.js +0 -1
  8. algospaced-ui/dist/assets/{PythonChallenge-Bfcp7_2V.js → PythonChallenge-3lpSHvfF.js} +1 -1
  9. algospaced-ui/dist/assets/ReviewQueue-BCTxdw81.js +0 -0
  10. algospaced-ui/dist/assets/ReviewQueue-CYwGYMOV.js +0 -0
  11. algospaced-ui/dist/assets/Settings-C3gzd0DF.js +1 -0
  12. algospaced-ui/dist/assets/Settings-Cz_GHQn5.js +0 -1
  13. algospaced-ui/dist/assets/circle-alert-BL6bvZTM.js +1 -0
  14. algospaced-ui/dist/assets/{confetti.module-BEqdENp8.js → confetti.module-nUzO7Zin.js} +1 -1
  15. algospaced-ui/dist/assets/{external-link-yb1gedrc.js → external-link-BGZfX5Bi.js} +1 -1
  16. algospaced-ui/dist/assets/eye-DeJ_5v51.js +0 -1
  17. algospaced-ui/dist/assets/githubSyncService--4Z5jmjP.js +0 -1
  18. algospaced-ui/dist/assets/githubSyncService-CsqBgIfT.js +1 -0
  19. algospaced-ui/dist/assets/index-B05nv6MT.css +0 -0
  20. algospaced-ui/dist/assets/{index-g5jVBiGr.js → index-V2pPJO9M.js} +0 -0
  21. algospaced-ui/dist/assets/index-Y3EVepB8.css +0 -0
  22. algospaced-ui/dist/assets/{info-CU16dSEt.js → info-CAmdZoA6.js} +1 -1
  23. algospaced-ui/dist/assets/{save-CdpRk537.js → save-BgzMM0iu.js} +1 -1
  24. algospaced-ui/dist/index.html +2 -2
  25. algospaced-ui/dist/sw.js +1 -1
  26. algospaced-ui/src/components/CreateProblemForm.tsx +390 -114
  27. algospaced-ui/src/components/ReviewQueue.tsx +39 -10
  28. algospaced-ui/src/components/review/ProblemSpecPanel.tsx +654 -217
  29. algospaced-ui/src/components/review/ReviewHeader.tsx +6 -2
  30. algospaced-ui/src/hooks/useAiReviewer.ts +11 -5
  31. algospaced-ui/src/hooks/useReviewQueue.ts +23 -17
  32. algospaced-ui/src/hooks/useSandboxRunner.ts +13 -9
  33. algospaced-ui/src/services/catalogService.ts +38 -0
  34. algospaced-ui/src/services/reviewService.ts +45 -0
  35. algospaced-ui/src/types/reviewTypes.ts +13 -0
  36. algospaced-ui/src/utils/problemContentParser.tsx +169 -1
  37. core/problem_utils.py +62 -38
  38. db.py +7 -2
  39. gdrive_sync.py +28 -6
  40. main.py +3 -2
  41. routers/explorer.py +21 -0
  42. routers/github_sync.py +59 -27
  43. routers/reviews.py +122 -4
  44. sandbox.py +1 -2
  45. sandbox_db.py +22 -1
  46. tests/unit/test_gdrive_sync.py +69 -0
  47. tests/unit/test_github_sync.py +12 -8
  48. tests/unit/test_problem_utils.py +91 -0
  49. tests/unit/test_reviews_lookup.py +3 -1
algospaced-ui/dist/assets/CreateProblemForm-1KsGQ8w8.js DELETED
@@ -1,11 +0,0 @@
1
- import{a as e,c as t,i as n,t as r}from"./jsx-runtime-j9uSgrFF.js";var i=t(e(),1),a=r(),o=[`Arrays & Hashing`,`Two Pointers`,`Sliding Window`,`Stack`,`Binary Search`,`Linked List`,`Trees`,`Tries`,`Heap / Priority Queue`,`Backtracking`,`Graphs`,`Advanced Graphs`,`1-D Dynamic Programming`,`2-D Dynamic Programming`,`Greedy`,`Intervals`,`Math & Geometry`,`Bit Manipulation`];function s({onClose:e,onSuccess:t,initialProblem:r,mode:s=r?`edit`:`create`}){let c=s===`edit`||!!r,[l,u]=(0,i.useState)(`form`),[d,ee]=(0,i.useState)(``),[f,p]=(0,i.useState)(!1),[m,h]=(0,i.useState)(()=>{if(r?.name)return r.name;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).name||``}catch{}return``}),[g,_]=(0,i.useState)(()=>r?.problem_number!==void 0&&r?.problem_number!==null?r.problem_number:``),[v,y]=(0,i.useState)(()=>{if(r?.pattern)return r.pattern;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).pattern||``}catch{}return`Arrays & Hashing`}),[b,x]=(0,i.useState)(()=>r?.difficulty===`Easy`||r?.difficulty===`Medium`||r?.difficulty===`Hard`?r.difficulty:`Medium`),[S,C]=(0,i.useState)(()=>r?.optimal_time||`O(N)`),[w,T]=(0,i.useState)(()=>r?.optimal_space||`O(N)`),[E,D]=(0,i.useState)(()=>r?.description||``),[O,k]=(0,i.useState)(()=>r?.examples&&Array.isArray(r.examples)&&r.examples.length>0?r.examples.map(e=>typeof e==`string`?{input:e,output:``,explanation:``}:{input:String(e?.input??``),output:String(e?.output??``),explanation:e?.explanation||``}):[{input:``,output:``,explanation:``}]),[A,j]=(0,i.useState)(()=>r?.constraints?Array.isArray(r.constraints)?r.constraints.join(`
2
- `):String(r.constraints):``),[M,N]=(0,i.useState)(()=>r?.how_to_solve||``),[P,F]=(0,i.useState)(()=>{if(r?.reference_code)return r.reference_code;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).code||``}catch{}return``}),[I,L]=(0,i.useState)(!0),[R,z]=(0,i.useState)(``),[B,V]=(0,i.useState)(``),[H,U]=(0,i.useState)(!1),[W,G]=(0,i.useState)(!1),[K,q]=(0,i.useState)(!1),[J,Y]=(0,i.useState)(!1);i.useEffect(()=>{c||localStorage.removeItem(`algospaced_prefill_draft`)},[c]);let X=async()=>{let{data:{session:e}}=await n.auth.getSession(),t=e?e.access_token:`sandbox`,r=localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``,i=localStorage.getItem(`algospaced_custom_ai_provider`)||`default`,a={"Content-Type":`application/json`,Authorization:`Bearer ${t}`};return i&&i!=="default"&&r&&r.trim()&&(a[`x-custom-api-key`]=r.trim(),a[`x-gemini-api-key`]=r.trim(),a[`x-ai-provider`]=i),a},Z=async()=>{if(d.trim()){p(!0),z(``);try{let e=await X(),t=await fetch(`/api/explorer/problems/fetch-leetcode`,{method:`POST`,headers:e,body:JSON.stringify({query:d.trim()})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&_(e.problem_number),e.title&&h(e.title),e.difficulty&&x(e.difficulty),e.pattern&&y(e.pattern),e.optimal_time&&C(e.optimal_time),e.optimal_space&&T(e.optimal_space),e.description&&D(e.description),e.how_to_solve&&N(e.how_to_solve),e.starter_code&&!P.trim()&&F(e.starter_code),Array.isArray(e.examples)&&e.examples.length>0&&k(e.examples),Array.isArray(e.constraints)?j(e.constraints.join(`
3
- `)):typeof e.constraints==`string`&&j(e.constraints)}else{let e=await t.json();z(e.detail||`Failed to fetch LeetCode problem data.`)}}catch{z(`Fetch request failed due to connection error.`)}finally{p(!1)}}},Q=async()=>{if(m.trim()||P.trim()){Y(!0),z(``);try{let e=await X(),t=await fetch(`/api/explorer/problems/prefill`,{method:`POST`,headers:e,body:JSON.stringify({name:m,code:P})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&_(e.problem_number),e.title&&!m&&h(e.title),e.pattern&&y(e.pattern),e.difficulty&&x(e.difficulty),e.optimal_time&&C(e.optimal_time),e.optimal_space&&T(e.optimal_space),e.description&&D(e.description),e.reference_code&&!P.trim()&&F(e.reference_code)}else{let e=await t.json();z(e.detail||`Prefill failed.`)}}catch{z(`Prefill request failed due to connection error.`)}finally{Y(!1)}}},te=async()=>{if(!m.trim()&&!P.trim()){z(`Please enter a problem name or code first.`);return}G(!0),z(``);try{let e=await X(),t=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:e,body:JSON.stringify({field:`intuition`,title:m,code:P,description:E})});if(t.ok){let e=await t.json();e.how_to_solve&&N(e.how_to_solve)}else{let e=await t.json();z(e.detail||`Failed to generate intuition.`)}}catch{z(`Intuition generator failed due to connection error.`)}finally{G(!1)}},ne=async()=>{if(!P.trim()){z(`Please enter some Python code to format.`);return}q(!0),z(``);try{let e=await X(),t=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:e,body:JSON.stringify({field:`comments`,title:m,code:P})});if(t.ok){let e=await t.json();e.formatted_code&&F(e.formatted_code)}else{let e=await t.json();z(e.detail||`Failed to format code.`)}}catch{z(`Code formatter failed due to connection error.`)}finally{q(!1)}},re=async n=>{if(n.preventDefault(),!m.trim()){z(`Problem name cannot be empty`);return}U(!0),z(``),V(``);try{let n=await X(),i=A.split(`
4
- `).map(e=>e.trim()).filter(Boolean),a;if(c&&r){let e=r.id||(r.problem_number?String(r.problem_number):``)||m.trim();a=await fetch(`/api/explorer/problems/${encodeURIComponent(e)}`,{method:`PUT`,headers:n,body:JSON.stringify({name:m.trim(),pattern:v.trim()||`General`,difficulty:b,reference_code:P,description:E,problem_number:g===``?null:Number(g),optimal_time:S,optimal_space:w,examples:O.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:M})})}else a=await fetch(`/api/explorer/problems/create`,{method:`POST`,headers:n,body:JSON.stringify({name:m.trim(),pattern:v.trim()||`General`,difficulty:b,reference_code:P,description:E,problem_number:g===``?null:Number(g),optimal_time:S,optimal_space:w,examples:O.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:M,sync_to_gdoc:I})});let o=await a.json();a.ok&&(o.success||o.problem_id)?(V(c?`Problem updated successfully!`:`Problem saved and synced successfully!`),setTimeout(()=>{t(),e()},1e3)):z(o.detail||(c?`Failed to update problem.`:`Failed to create problem.`))}catch{z(`Connection timed out.`)}finally{U(!1)}},ie=()=>{k([...O,{input:``,output:``,explanation:``}])},ae=e=>{O.length<=1||k(O.filter((t,n)=>n!==e))},$=(e,t,n)=>{let r=[...O];r[e]={...r[e],[t]:n},k(r)};return(0,a.jsxs)(`form`,{onSubmit:re,className:`flex flex-col h-full bg-[#fdf8e1] text-ink-black font-sans overflow-hidden`,children:[(0,a.jsxs)(`div`,{className:`bg-[#f0e6c8] p-2.5 border-b-2 border-ink-black flex flex-col gap-2 shrink-0`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`font-arcade text-xs text-primary-purple`,children:`✦`}),(0,a.jsx)(`h2`,{className:`text-xs font-bold font-arcade tracking-tight uppercase`,children:c?`Edit Problem Specification`:`Problem & Note Studio`}),c&&(0,a.jsx)(`span`,{className:`text-[9px] bg-primary-purple/10 text-primary-purple font-mono px-1.5 py-0.5 rounded border border-primary-purple/30 font-bold`,children:`EDIT MODE`})]}),(0,a.jsxs)(`div`,{className:`flex border-2 border-ink-black bg-white rounded overflow-hidden shadow-[1px_1px_0px_#1E293B]`,children:[(0,a.jsx)(`button`,{type:`button`,onClick:()=>u(`form`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${l===`form`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`✏️ Editor`}),(0,a.jsx)(`button`,{type:`button`,onClick:()=>u(`preview`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${l===`preview`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`📄 Doc Preview`})]})]}),(0,a.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,a.jsx)(`input`,{type:`text`,value:d,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),Z())},placeholder:`Paste LeetCode URL (e.g. https://leetcode.com/problems/two-sum/) or Title...`,className:`flex-1 bg-white border-2 border-ink-black px-2 py-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium`}),(0,a.jsxs)(`button`,{type:`button`,onClick:Z,disabled:f||!d.trim(),className:`bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 text-ink-black font-arcade text-[9px] font-bold px-2.5 py-1.5 border-2 border-ink-black shadow-[1px_1px_0px_#1E293B] active:translate-y-0.5 cursor-pointer flex items-center gap-1 shrink-0`,children:[(0,a.jsx)(`span`,{children:`⚡`}),` `,f?`FETCHING...`:`FETCH LEETCODE`]})]})]}),R&&(0,a.jsxs)(`div`,{className:`mx-3 mt-2 p-2 border-2 border-red-500 bg-red-50 text-red-800 text-[11px] font-mono leading-relaxed shrink-0`,children:[`⚠️ `,R]}),B&&(0,a.jsxs)(`div`,{className:`mx-3 mt-2 p-2 border-2 border-green-500 bg-green-50 text-green-800 text-[11px] font-mono leading-relaxed shrink-0`,children:[`✅ `,B]}),(0,a.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar p-3 space-y-3`,children:l===`form`?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`grid grid-cols-12 gap-2`,children:[(0,a.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Problem #:`}),(0,a.jsx)(`input`,{type:`number`,value:g,onChange:e=>_(e.target.value===``?``:Number(e.target.value)),placeholder:`e.g. 1`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-bold`})]}),(0,a.jsxs)(`div`,{className:`col-span-6 flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Title:`}),(0,a.jsxs)(`button`,{type:`button`,onClick:Q,disabled:J||!m.trim()&&!P.trim(),className:`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer`,children:[(0,a.jsx)(`span`,{children:`✦`}),` `,J?`...`:`AUTO-FILL`]})]}),(0,a.jsx)(`input`,{type:`text`,required:!0,value:m,onChange:e=>h(e.target.value),placeholder:`e.g. Two Sum`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-bold`})]}),(0,a.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Difficulty:`}),(0,a.jsxs)(`select`,{value:b,onChange:e=>x(e.target.value),className:`border-2 border-ink-black p-1.5 text-xs font-bold outline-none cursor-pointer ${b===`Easy`?`bg-emerald-100 text-emerald-900`:b===`Medium`?`bg-amber-100 text-amber-900`:`bg-rose-100 text-rose-900`}`,children:[(0,a.jsx)(`option`,{value:`Easy`,children:`Easy`}),(0,a.jsx)(`option`,{value:`Medium`,children:`Medium`}),(0,a.jsx)(`option`,{value:`Hard`,children:`Hard`})]})]})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Pattern / Topic:`}),(0,a.jsx)(`input`,{type:`text`,list:`pattern-suggestions`,value:v,onChange:e=>y(e.target.value),placeholder:`e.g. Arrays & Hashing`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium`}),(0,a.jsx)(`datalist`,{id:`pattern-suggestions`,children:o.map(e=>(0,a.jsx)(`option`,{value:e},e))})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Time Complexity:`}),(0,a.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(e.target.value),placeholder:`e.g. O(N)`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-semibold`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Space Complexity:`}),(0,a.jsx)(`input`,{type:`text`,value:w,onChange:e=>T(e.target.value),placeholder:`e.g. O(1)`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-semibold`})]})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Problem Description:`}),(0,a.jsx)(`textarea`,{value:E,onChange:e=>D(e.target.value),placeholder:`Given an array of integers nums and an integer target...`,className:`bg-white border-2 border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-20 resize-y leading-relaxed`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1.5 bg-[#f6edd2] p-2.5 border-2 border-ink-black rounded`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`🧪`}),` Examples (`,O.length,`)`]}),(0,a.jsx)(`button`,{type:`button`,onClick:ie,className:`text-[9px] font-bold px-2 py-0.5 border border-ink-black bg-white hover:bg-slate-100 cursor-pointer shadow-[1px_1px_0px_#1E293B]`,children:`+ Add Example`})]}),O.map((e,t)=>(0,a.jsxs)(`div`,{className:`bg-white border border-ink-black p-2 space-y-1.5 rounded relative text-xs`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`span`,{className:`font-bold text-[10px] text-slate-500`,children:[`Example `,t+1,`:`]}),O.length>1&&(0,a.jsx)(`button`,{type:`button`,onClick:()=>ae(t),className:`text-[10px] text-red-600 hover:text-red-800 font-bold`,children:`✕`})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,a.jsx)(`input`,{type:`text`,value:e.input,onChange:e=>$(t,`input`,e.target.value),placeholder:`Input: nums = [2,7,11,15], target = 9`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] font-mono outline-none`}),(0,a.jsx)(`input`,{type:`text`,value:e.output,onChange:e=>$(t,`output`,e.target.value),placeholder:`Output: [0,1]`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] font-mono outline-none`})]}),(0,a.jsx)(`input`,{type:`text`,value:e.explanation||``,onChange:e=>$(t,`explanation`,e.target.value),placeholder:`Explanation (Optional): Because nums[0] + nums[1] == 9, we return [0, 1].`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] outline-none w-full`})]},t))]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Constraints (1 per line):`}),(0,a.jsx)(`textarea`,{value:A,onChange:e=>j(e.target.value),placeholder:`2 <= nums.length <= 10^4
5
- -10^9 <= nums[i] <= 10^9
6
- Only one valid answer exists.`,className:`bg-white border-2 border-ink-black p-2 text-xs font-mono outline-none focus:ring-1 focus:ring-primary-purple h-16 resize-y leading-snug`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`💡`}),` "How to solve?" Intuition:`]}),(0,a.jsxs)(`button`,{type:`button`,onClick:te,disabled:W,className:`text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 shadow-[1px_1px_0px_#1E293B] cursor-pointer`,children:[(0,a.jsx)(`span`,{children:`✦`}),` `,W?`GENERATING...`:`AI INTUITION`]})]}),(0,a.jsx)(`textarea`,{value:M,onChange:e=>N(e.target.value),placeholder:`Explain the mental model, dummy nodes, invariants, or two-pointer logic...`,className:`bg-white border-2 border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-24 resize-y leading-relaxed`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`🐍`}),` Solution Code (Python):`]}),(0,a.jsxs)(`button`,{type:`button`,onClick:ne,disabled:K||!P.trim(),className:`text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black bg-[#a7f3d0] hover:bg-emerald-300 disabled:opacity-50 flex items-center gap-1 shadow-[1px_1px_0px_#1E293B] cursor-pointer text-emerald-950`,children:[(0,a.jsx)(`span`,{children:`✨`}),` `,K?`FORMATTING...`:`ADD EMOJI COMMENTS`]})]}),(0,a.jsx)(`textarea`,{value:P,onChange:e=>F(e.target.value),placeholder:`def twoSum(nums: list[int], target: int) -> list[int]:
7
- # 1. 🗺️ Initialize lookup map
8
- seen = {}
9
- ...
10
- return []`,className:`bg-slate-900 text-[#4ADE80] font-mono p-2.5 border-2 border-ink-black rounded outline-none h-44 text-xs leading-relaxed resize-y w-full`})]})]}):(0,a.jsxs)(`div`,{className:`bg-white border-2 border-ink-black p-6 rounded shadow-sm font-sans space-y-4 text-slate-800`,children:[(0,a.jsx)(`div`,{className:`border-b pb-2`,children:(0,a.jsx)(`span`,{className:`text-[10px] font-mono uppercase bg-purple-100 text-purple-800 px-2 py-0.5 rounded font-bold`,children:`Google Doc Preview (Exact formatting preview)`})}),(0,a.jsxs)(`h1`,{className:`text-xl font-bold text-slate-900`,children:[g?`${g}. `:``,m||`Problem Title`]}),(0,a.jsx)(`div`,{children:(0,a.jsx)(`span`,{className:`text-xs font-bold px-2.5 py-0.5 rounded ${b===`Easy`?`bg-emerald-100 text-[#137c36]`:b===`Medium`?`bg-amber-100 text-[#c06100]`:`bg-rose-100 text-[#c5221f]`}`,children:b})}),E&&(0,a.jsx)(`div`,{className:`text-xs text-slate-700 leading-relaxed whitespace-pre-wrap`,children:E}),O.some(e=>e.input.trim()||e.output.trim())&&(0,a.jsx)(`div`,{className:`space-y-3 pt-2`,children:O.map((e,t)=>(0,a.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-slate-800`,children:[`Example `,t+1,`:`]}),e.input&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Input: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.input})]}),e.output&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Output: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.output})]}),e.explanation&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Explanation: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.explanation})]})]},t))}),A&&(0,a.jsxs)(`div`,{className:`space-y-1.5 pt-2`,children:[(0,a.jsx)(`div`,{className:`font-bold text-xs text-slate-800`,children:`Constraints:`}),(0,a.jsx)(`ul`,{className:`list-disc pl-5 text-xs space-y-1`,children:A.split(`
11
- `).filter(Boolean).map((e,t)=>(0,a.jsx)(`li`,{children:(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.replace(/^[•\-*]\s*/,``)})},t))})]}),(0,a.jsxs)(`div`,{className:`pt-2`,children:[(0,a.jsx)(`div`,{className:`font-bold text-xs text-slate-800`,children:`Method:`}),(0,a.jsx)(`div`,{className:`text-xs text-slate-600`,children:`Pattern:`}),(0,a.jsx)(`h3`,{className:`text-base font-bold text-primary-purple mt-0.5`,children:v||`Standard`})]}),(0,a.jsxs)(`div`,{className:`space-y-1 text-xs`,children:[(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`font-bold text-slate-800`,children:`Time Complexity: `}),(0,a.jsx)(`span`,{className:`font-mono text-slate-900`,children:S})]}),(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`font-bold text-slate-800`,children:`Space Complexity: `}),(0,a.jsx)(`span`,{className:`font-mono text-slate-900`,children:w})]})]}),M&&(0,a.jsxs)(`div`,{className:`space-y-1.5 pt-2`,children:[(0,a.jsx)(`h3`,{className:`text-sm font-bold text-slate-900`,children:`How to solve?`}),(0,a.jsx)(`div`,{className:`text-xs text-slate-700 leading-relaxed whitespace-pre-wrap`,children:M})]}),P&&(0,a.jsx)(`div`,{className:`pt-2`,children:(0,a.jsx)(`div`,{className:`bg-[#f8fafc] border border-slate-300 p-3 rounded font-mono text-[11.5px] leading-relaxed text-slate-900 overflow-x-auto whitespace-pre`,children:P})})]})}),(0,a.jsxs)(`div`,{className:`p-3 bg-[#f0e6c8] border-t-2 border-ink-black flex flex-wrap items-center justify-between gap-2 shrink-0`,children:[c?(0,a.jsxs)(`div`,{className:`text-[11px] text-slate-600 font-mono flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-primary-purple inline-block`}),`Editing #`,r?.problem_number??`—`,` `,r?.name]}):(0,a.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer select-none`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:I,onChange:e=>L(e.target.checked),className:`w-4 h-4 accent-primary-purple cursor-pointer`}),(0,a.jsx)(`span`,{children:`Format & Sync to Google Doc`})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 py-1.5 bg-white hover:bg-slate-50 border-2 border-ink-black text-xs font-bold cursor-pointer`,children:`CANCEL`}),(0,a.jsxs)(`button`,{type:`submit`,disabled:H,className:`px-4 py-1.5 bg-primary-purple hover:bg-purple-600 text-white font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{children:c?`✏️`:`💾`}),` `,H?c?`UPDATING...`:`SAVING...`:c?`UPDATE PROBLEM`:`SAVE SOLUTION`]})]})]})]})}export{s as default};
 
 
 
 
 
 
 
 
 
 
 
 
algospaced-ui/dist/assets/CreateProblemForm-Cu_hnDPM.js ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import{a as e,c as t,i as n,t as r}from"./jsx-runtime-j9uSgrFF.js";var i=t(e(),1),a=r(),o=[`Arrays & Hashing`,`Two Pointers`,`Sliding Window`,`Stack`,`Binary Search`,`Linked List`,`Trees`,`Tries`,`Heap / Priority Queue`,`Backtracking`,`Graphs`,`Advanced Graphs`,`1-D Dynamic Programming`,`2-D Dynamic Programming`,`Greedy`,`Intervals`,`Math & Geometry`,`Bit Manipulation`];function s(){return typeof crypto<`u`&&typeof crypto.randomUUID==`function`?`sol-${crypto.randomUUID()}`:`sol-${Date.now()}`}function c({onClose:e,onSuccess:t,initialProblem:r,mode:c=r?`edit`:`create`}){let l=c===`edit`||!!r,[u,d]=(0,i.useState)(`form`),[f,p]=(0,i.useState)(``),[ee,m]=(0,i.useState)(!1),[h,g]=(0,i.useState)(()=>{if(r?.name)return r.name;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).name||``}catch{}return``}),[_,v]=(0,i.useState)(()=>r?.problem_number!==void 0&&r?.problem_number!==null?r.problem_number:``),[y,b]=(0,i.useState)(()=>{if(r?.pattern)return r.pattern;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).pattern||``}catch{}return`Arrays & Hashing`}),[x,S]=(0,i.useState)(()=>r?.difficulty===`Easy`||r?.difficulty===`Medium`||r?.difficulty===`Hard`?r.difficulty:`Medium`),[C,w]=(0,i.useState)(()=>r?.optimal_time||`O(N)`),[T,E]=(0,i.useState)(()=>r?.optimal_space||`O(1)`),[D,O]=(0,i.useState)(()=>r?.description||``),[k,A]=(0,i.useState)(()=>r?.examples&&Array.isArray(r.examples)&&r.examples.length>0?r.examples.map(e=>typeof e==`string`?{input:e,output:``,explanation:``}:{input:String(e?.input??``),output:String(e?.output??``),explanation:e?.explanation||``}):[{input:``,output:``,explanation:``}]),[j,M]=(0,i.useState)(()=>r?.constraints?Array.isArray(r.constraints)?r.constraints.join(`
2
+ `):String(r.constraints):``),[te,ne]=(0,i.useState)(()=>r?.how_to_solve||``),[N,P]=(0,i.useState)(()=>{if(r?.reference_code)return r.reference_code;try{let e=localStorage.getItem(`algospaced_prefill_draft`);if(e)return JSON.parse(e).code||``}catch{}return``}),[F,I]=(0,i.useState)(()=>{if(r?.solutions&&Array.isArray(r.solutions)&&r.solutions.length>0)return r.solutions.map((e,t)=>({id:e.id||`sol-${t+1}`,name:e.name||`Method ${t+1}`,pattern:e.pattern||r.pattern||`Arrays & Hashing`,time_complexity:e.time_complexity||r.optimal_time||`O(N)`,space_complexity:e.space_complexity||r.optimal_space||`O(1)`,code:e.code||``,explanation:e.explanation||``,is_optimal:e.is_optimal??t===0}));let e=r?.reference_code||``,t=r?.pattern||`Arrays & Hashing`;try{let n=localStorage.getItem(`algospaced_prefill_draft`);if(n){let r=JSON.parse(n);r.code&&!e&&(e=r.code),r.pattern&&!t&&(t=r.pattern)}}catch{}return[{id:`sol-1`,name:`Optimal Method`,pattern:t,time_complexity:r?.optimal_time||`O(N)`,space_complexity:r?.optimal_space||`O(1)`,code:e,explanation:r?.how_to_solve||``,is_optimal:!0}]}),[L,R]=(0,i.useState)(0),z=F[L]||F[0]||{id:`sol-1`,name:`Method 1`,pattern:`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:!0},B=e=>{I(t=>{let n=[...t],r=L<n.length?L:0;return n[r]={...n[r],...e},e.is_optimal&&(n.forEach((e,t)=>{t!==r&&(e.is_optimal=!1)}),n[r].time_complexity&&w(n[r].time_complexity),n[r].space_complexity&&E(n[r].space_complexity),n[r].pattern&&b(n[r].pattern)),n})},re=()=>{let e=F.length+1,t={id:s(),name:`Method ${e}`,pattern:y||`Arrays & Hashing`,time_complexity:`O(N)`,space_complexity:`O(1)`,code:``,explanation:``,is_optimal:F.length===0};I(e=>[...e,t]),R(F.length)},ie=e=>{F.length<=1||(I(t=>{let n=t.filter((t,n)=>n!==e);return n.some(e=>e.is_optimal)||(n[0].is_optimal=!0),n}),L>=F.length-1&&R(Math.max(0,F.length-2)))},[V,ae]=(0,i.useState)(!0),[H,U]=(0,i.useState)(``),[W,G]=(0,i.useState)(``),[K,q]=(0,i.useState)(!1),[J,Y]=(0,i.useState)(!1),[X,Z]=(0,i.useState)(!1),[oe,se]=(0,i.useState)(!1);i.useEffect(()=>{l||localStorage.removeItem(`algospaced_prefill_draft`)},[l]);let Q=async()=>{let{data:{session:e}}=await n.auth.getSession(),t=e?e.access_token:`sandbox`,r=localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``,i=localStorage.getItem(`algospaced_custom_ai_provider`)||`default`,a={"Content-Type":`application/json`,Authorization:`Bearer ${t}`};return i&&i!=="default"&&r&&r.trim()&&(a[`x-custom-api-key`]=r.trim(),a[`x-gemini-api-key`]=r.trim(),a[`x-ai-provider`]=i),a},ce=async()=>{if(f.trim()){m(!0),U(``);try{let e=await Q(),t=await fetch(`/api/explorer/problems/fetch-leetcode`,{method:`POST`,headers:e,body:JSON.stringify({query:f.trim()})});if(t.ok){let e=await t.json();e.problem_number!==void 0&&e.problem_number!==null&&v(e.problem_number),e.title&&g(e.title),e.difficulty&&S(e.difficulty),e.pattern&&b(e.pattern),e.optimal_time&&w(e.optimal_time),e.optimal_space&&E(e.optimal_space),e.description&&O(e.description),e.how_to_solve&&ne(e.how_to_solve),e.starter_code&&!N.trim()&&P(e.starter_code),I(t=>{let n=[...t],r={...n[L]};return e.pattern&&(r.pattern=e.pattern),e.optimal_time&&(r.time_complexity=e.optimal_time),e.optimal_space&&(r.space_complexity=e.optimal_space),e.how_to_solve&&(r.explanation=e.how_to_solve),e.starter_code&&!r.code?.trim()&&(r.code=e.starter_code),n[L]=r,n}),Array.isArray(e.examples)&&e.examples.length>0&&A(e.examples),Array.isArray(e.constraints)?M(e.constraints.join(`
3
+ `)):typeof e.constraints==`string`&&M(e.constraints)}else{let e=await t.json();U(e.detail||`Failed to fetch LeetCode problem data.`)}}catch{U(`Fetch request failed due to connection error.`)}finally{m(!1)}}},le=async()=>{let e=z.code||N;if(h.trim()||e.trim()){se(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/prefill`,{method:`POST`,headers:t,body:JSON.stringify({name:h,code:e})});if(n.ok){let t=await n.json();t.problem_number!==void 0&&t.problem_number!==null&&v(t.problem_number),t.title&&!h&&g(t.title),t.pattern&&b(t.pattern),t.difficulty&&S(t.difficulty),t.optimal_time&&w(t.optimal_time),t.optimal_space&&E(t.optimal_space),t.description&&O(t.description),t.reference_code&&!e.trim()&&P(t.reference_code),I(e=>{let n=[...e],r={...n[L]};return t.pattern&&(r.pattern=t.pattern),t.optimal_time&&(r.time_complexity=t.optimal_time),t.optimal_space&&(r.space_complexity=t.optimal_space),t.reference_code&&!r.code?.trim()&&(r.code=t.reference_code),n[L]=r,n})}else{let e=await n.json();U(e.detail||`Prefill failed.`)}}catch{U(`Prefill request failed due to connection error.`)}finally{se(!1)}}},ue=async()=>{let e=z.code||N;if(!h.trim()&&!e.trim()){U(`Please enter a problem name or code first.`);return}Y(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:t,body:JSON.stringify({field:`intuition`,title:h,code:e,description:D})});if(n.ok){let e=await n.json();e.how_to_solve&&(ne(e.how_to_solve),B({explanation:e.how_to_solve}))}else{let e=await n.json();U(e.detail||`Failed to generate intuition.`)}}catch{U(`Intuition generator failed due to connection error.`)}finally{Y(!1)}},de=async()=>{let e=z.code||N;if(!e.trim()){U(`Please enter some Python code to format.`);return}Z(!0),U(``);try{let t=await Q(),n=await fetch(`/api/explorer/problems/assist-field`,{method:`POST`,headers:t,body:JSON.stringify({field:`comments`,title:h,code:e})});if(n.ok){let e=await n.json();e.formatted_code&&(P(e.formatted_code),B({code:e.formatted_code}))}else{let e=await n.json();U(e.detail||`Failed to format code.`)}}catch{U(`Code formatter failed due to connection error.`)}finally{Z(!1)}},fe=async n=>{if(n.preventDefault(),!h.trim()){U(`Problem name cannot be empty`);return}q(!0),U(``),G(``);try{let n=await Q(),i=j.split(`
4
+ `).map(e=>e.trim()).filter(Boolean),a=F.find(e=>e.is_optimal)||F[0],o=a?.pattern||y.trim()||`General`,s=a?.code||N,c=a?.explanation||te,u=C||a?.time_complexity||`O(N)`,d=T||a?.space_complexity||`O(1)`,f;if(l&&r){let e=r.id||(r.problem_number?String(r.problem_number):``)||h.trim();f=await fetch(`/api/explorer/problems/${encodeURIComponent(e)}`,{method:`PUT`,headers:n,body:JSON.stringify({name:h.trim(),pattern:o,difficulty:x,reference_code:s,description:D,problem_number:_===``?null:Number(_),optimal_time:u,optimal_space:d,examples:k.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:c,solutions:F})})}else f=await fetch(`/api/explorer/problems/create`,{method:`POST`,headers:n,body:JSON.stringify({name:h.trim(),pattern:o,difficulty:x,reference_code:s,description:D,problem_number:_===``?null:Number(_),optimal_time:u,optimal_space:d,examples:k.filter(e=>e.input.trim()||e.output.trim()),constraints:i,how_to_solve:c,sync_to_gdoc:V,solutions:F})});let p=await f.json();f.ok&&(p.success||p.problem_id)?(G(l?`Problem updated successfully!`:`Problem saved and synced successfully!`),setTimeout(()=>{t(),e()},1e3)):U(p.detail||(l?`Failed to update problem.`:`Failed to create problem.`))}catch{U(`Connection timed out.`)}finally{q(!1)}},pe=()=>{A([...k,{input:``,output:``,explanation:``}])},me=e=>{k.length<=1||A(k.filter((t,n)=>n!==e))},$=(e,t,n)=>{let r=[...k];r[e]={...r[e],[t]:n},A(r)};return(0,a.jsxs)(`form`,{onSubmit:fe,className:`flex flex-col h-full bg-[#fdf8e1] text-ink-black font-sans overflow-hidden`,children:[(0,a.jsxs)(`div`,{className:`bg-[#f0e6c8] p-2.5 border-b-2 border-ink-black flex flex-col gap-2 shrink-0`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`font-arcade text-xs text-primary-purple`,children:`✦`}),(0,a.jsx)(`h2`,{className:`text-xs font-bold font-arcade tracking-tight uppercase`,children:l?`Edit Problem Specification`:`Problem & Note Studio`}),l&&(0,a.jsx)(`span`,{className:`text-[9px] bg-primary-purple/10 text-primary-purple font-mono px-1.5 py-0.5 rounded border border-primary-purple/30 font-bold`,children:`EDIT MODE`})]}),(0,a.jsxs)(`div`,{className:`flex border-2 border-ink-black bg-white rounded overflow-hidden shadow-[1px_1px_0px_#1E293B]`,children:[(0,a.jsx)(`button`,{type:`button`,onClick:()=>d(`form`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${u===`form`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`✏️ Editor`}),(0,a.jsx)(`button`,{type:`button`,onClick:()=>d(`preview`),className:`px-3 py-1 text-[10px] font-bold uppercase transition-colors ${u===`preview`?`bg-primary-purple text-white`:`hover:bg-slate-100`}`,children:`📄 Doc Preview`})]})]}),(0,a.jsxs)(`div`,{className:`flex gap-1.5 items-center`,children:[(0,a.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),ce())},placeholder:`Paste LeetCode URL (e.g. https://leetcode.com/problems/two-sum/) or Title...`,className:`flex-1 bg-white border-2 border-ink-black px-2 py-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium`}),(0,a.jsxs)(`button`,{type:`button`,onClick:ce,disabled:ee||!f.trim(),className:`bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 text-ink-black font-arcade text-[9px] font-bold px-2.5 py-1.5 border-2 border-ink-black shadow-[1px_1px_0px_#1E293B] active:translate-y-0.5 cursor-pointer flex items-center gap-1 shrink-0`,children:[(0,a.jsx)(`span`,{children:`⚡`}),` `,ee?`FETCHING...`:`FETCH LEETCODE`]})]})]}),H&&(0,a.jsxs)(`div`,{className:`mx-3 mt-2 p-2 border-2 border-red-500 bg-red-50 text-red-800 text-[11px] font-mono leading-relaxed shrink-0`,children:[`⚠️ `,H]}),W&&(0,a.jsxs)(`div`,{className:`mx-3 mt-2 p-2 border-2 border-green-500 bg-green-50 text-green-800 text-[11px] font-mono leading-relaxed shrink-0`,children:[`✅ `,W]}),(0,a.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-scrollbar p-3 space-y-3`,children:u===`form`?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(`div`,{className:`grid grid-cols-12 gap-2`,children:[(0,a.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Problem #:`}),(0,a.jsx)(`input`,{type:`number`,value:_,onChange:e=>v(e.target.value===``?``:Number(e.target.value)),placeholder:`e.g. 1`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-bold`})]}),(0,a.jsxs)(`div`,{className:`col-span-6 flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Title:`}),(0,a.jsxs)(`button`,{type:`button`,onClick:le,disabled:oe||!h.trim()&&!z.code?.trim(),className:`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer`,children:[(0,a.jsx)(`span`,{children:`✦`}),` `,oe?`...`:`AUTO-FILL`]})]}),(0,a.jsx)(`input`,{type:`text`,required:!0,value:h,onChange:e=>g(e.target.value),placeholder:`e.g. Two Sum`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-bold`})]}),(0,a.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Difficulty:`}),(0,a.jsxs)(`select`,{value:x,onChange:e=>S(e.target.value),className:`border-2 border-ink-black p-1.5 text-xs font-bold outline-none cursor-pointer ${x===`Easy`?`bg-emerald-100 text-emerald-900`:x===`Medium`?`bg-amber-100 text-amber-900`:`bg-rose-100 text-rose-900`}`,children:[(0,a.jsx)(`option`,{value:`Easy`,children:`Easy`}),(0,a.jsx)(`option`,{value:`Medium`,children:`Medium`}),(0,a.jsx)(`option`,{value:`Hard`,children:`Hard`})]})]})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 bg-[#f6edd2] p-2 border-2 border-ink-black rounded`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`⏱️`}),` Target Optimal Time:`]}),(0,a.jsx)(`span`,{className:`text-[8px] font-mono text-slate-500`,children:`(hidden behind spoiler on review)`})]}),(0,a.jsx)(`input`,{type:`text`,value:C,onChange:e=>w(e.target.value),placeholder:`e.g. O(N)`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-bold`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`📦`}),` Target Optimal Space:`]}),(0,a.jsx)(`span`,{className:`text-[8px] font-mono text-slate-500`,children:`(hidden behind spoiler on review)`})]}),(0,a.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`e.g. O(1)`,className:`bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-bold`})]})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Problem Description:`}),(0,a.jsx)(`textarea`,{value:D,onChange:e=>O(e.target.value),placeholder:`Given an array of integers nums and an integer target...`,className:`bg-white border-2 border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-20 resize-y leading-relaxed`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1.5 bg-[#f6edd2] p-2.5 border-2 border-ink-black rounded`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`🧪`}),` Examples (`,k.length,`)`]}),(0,a.jsx)(`button`,{type:`button`,onClick:pe,className:`text-[9px] font-bold px-2 py-0.5 border border-ink-black bg-white hover:bg-slate-100 cursor-pointer shadow-[1px_1px_0px_#1E293B]`,children:`+ Add Example`})]}),k.map((e,t)=>(0,a.jsxs)(`div`,{className:`bg-white border border-ink-black p-2 space-y-1.5 rounded relative text-xs`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`span`,{className:`font-bold text-[10px] text-slate-500`,children:[`Example `,t+1,`:`]}),k.length>1&&(0,a.jsx)(`button`,{type:`button`,onClick:()=>me(t),className:`text-[10px] text-red-600 hover:text-red-800 font-bold cursor-pointer`,children:`✕`})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,a.jsx)(`input`,{type:`text`,value:e.input,onChange:e=>$(t,`input`,e.target.value),placeholder:`Input: nums = [2,7,11,15], target = 9`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] font-mono outline-none`}),(0,a.jsx)(`input`,{type:`text`,value:e.output,onChange:e=>$(t,`output`,e.target.value),placeholder:`Output: [0,1]`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] font-mono outline-none`})]}),(0,a.jsx)(`input`,{type:`text`,value:e.explanation||``,onChange:e=>$(t,`explanation`,e.target.value),placeholder:`Explanation (Optional): Because nums[0] + nums[1] == 9, we return [0, 1].`,className:`bg-slate-50 border border-slate-300 p-1 text-[11px] outline-none w-full`})]},t))]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Constraints (1 per line):`}),(0,a.jsx)(`textarea`,{value:j,onChange:e=>M(e.target.value),placeholder:`2 <= nums.length <= 10^4
5
+ -10^9 <= nums[i] <= 10^9
6
+ Only one valid answer exists.`,className:`bg-white border-2 border-ink-black p-2 text-xs font-mono outline-none focus:ring-1 focus:ring-primary-purple h-16 resize-y leading-snug`})]}),(0,a.jsxs)(`div`,{className:`border-2 border-ink-black bg-[#faf6eb] p-3 rounded space-y-3`,children:[(0,a.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b-2 border-ink-black pb-2`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`span`,{className:`text-xs`,children:`💡`}),(0,a.jsxs)(`label`,{className:`text-[11px] font-bold font-arcade uppercase tracking-wide`,children:[`Solutions & Methods (`,F.length,`)`]}),(0,a.jsx)(`span`,{className:`text-[9px] bg-slate-200 text-slate-700 font-mono px-1.5 py-0.5 rounded border border-slate-300`,children:`Active Recall: Shown on Solutions Tab`})]}),(0,a.jsxs)(`button`,{type:`button`,onClick:re,className:`px-2.5 py-1 text-[9px] font-bold font-arcade bg-[#ffe24c] hover:bg-yellow-300 border-2 border-ink-black shadow-[1px_1px_0px_#1E293B] cursor-pointer flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`+`}),` ADD METHOD`]})]}),(0,a.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:F.map((e,t)=>(0,a.jsxs)(`button`,{type:`button`,onClick:()=>R(t),className:`px-2.5 py-1 text-[10px] font-bold border-2 border-ink-black flex items-center gap-1.5 cursor-pointer rounded transition-colors ${L===t?`bg-primary-purple text-white shadow-[1px_1px_0px_#1E293B]`:`bg-white text-slate-700 hover:bg-slate-100`}`,children:[(0,a.jsx)(`span`,{children:e.name||`Method ${t+1}`}),e.is_optimal&&(0,a.jsx)(`span`,{className:`text-[8px] px-1 py-0.2 rounded font-mono uppercase font-black ${L===t?`bg-amber-400 text-ink-black`:`bg-amber-200 text-amber-900`}`,children:`★ Optimal`})]},e.id||t))}),(0,a.jsxs)(`div`,{className:`bg-white border-2 border-ink-black p-3 rounded space-y-2.5`,children:[(0,a.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-slate-200 pb-2`,children:[(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsxs)(`span`,{className:`text-xs font-bold text-slate-500`,children:[`Method #`,L+1,`:`]}),(0,a.jsx)(`input`,{type:`text`,value:z.name,onChange:e=>B({name:e.target.value}),placeholder:`e.g. Hash Map Lookup or Two Pointers`,className:`border border-ink-black px-2 py-0.5 text-xs font-bold bg-[#fffdf5] outline-none focus:ring-1 focus:ring-primary-purple w-56`})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,a.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] font-bold text-amber-800 cursor-pointer select-none`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:!!z.is_optimal,onChange:e=>B({is_optimal:e.target.checked}),className:`w-3.5 h-3.5 accent-amber-500 cursor-pointer`}),(0,a.jsx)(`span`,{children:`Mark as Optimal Solution`})]}),F.length>1&&(0,a.jsx)(`button`,{type:`button`,onClick:()=>ie(L),className:`text-[10px] font-bold text-red-600 hover:text-red-800 border border-red-300 hover:border-red-500 px-2 py-0.5 rounded cursor-pointer`,children:`Remove Method`})]})]}),(0,a.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-2`,children:[(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Pattern / Technique:`}),(0,a.jsx)(`input`,{type:`text`,list:`pattern-suggestions`,value:z.pattern||``,onChange:e=>B({pattern:e.target.value}),placeholder:`e.g. Arrays & Hashing`,className:`bg-[#fafafa] border border-ink-black p-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium`}),(0,a.jsx)(`datalist`,{id:`pattern-suggestions`,children:o.map(e=>(0,a.jsx)(`option`,{value:e},e))})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Method Time Complexity:`}),(0,a.jsx)(`input`,{type:`text`,value:z.time_complexity||``,onChange:e=>B({time_complexity:e.target.value}),placeholder:`e.g. O(N)`,className:`bg-[#fafafa] border border-ink-black p-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-semibold`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsx)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase`,children:`Method Space Complexity:`}),(0,a.jsx)(`input`,{type:`text`,value:z.space_complexity||``,onChange:e=>B({space_complexity:e.target.value}),placeholder:`e.g. O(1)`,className:`bg-[#fafafa] border border-ink-black p-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-semibold`})]})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`💡`}),` Intuition / Mental Model:`]}),(0,a.jsxs)(`button`,{type:`button`,onClick:ue,disabled:J,className:`text-[8px] font-arcade font-bold px-2 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer`,children:[(0,a.jsx)(`span`,{children:`✦`}),` `,J?`GENERATING...`:`AI INTUITION`]})]}),(0,a.jsx)(`textarea`,{value:z.explanation||``,onChange:e=>B({explanation:e.target.value}),placeholder:`Explain how this specific method works, key data structures, invariants, or edge cases...`,className:`bg-[#fafafa] border border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-20 resize-y leading-relaxed`})]}),(0,a.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,a.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,a.jsxs)(`label`,{className:`text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1`,children:[(0,a.jsx)(`span`,{children:`🐍`}),` Method Python Code:`]}),(0,a.jsxs)(`button`,{type:`button`,onClick:de,disabled:X||!z.code?.trim(),className:`text-[8px] font-arcade font-bold px-2 py-0.5 border border-ink-black bg-[#a7f3d0] hover:bg-emerald-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer text-emerald-950`,children:[(0,a.jsx)(`span`,{children:`✨`}),` `,X?`FORMATTING...`:`ADD EMOJI COMMENTS`]})]}),(0,a.jsx)(`textarea`,{value:z.code||``,onChange:e=>B({code:e.target.value}),placeholder:`def twoSum(nums: list[int], target: int) -> list[int]:
7
+ # 1. 🗺️ Initialize lookup map
8
+ seen = {}
9
+ ...
10
+ return []`,className:`bg-slate-900 text-[#4ADE80] font-mono p-2.5 border-2 border-ink-black rounded outline-none h-44 text-xs leading-relaxed resize-y w-full`})]})]})]})]}):(0,a.jsxs)(`div`,{className:`bg-white border-2 border-ink-black p-6 rounded shadow-sm font-sans space-y-4 text-slate-800`,children:[(0,a.jsx)(`div`,{className:`border-b pb-2`,children:(0,a.jsx)(`span`,{className:`text-[10px] font-mono uppercase bg-purple-100 text-purple-800 px-2 py-0.5 rounded font-bold`,children:`Google Doc Preview (Exact formatting preview)`})}),(0,a.jsxs)(`h1`,{className:`text-xl font-bold text-slate-900`,children:[_?`${_}. `:``,h||`Problem Title`]}),(0,a.jsx)(`div`,{children:(0,a.jsx)(`span`,{className:`text-xs font-bold px-2.5 py-0.5 rounded ${x===`Easy`?`bg-emerald-100 text-[#137c36]`:x===`Medium`?`bg-amber-100 text-[#c06100]`:`bg-rose-100 text-[#c5221f]`}`,children:x})}),D&&(0,a.jsx)(`div`,{className:`text-xs text-slate-700 leading-relaxed whitespace-pre-wrap`,children:D}),k.some(e=>e.input.trim()||e.output.trim())&&(0,a.jsx)(`div`,{className:`space-y-3 pt-2`,children:k.map((e,t)=>(0,a.jsxs)(`div`,{className:`text-xs space-y-1`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-slate-800`,children:[`Example `,t+1,`:`]}),e.input&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Input: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.input})]}),e.output&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Output: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.output})]}),e.explanation&&(0,a.jsxs)(`div`,{children:[(0,a.jsx)(`span`,{className:`text-slate-600`,children:`Explanation: `}),(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.explanation})]})]},t))}),j&&(0,a.jsxs)(`div`,{className:`space-y-1.5 pt-2`,children:[(0,a.jsx)(`div`,{className:`font-bold text-xs text-slate-800`,children:`Constraints:`}),(0,a.jsx)(`ul`,{className:`list-disc pl-5 text-xs space-y-1`,children:j.split(`
11
+ `).filter(Boolean).map((e,t)=>(0,a.jsx)(`li`,{children:(0,a.jsx)(`span`,{className:`bg-[#d9d9d9] font-mono px-1.5 py-0.5 rounded text-[11px]`,children:e.replace(/^[•\-*]\s*/,``)})},t))})]}),(0,a.jsxs)(`div`,{className:`p-2.5 bg-slate-50 border border-slate-200 rounded space-y-1 text-xs`,children:[(0,a.jsx)(`div`,{className:`font-bold text-slate-700`,children:`Target Optimal Complexities (Active Recall Shielded on Review):`}),(0,a.jsxs)(`div`,{className:`flex gap-4 font-mono text-slate-900`,children:[(0,a.jsxs)(`span`,{children:[`Time: `,C]}),(0,a.jsxs)(`span`,{children:[`Space: `,T]})]})]}),(0,a.jsxs)(`div`,{className:`pt-3 space-y-4`,children:[(0,a.jsxs)(`div`,{className:`font-bold text-sm text-slate-900 border-b pb-1`,children:[`Solutions & Methods (`,F.length,`)`]}),F.map((e,t)=>(0,a.jsxs)(`div`,{className:`border border-slate-300 p-3 rounded space-y-2 bg-[#fdfdfd]`,children:[(0,a.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,a.jsx)(`span`,{className:`font-bold text-xs text-slate-900`,children:e.name||`Method ${t+1}`}),(0,a.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[e.is_optimal&&(0,a.jsx)(`span`,{className:`text-[9px] bg-amber-100 text-amber-800 font-bold px-1.5 py-0.5 rounded border border-amber-300`,children:`★ Optimal`}),(0,a.jsx)(`span`,{className:`text-[9px] bg-purple-100 text-primary-purple font-bold px-1.5 py-0.5 rounded border border-purple-200`,children:e.pattern||`Standard`})]})]}),(0,a.jsxs)(`div`,{className:`flex gap-4 text-xs font-mono text-slate-600`,children:[(0,a.jsxs)(`span`,{children:[`T: `,e.time_complexity||`O(?)`]}),(0,a.jsxs)(`span`,{children:[`S: `,e.space_complexity||`O(?)`]})]}),e.explanation&&(0,a.jsx)(`div`,{className:`text-xs text-slate-700 leading-relaxed whitespace-pre-wrap bg-slate-50 p-2 rounded`,children:e.explanation}),e.code&&(0,a.jsx)(`div`,{className:`bg-[#f8fafc] border border-slate-200 p-2.5 rounded font-mono text-[11px] leading-relaxed text-slate-900 overflow-x-auto whitespace-pre`,children:e.code})]},e.id||t))]})]})}),(0,a.jsxs)(`div`,{className:`p-3 bg-[#f0e6c8] border-t-2 border-ink-black flex flex-wrap items-center justify-between gap-2 shrink-0`,children:[l?(0,a.jsxs)(`div`,{className:`text-[11px] text-slate-600 font-mono flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-primary-purple inline-block`}),`Editing #`,r?.problem_number??`—`,` `,r?.name]}):(0,a.jsxs)(`label`,{className:`flex items-center gap-2 text-xs font-bold text-slate-700 cursor-pointer select-none`,children:[(0,a.jsx)(`input`,{type:`checkbox`,checked:V,onChange:e=>ae(e.target.checked),className:`w-4 h-4 accent-primary-purple cursor-pointer`}),(0,a.jsx)(`span`,{children:`Format & Sync to Google Doc`})]}),(0,a.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,a.jsx)(`button`,{type:`button`,onClick:e,className:`px-3 py-1.5 bg-white hover:bg-slate-50 border-2 border-ink-black text-xs font-bold cursor-pointer`,children:`CANCEL`}),(0,a.jsxs)(`button`,{type:`submit`,disabled:K,className:`px-4 py-1.5 bg-primary-purple hover:bg-purple-600 text-white font-arcade text-[10px] font-bold border-2 border-ink-black shadow-[2px_2px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer flex items-center gap-1.5`,children:[(0,a.jsx)(`span`,{children:l?`✏️`:`💾`}),` `,K?l?`UPDATING...`:`SAVING...`:l?`UPDATE PROBLEM`:`SAVE SOLUTION`]})]})]})]})}export{c as default};
algospaced-ui/dist/assets/GitHubSyncWindow-Ca288SgB.js ADDED
@@ -0,0 +1 @@
 
 
1
+ import{a as e,c as t,t as n}from"./jsx-runtime-j9uSgrFF.js";import{t as r}from"./circle-alert-BL6bvZTM.js";import{t as i}from"./external-link-BGZfX5Bi.js";import{a,c as o,d as s,f as c,i as l,l as u,n as d,o as f,r as p,s as m,t as h,u as g}from"./githubSyncService-CsqBgIfT.js";import{F as _,G as v,T as y,U as b,z as x}from"./index-V2pPJO9M.js";var S=v(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),C=v(`git-branch`,[[`path`,{d:`M15 6a9 9 0 0 0-9 9V3`,key:`1cii5b`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}]]),w=v(`git-commit-horizontal`,[[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`line`,{x1:`3`,x2:`9`,y1:`12`,y2:`12`,key:`1dyftd`}],[`line`,{x1:`15`,x2:`21`,y1:`12`,y2:`12`,key:`oup4p8`}]]),T=v(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),E=t(e(),1),D=n(),O=({onClose:e,currentProblem:t})=>{let[n,v]=(0,E.useState)(()=>p()),[O,k]=(0,E.useState)(()=>l()),[A,j]=(0,E.useState)(``),[M,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(!1),[I,L]=(0,E.useState)(!1),[R,z]=(0,E.useState)(!1),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(!1),[K,q]=(0,E.useState)(null),J=!!(n.token&&(n.username||O?.login));(0,E.useEffect)(()=>{n.token&&!O&&u(n.token).then(e=>{e.valid&&e.user&&(k(e.user),m({username:e.user.login},e.user))})},[n.token,O]);let Y=async()=>{L(!0),q(null);try{let{token:e,user:t}=await d();k(t);let n=p();v(n);try{await a(e,n.repoName,n.isPrivate)}catch{}q({type:`success`,text:`Connected successfully to GitHub as @${t.login}!`,linkUrl:t.html_url})}catch(e){q({type:`error`,text:e.message||`GitHub OAuth authorization failed.`})}finally{L(!1)}},X=async()=>{let e=A.trim();if(!e){q({type:`error`,text:`Please enter a valid GitHub token.`});return}z(!0),q(null);try{let t=await u(e);if(t.valid&&t.user){k(t.user),m({token:e,username:t.user.login},t.user),v(p());try{await a(e,n.repoName,n.isPrivate)}catch{}j(``),N(!1),q({type:`success`,text:`Verified and connected as @${t.user.login}!`,linkUrl:t.user.html_url})}else q({type:`error`,text:t.error||`Token verification failed. Please check permissions.`})}catch(e){q({type:`error`,text:e.message||`Failed to connect with token.`})}finally{z(!1)}},Z=async()=>{if(n.token){V(!0),q(null);try{let e=await a(n.token,n.repoName,n.isPrivate);m({repoName:n.repoName}),q({type:`success`,text:e.created?`Created new repository ${e.full_name} on GitHub!`:`Connected to existing repository ${e.full_name}!`,linkUrl:e.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to initialize repository.`})}finally{V(!1)}}},Q=async()=>{if(n.token&&n.repoName){U(!0),q(null);try{let e=await o(n.token,n.repoName,n.branch);q({type:`success`,text:e.message||`Synced ${e.synced_count} solutions to ${n.repoName}!`,linkUrl:e.repo_url})}catch(e){q({type:`error`,text:e.message||`Batch sync failed.`})}finally{U(!1)}}},$=async()=>{if(!t||!n.token)return;let e=t.code||t.reference_code;if(!e||!e.trim()){q({type:`error`,text:`Current problem has no code to push. Write or save code first!`});return}G(!0),q(null);try{let r={token:n.token,repo:n.repoName,branch:n.branch,problem_number:t.problem_number,problem_name:t.name||`Algorithm Problem`,difficulty:t.difficulty||`Medium`,pattern:t.pattern||`Algorithms`,optimal_time:t.optimal_time||`O(N)`,optimal_space:t.optimal_space||`O(1)`,description:t.description||``,code:e},i=await f(r);q({type:`success`,text:`Committed ${t.name} to GitHub!`,linkUrl:i.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to push current solution.`})}finally{G(!1)}},ee=e=>{m({autoCommit:e}),v(t=>({...t,autoCommit:e})),q({type:`info`,text:e?`Auto-commit ENABLED: Solutions will sync automatically on submission.`:`Auto-commit DISABLED: You can still push manually any time.`})};return(0,D.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-4 sm:p-6 flex flex-col justify-between select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-b-[3px] border-ink-black pb-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(`div`,{className:`w-9 h-9 bg-ink-black rounded border-2 border-ink-black flex items-center justify-center text-white shadow-[2px_2px_0px_0px_rgba(0,0,0,0.15)]`,children:(0,D.jsx)(`svg`,{className:`w-5 h-5 fill-white`,viewBox:`0 0 19 19`,children:(0,D.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{className:`font-headline-md font-bold text-sm uppercase m-0 flex items-center gap-2`,children:`GitHub Solutions Station`}),(0,D.jsx)(`p`,{className:`text-[11px] text-trash-gray font-semibold m-0`,children:`Sync algorithm solutions & auto-commit to your personal portfolio repository`})]})]}),(0,D.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,D.jsx)(`span`,{className:`px-2.5 py-1 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black ${J?`bg-emerald-300 text-emerald-950`:`bg-amber-200 text-amber-950`}`,children:J?`CONNECTED`:`DISCONNECTED`})})]}),J?(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[O?.avatar_url?(0,D.jsx)(`img`,{src:O.avatar_url,alt:O.login,className:`w-10 h-10 rounded-full border-2 border-ink-black shadow-[1px_1px_0px_0px_#1E293B]`}):(0,D.jsx)(`div`,{className:`w-10 h-10 bg-slate-200 rounded-full border-2 border-ink-black flex items-center justify-center font-bold`,children:`GH`}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`font-bold text-xs text-ink-black`,children:O?.name||O?.login||n.username}),(0,D.jsxs)(`span`,{className:`text-[10px] text-trash-gray font-mono`,children:[`(@`,O?.login||n.username,`)`]})]}),(0,D.jsxs)(`div`,{className:`text-[11px] text-slate-600 font-medium flex items-center gap-1 mt-0.5`,children:[(0,D.jsx)(g,{className:`w-3.5 h-3.5 text-blue-600 shrink-0`}),(0,D.jsxs)(`span`,{className:`font-semibold text-ink-black`,children:[n.username||O?.login,`/`,n.repoName]}),(0,D.jsxs)(`span`,{className:`text-slate-400`,children:[`(`,n.branch,`)`]})]})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(`a`,{href:`https://github.com/${n.username||O?.login}/${n.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-3 py-1.5 bg-slate-50 hover:bg-slate-100 border-2 border-ink-black text-xs font-bold text-ink-black flex items-center gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none no-underline cursor-pointer`,children:[(0,D.jsx)(i,{className:`w-3.5 h-3.5`}),(0,D.jsx)(`span`,{children:`View Repo`})]}),(0,D.jsxs)(`button`,{onClick:()=>{window.confirm(`Disconnect your GitHub account from AlgoSpaced?`)&&(h(),v(p()),k(null),q({type:`info`,text:`Disconnected from GitHub.`}))},className:`px-3 py-1.5 bg-white hover:bg-rose-50 border-2 border-rose-300 text-rose-700 text-xs font-bold flex items-center gap-1 cursor-pointer transition-all`,title:`Disconnect GitHub`,children:[(0,D.jsx)(T,{className:`w-3 h-3`}),(0,D.jsx)(`span`,{children:`Disconnect`})]})]})]}),(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-b pb-2 border-slate-200`,children:[(0,D.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,D.jsx)(C,{className:`w-3.5 h-3.5 text-ink-black`}),`Target Repository & Branch`]}),(0,D.jsxs)(`button`,{onClick:Z,disabled:B,className:`px-2.5 py-1 bg-yellow-100 hover:bg-yellow-200 border border-ink-black text-[10px] font-bold text-ink-black flex items-center gap-1 cursor-pointer disabled:opacity-50 shadow-[1px_1px_0px_0px_#1E293B]`,children:[B?(0,D.jsx)(_,{className:`w-3 h-3 animate-spin`}):(0,D.jsx)(b,{className:`w-3 h-3 text-emerald-700`}),(0,D.jsx)(`span`,{children:`Verify / Init Repo`})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Repository Name`}),(0,D.jsx)(`input`,{type:`text`,value:n.repoName,onChange:e=>{let t=e.target.value;v(e=>({...e,repoName:t})),m({repoName:t})},placeholder:`algospaced-solutions`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Branch Name`}),(0,D.jsx)(`input`,{type:`text`,value:n.branch,onChange:e=>{let t=e.target.value;v(e=>({...e,branch:t})),m({branch:t})},placeholder:`main`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]})]}),(0,D.jsxs)(`div`,{className:`pt-2 border-t border-slate-100 flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,D.jsx)(y,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,D.jsx)(`span`,{className:`text-[10px] text-trash-gray font-medium`,children:`Automatically push code to your repo when grading a review card or saving a solution.`})]})]}),(0,D.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer select-none`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:n.autoCommit,onChange:e=>ee(e.target.checked),className:`sr-only peer`}),(0,D.jsx)(`div`,{className:`w-9 h-5 bg-slate-300 peer-focus:outline-none border-2 border-ink-black rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-2 after:border-ink-black after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-emerald-500`})]})]})]}),(0,D.jsxs)(`div`,{className:`bg-[#fffdf0] border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,D.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,D.jsx)(S,{className:`w-3.5 h-3.5 text-ink-black`}),`Manual Push & Sync Operations`]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,D.jsxs)(`button`,{onClick:$,disabled:W||!t,className:`p-3 bg-white hover:bg-emerald-50 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,D.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[W?(0,D.jsx)(_,{className:`w-3.5 h-3.5 animate-spin text-emerald-600`}):(0,D.jsx)(w,{className:`w-3.5 h-3.5 text-emerald-600`}),`Push Active Problem`]}),t?.problem_number&&(0,D.jsxs)(`span`,{className:`text-[9px] font-mono px-1.5 py-0.5 bg-emerald-100 text-emerald-800 rounded font-bold`,children:[`#`,t.problem_number]})]}),(0,D.jsx)(`span`,{className:`text-[10px] text-slate-500 line-clamp-1`,children:t?.name||`No active problem open in review`})]}),(0,D.jsxs)(`button`,{onClick:Q,disabled:H,className:`p-3 bg-[#ffe24c] hover:bg-yellow-300 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,D.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[H?(0,D.jsx)(_,{className:`w-3.5 h-3.5 animate-spin text-ink-black`}):(0,D.jsx)(g,{className:`w-3.5 h-3.5 text-ink-black`}),`Sync Entire Library`]}),(0,D.jsx)(`span`,{className:`text-[8px] font-arcade uppercase font-bold bg-white px-1.5 py-0.5 border border-ink-black`,children:`BATCH`})]}),(0,D.jsx)(`span`,{className:`text-[10px] text-slate-700`,children:`Push all solved problems + generate root README index`})]})]})]})]}):(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-5 sm:p-6 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] text-center space-y-4`,children:[(0,D.jsxs)(`div`,{className:`max-w-md mx-auto space-y-2`,children:[(0,D.jsx)(`h4`,{className:`font-headline-md font-bold text-sm uppercase text-ink-black m-0`,children:`Connect Your GitHub Account`}),(0,D.jsx)(`p`,{className:`text-xs text-trash-gray font-medium leading-relaxed m-0`,children:`Sync all your DSA solutions directly to your GitHub repository. Commit automatically on review completion or push anytime with 1-click.`})]}),(0,D.jsxs)(`div`,{className:`pt-2 flex flex-col items-center`,children:[(0,D.jsx)(`button`,{onClick:Y,disabled:I,className:`w-full sm:w-auto px-6 py-3 bg-[#24292e] hover:bg-black text-white font-bold text-xs uppercase font-headline-md border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center gap-2.5 transition-all cursor-pointer disabled:opacity-50`,children:I?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(_,{className:`w-4 h-4 animate-spin text-yellow-300`}),(0,D.jsx)(`span`,{children:`AUTHORIZING WITH GITHUB...`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`svg`,{className:`w-4 h-4 fill-white`,viewBox:`0 0 19 19`,children:(0,D.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})}),(0,D.jsx)(`span`,{children:`CONNECT WITH GITHUB (1-CLICK)`})]})}),(0,D.jsxs)(`span`,{className:`text-[10px] text-trash-gray mt-2`,children:[`Direct 1-click OAuth (works for guest and signed-in users). Requests `,(0,D.jsx)(`code`,{children:`repo`}),` access.`]})]})]}),(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)]`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>N(!M),className:`w-full flex items-center justify-between text-left text-xs font-bold text-ink-black font-headline-md uppercase cursor-pointer bg-transparent border-0 p-0`,children:[(0,D.jsx)(`span`,{children:`Or connect via Personal Access Token (PAT)`}),(0,D.jsx)(`span`,{className:`text-slate-500`,children:M?`▲ Hide`:`▼ Show`})]}),M&&(0,D.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-slate-200 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,D.jsx)(`span`,{className:`font-semibold text-slate-700`,children:`Personal Access Token:`}),(0,D.jsxs)(`a`,{href:`https://github.com/settings/tokens/new?scopes=repo&description=AlgoSpaced%20Solutions%20Sync`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 hover:text-blue-800 font-bold flex items-center gap-1 no-underline text-[10px]`,children:[(0,D.jsx)(`span`,{children:`Generate token with repo scope`}),(0,D.jsx)(i,{className:`w-3 h-3`})]})]}),(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsx)(`input`,{type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),placeholder:`ghp_... or github_pat_...`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-2 pl-3 pr-9 text-xs font-mono focus:outline-none focus:bg-white`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-ink-black cursor-pointer bg-transparent border-0 p-1`,children:P?(0,D.jsx)(c,{className:`w-3.5 h-3.5`}):(0,D.jsx)(s,{className:`w-3.5 h-3.5`})})]}),(0,D.jsx)(`button`,{onClick:X,disabled:R||!A.trim(),className:`px-4 py-2 bg-[#ffe24c] hover:bg-yellow-300 text-ink-black font-bold text-xs uppercase border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer disabled:opacity-50 flex items-center gap-1.5`,children:R?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(_,{className:`w-3.5 h-3.5 animate-spin`}),(0,D.jsx)(`span`,{children:`VERIFYING TOKEN...`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(b,{className:`w-3.5 h-3.5`}),(0,D.jsx)(`span`,{children:`SAVE & CONNECT TOKEN`})]})})]})]})]}),K&&(0,D.jsxs)(`div`,{className:`p-3 border-[2px] border-ink-black text-xs font-semibold rounded flex items-center justify-between gap-2 ${K.type===`success`?`bg-emerald-100 text-emerald-900 border-emerald-600`:K.type===`error`?`bg-rose-100 text-rose-900 border-rose-600`:`bg-sky-100 text-sky-900 border-sky-600`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[K.type===`success`?(0,D.jsx)(x,{className:`w-4 h-4 shrink-0`}):(0,D.jsx)(r,{className:`w-4 h-4 shrink-0`}),(0,D.jsx)(`span`,{children:K.text})]}),K.linkUrl&&(0,D.jsxs)(`a`,{href:K.linkUrl,target:`_blank`,rel:`noopener noreferrer`,className:`px-2 py-0.5 bg-white border border-ink-black text-[10px] font-bold text-ink-black hover:bg-slate-50 no-underline shrink-0 flex items-center gap-1`,children:[(0,D.jsx)(`span`,{children:`Open`}),(0,D.jsx)(i,{className:`w-3 h-3`})]})]})]}),(0,D.jsx)(`div`,{className:`pt-4 border-t border-slate-300 flex justify-end`,children:(0,D.jsx)(`button`,{onClick:e,className:`px-4 py-2 bg-white hover:bg-slate-100 border-[2px] border-ink-black text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer uppercase`,children:`CLOSE`})})]})};export{O as GitHubSyncWindow,O as default};
algospaced-ui/dist/assets/GitHubSyncWindow-DGw-FVNu.js DELETED
@@ -1 +0,0 @@
1
- import{a as e,c as t,t as n}from"./jsx-runtime-j9uSgrFF.js";import{n as r,r as i,t as a}from"./eye-DeJ_5v51.js";import{t as o}from"./external-link-yb1gedrc.js";import{a as s,c,i as l,l as u,n as d,o as f,r as p,s as m,t as h,u as g}from"./githubSyncService--4Z5jmjP.js";import{C as _,L as v,N as y,U as b,V as x}from"./index-g5jVBiGr.js";var S=b(`cloud-upload`,[[`path`,{d:`M12 13v8`,key:`1l5pq0`}],[`path`,{d:`M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242`,key:`1pljnt`}],[`path`,{d:`m8 17 4-4 4 4`,key:`1quai1`}]]),C=b(`git-branch`,[[`path`,{d:`M15 6a9 9 0 0 0-9 9V3`,key:`1cii5b`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}]]),w=b(`git-commit-horizontal`,[[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}],[`line`,{x1:`3`,x2:`9`,y1:`12`,y2:`12`,key:`1dyftd`}],[`line`,{x1:`15`,x2:`21`,y1:`12`,y2:`12`,key:`oup4p8`}]]),T=b(`log-out`,[[`path`,{d:`m16 17 5-5-5-5`,key:`1bji2h`}],[`path`,{d:`M21 12H9`,key:`dn1m92`}],[`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`,key:`1uf3rs`}]]),E=t(e(),1),D=n(),O=({onClose:e,currentProblem:t})=>{let[n,b]=(0,E.useState)(()=>p()),[O,k]=(0,E.useState)(()=>l()),[A,j]=(0,E.useState)(``),[M,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(!1),[I,L]=(0,E.useState)(!1),[R,z]=(0,E.useState)(!1),[B,V]=(0,E.useState)(!1),[H,U]=(0,E.useState)(!1),[W,G]=(0,E.useState)(!1),[K,q]=(0,E.useState)(null),J=!!(n.token&&(n.username||O?.login));(0,E.useEffect)(()=>{n.token&&!O&&u(n.token).then(e=>{e.valid&&e.user&&(k(e.user),m({username:e.user.login},e.user))})},[n.token,O]);let Y=async()=>{L(!0),q(null);try{let{token:e,user:t}=await d();k(t);let n=p();b(n);try{await s(e,n.repoName,n.isPrivate)}catch{}q({type:`success`,text:`Connected successfully to GitHub as @${t.login}!`,linkUrl:t.html_url})}catch(e){q({type:`error`,text:e.message||`GitHub OAuth authorization failed.`})}finally{L(!1)}},X=async()=>{let e=A.trim();if(!e){q({type:`error`,text:`Please enter a valid GitHub token.`});return}z(!0),q(null);try{let t=await u(e);if(t.valid&&t.user){k(t.user),m({token:e,username:t.user.login},t.user),b(p());try{await s(e,n.repoName,n.isPrivate)}catch{}j(``),N(!1),q({type:`success`,text:`Verified and connected as @${t.user.login}!`,linkUrl:t.user.html_url})}else q({type:`error`,text:t.error||`Token verification failed. Please check permissions.`})}catch(e){q({type:`error`,text:e.message||`Failed to connect with token.`})}finally{z(!1)}},Z=async()=>{if(n.token){V(!0),q(null);try{let e=await s(n.token,n.repoName,n.isPrivate);m({repoName:n.repoName}),q({type:`success`,text:e.created?`Created new repository ${e.full_name} on GitHub!`:`Connected to existing repository ${e.full_name}!`,linkUrl:e.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to initialize repository.`})}finally{V(!1)}}},Q=async()=>{if(n.token&&n.repoName){U(!0),q(null);try{let e=await c(n.token,n.repoName,n.branch);q({type:`success`,text:e.message||`Synced ${e.synced_count} solutions to ${n.repoName}!`,linkUrl:e.repo_url})}catch(e){q({type:`error`,text:e.message||`Batch sync failed.`})}finally{U(!1)}}},$=async()=>{if(!t||!n.token)return;let e=t.code||t.reference_code;if(!e||!e.trim()){q({type:`error`,text:`Current problem has no code to push. Write or save code first!`});return}G(!0),q(null);try{let r={token:n.token,repo:n.repoName,branch:n.branch,problem_number:t.problem_number,problem_name:t.name||`Algorithm Problem`,difficulty:t.difficulty||`Medium`,pattern:t.pattern||`Algorithms`,optimal_time:t.optimal_time||`O(N)`,optimal_space:t.optimal_space||`O(1)`,description:t.description||``,code:e},i=await f(r);q({type:`success`,text:`Committed ${t.name} to GitHub!`,linkUrl:i.html_url})}catch(e){q({type:`error`,text:e.message||`Failed to push current solution.`})}finally{G(!1)}},ee=e=>{m({autoCommit:e}),b(t=>({...t,autoCommit:e})),q({type:`info`,text:e?`Auto-commit ENABLED: Solutions will sync automatically on submission.`:`Auto-commit DISABLED: You can still push manually any time.`})};return(0,D.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-4 sm:p-6 flex flex-col justify-between select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-b-[3px] border-ink-black pb-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(`div`,{className:`w-9 h-9 bg-ink-black rounded border-2 border-ink-black flex items-center justify-center text-white shadow-[2px_2px_0px_0px_rgba(0,0,0,0.15)]`,children:(0,D.jsx)(`svg`,{className:`w-5 h-5 fill-white`,viewBox:`0 0 19 19`,children:(0,D.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{className:`font-headline-md font-bold text-sm uppercase m-0 flex items-center gap-2`,children:`GitHub Solutions Station`}),(0,D.jsx)(`p`,{className:`text-[11px] text-trash-gray font-semibold m-0`,children:`Sync algorithm solutions & auto-commit to your personal portfolio repository`})]})]}),(0,D.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,D.jsx)(`span`,{className:`px-2.5 py-1 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black ${J?`bg-emerald-300 text-emerald-950`:`bg-amber-200 text-amber-950`}`,children:J?`CONNECTED`:`DISCONNECTED`})})]}),J?(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[O?.avatar_url?(0,D.jsx)(`img`,{src:O.avatar_url,alt:O.login,className:`w-10 h-10 rounded-full border-2 border-ink-black shadow-[1px_1px_0px_0px_#1E293B]`}):(0,D.jsx)(`div`,{className:`w-10 h-10 bg-slate-200 rounded-full border-2 border-ink-black flex items-center justify-center font-bold`,children:`GH`}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`font-bold text-xs text-ink-black`,children:O?.name||O?.login||n.username}),(0,D.jsxs)(`span`,{className:`text-[10px] text-trash-gray font-mono`,children:[`(@`,O?.login||n.username,`)`]})]}),(0,D.jsxs)(`div`,{className:`text-[11px] text-slate-600 font-medium flex items-center gap-1 mt-0.5`,children:[(0,D.jsx)(g,{className:`w-3.5 h-3.5 text-blue-600 shrink-0`}),(0,D.jsxs)(`span`,{className:`font-semibold text-ink-black`,children:[n.username||O?.login,`/`,n.repoName]}),(0,D.jsxs)(`span`,{className:`text-slate-400`,children:[`(`,n.branch,`)`]})]})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsxs)(`a`,{href:`https://github.com/${n.username||O?.login}/${n.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-3 py-1.5 bg-slate-50 hover:bg-slate-100 border-2 border-ink-black text-xs font-bold text-ink-black flex items-center gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none no-underline cursor-pointer`,children:[(0,D.jsx)(o,{className:`w-3.5 h-3.5`}),(0,D.jsx)(`span`,{children:`View Repo`})]}),(0,D.jsxs)(`button`,{onClick:()=>{window.confirm(`Disconnect your GitHub account from AlgoSpaced?`)&&(h(),b(p()),k(null),q({type:`info`,text:`Disconnected from GitHub.`}))},className:`px-3 py-1.5 bg-white hover:bg-rose-50 border-2 border-rose-300 text-rose-700 text-xs font-bold flex items-center gap-1 cursor-pointer transition-all`,title:`Disconnect GitHub`,children:[(0,D.jsx)(T,{className:`w-3 h-3`}),(0,D.jsx)(`span`,{children:`Disconnect`})]})]})]}),(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between border-b pb-2 border-slate-200`,children:[(0,D.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,D.jsx)(C,{className:`w-3.5 h-3.5 text-ink-black`}),`Target Repository & Branch`]}),(0,D.jsxs)(`button`,{onClick:Z,disabled:B,className:`px-2.5 py-1 bg-yellow-100 hover:bg-yellow-200 border border-ink-black text-[10px] font-bold text-ink-black flex items-center gap-1 cursor-pointer disabled:opacity-50 shadow-[1px_1px_0px_0px_#1E293B]`,children:[B?(0,D.jsx)(y,{className:`w-3 h-3 animate-spin`}):(0,D.jsx)(x,{className:`w-3 h-3 text-emerald-700`}),(0,D.jsx)(`span`,{children:`Verify / Init Repo`})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Repository Name`}),(0,D.jsx)(`input`,{type:`text`,value:n.repoName,onChange:e=>{let t=e.target.value;b(e=>({...e,repoName:t})),m({repoName:t})},placeholder:`algospaced-solutions`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block text-[10px] font-bold text-trash-gray uppercase mb-1`,children:`Branch Name`}),(0,D.jsx)(`input`,{type:`text`,value:n.branch,onChange:e=>{let t=e.target.value;b(e=>({...e,branch:t})),m({branch:t})},placeholder:`main`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-1.5 px-2.5 text-xs font-mono font-medium focus:outline-none focus:bg-white`})]})]}),(0,D.jsxs)(`div`,{className:`pt-2 border-t border-slate-100 flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,D.jsx)(_,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,D.jsx)(`span`,{className:`text-[10px] text-trash-gray font-medium`,children:`Automatically push code to your repo when grading a review card or saving a solution.`})]})]}),(0,D.jsxs)(`label`,{className:`relative inline-flex items-center cursor-pointer select-none`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:n.autoCommit,onChange:e=>ee(e.target.checked),className:`sr-only peer`}),(0,D.jsx)(`div`,{className:`w-9 h-5 bg-slate-300 peer-focus:outline-none border-2 border-ink-black rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-2 after:border-ink-black after:rounded-full after:h-4 after:w-4 after:transition-all peer-checked:bg-emerald-500`})]})]})]}),(0,D.jsxs)(`div`,{className:`bg-[#fffdf0] border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] space-y-3`,children:[(0,D.jsxs)(`span`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black flex items-center gap-1.5`,children:[(0,D.jsx)(S,{className:`w-3.5 h-3.5 text-ink-black`}),`Manual Push & Sync Operations`]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,D.jsxs)(`button`,{onClick:$,disabled:W||!t,className:`p-3 bg-white hover:bg-emerald-50 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,D.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[W?(0,D.jsx)(y,{className:`w-3.5 h-3.5 animate-spin text-emerald-600`}):(0,D.jsx)(w,{className:`w-3.5 h-3.5 text-emerald-600`}),`Push Active Problem`]}),t?.problem_number&&(0,D.jsxs)(`span`,{className:`text-[9px] font-mono px-1.5 py-0.5 bg-emerald-100 text-emerald-800 rounded font-bold`,children:[`#`,t.problem_number]})]}),(0,D.jsx)(`span`,{className:`text-[10px] text-slate-500 line-clamp-1`,children:t?.name||`No active problem open in review`})]}),(0,D.jsxs)(`button`,{onClick:Q,disabled:H,className:`p-3 bg-[#ffe24c] hover:bg-yellow-300 border-2 border-ink-black text-left flex flex-col justify-between gap-1 shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer transition-all disabled:opacity-50`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,D.jsxs)(`span`,{className:`font-bold text-xs text-ink-black font-headline-md flex items-center gap-1.5`,children:[H?(0,D.jsx)(y,{className:`w-3.5 h-3.5 animate-spin text-ink-black`}):(0,D.jsx)(g,{className:`w-3.5 h-3.5 text-ink-black`}),`Sync Entire Library`]}),(0,D.jsx)(`span`,{className:`text-[8px] font-arcade uppercase font-bold bg-white px-1.5 py-0.5 border border-ink-black`,children:`BATCH`})]}),(0,D.jsx)(`span`,{className:`text-[10px] text-slate-700`,children:`Push all solved problems + generate root README index`})]})]})]})]}):(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-5 sm:p-6 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] text-center space-y-4`,children:[(0,D.jsxs)(`div`,{className:`max-w-md mx-auto space-y-2`,children:[(0,D.jsx)(`h4`,{className:`font-headline-md font-bold text-sm uppercase text-ink-black m-0`,children:`Connect Your GitHub Account`}),(0,D.jsx)(`p`,{className:`text-xs text-trash-gray font-medium leading-relaxed m-0`,children:`Sync all your DSA solutions directly to your GitHub repository. Commit automatically on review completion or push anytime with 1-click.`})]}),(0,D.jsxs)(`div`,{className:`pt-2 flex flex-col items-center`,children:[(0,D.jsx)(`button`,{onClick:Y,disabled:I,className:`w-full sm:w-auto px-6 py-3 bg-[#24292e] hover:bg-black text-white font-bold text-xs uppercase font-headline-md border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none flex items-center justify-center gap-2.5 transition-all cursor-pointer disabled:opacity-50`,children:I?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(y,{className:`w-4 h-4 animate-spin text-yellow-300`}),(0,D.jsx)(`span`,{children:`AUTHORIZING WITH GITHUB...`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`svg`,{className:`w-4 h-4 fill-white`,viewBox:`0 0 19 19`,children:(0,D.jsx)(`path`,{fillRule:`evenodd`,d:`M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844`,clipRule:`evenodd`})}),(0,D.jsx)(`span`,{children:`CONNECT WITH GITHUB (1-CLICK)`})]})}),(0,D.jsxs)(`span`,{className:`text-[10px] text-trash-gray mt-2`,children:[`Direct 1-click OAuth (works for guest and signed-in users). Requests `,(0,D.jsx)(`code`,{children:`repo`}),` access.`]})]})]}),(0,D.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)]`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>N(!M),className:`w-full flex items-center justify-between text-left text-xs font-bold text-ink-black font-headline-md uppercase cursor-pointer bg-transparent border-0 p-0`,children:[(0,D.jsx)(`span`,{children:`Or connect via Personal Access Token (PAT)`}),(0,D.jsx)(`span`,{className:`text-slate-500`,children:M?`▲ Hide`:`▼ Show`})]}),M&&(0,D.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-slate-200 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-[11px]`,children:[(0,D.jsx)(`span`,{className:`font-semibold text-slate-700`,children:`Personal Access Token:`}),(0,D.jsxs)(`a`,{href:`https://github.com/settings/tokens/new?scopes=repo&description=AlgoSpaced%20Solutions%20Sync`,target:`_blank`,rel:`noopener noreferrer`,className:`text-blue-600 hover:text-blue-800 font-bold flex items-center gap-1 no-underline text-[10px]`,children:[(0,D.jsx)(`span`,{children:`Generate token with repo scope`}),(0,D.jsx)(o,{className:`w-3 h-3`})]})]}),(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsx)(`input`,{type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),placeholder:`ghp_... or github_pat_...`,className:`w-full bg-slate-50 border-2 border-ink-black rounded py-2 pl-3 pr-9 text-xs font-mono focus:outline-none focus:bg-white`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-ink-black cursor-pointer bg-transparent border-0 p-1`,children:P?(0,D.jsx)(r,{className:`w-3.5 h-3.5`}):(0,D.jsx)(a,{className:`w-3.5 h-3.5`})})]}),(0,D.jsx)(`button`,{onClick:X,disabled:R||!A.trim(),className:`px-4 py-2 bg-[#ffe24c] hover:bg-yellow-300 text-ink-black font-bold text-xs uppercase border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer disabled:opacity-50 flex items-center gap-1.5`,children:R?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(y,{className:`w-3.5 h-3.5 animate-spin`}),(0,D.jsx)(`span`,{children:`VERIFYING TOKEN...`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(x,{className:`w-3.5 h-3.5`}),(0,D.jsx)(`span`,{children:`SAVE & CONNECT TOKEN`})]})})]})]})]}),K&&(0,D.jsxs)(`div`,{className:`p-3 border-[2px] border-ink-black text-xs font-semibold rounded flex items-center justify-between gap-2 ${K.type===`success`?`bg-emerald-100 text-emerald-900 border-emerald-600`:K.type===`error`?`bg-rose-100 text-rose-900 border-rose-600`:`bg-sky-100 text-sky-900 border-sky-600`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[K.type===`success`?(0,D.jsx)(v,{className:`w-4 h-4 shrink-0`}):(0,D.jsx)(i,{className:`w-4 h-4 shrink-0`}),(0,D.jsx)(`span`,{children:K.text})]}),K.linkUrl&&(0,D.jsxs)(`a`,{href:K.linkUrl,target:`_blank`,rel:`noopener noreferrer`,className:`px-2 py-0.5 bg-white border border-ink-black text-[10px] font-bold text-ink-black hover:bg-slate-50 no-underline shrink-0 flex items-center gap-1`,children:[(0,D.jsx)(`span`,{children:`Open`}),(0,D.jsx)(o,{className:`w-3 h-3`})]})]})]}),(0,D.jsx)(`div`,{className:`pt-4 border-t border-slate-300 flex justify-end`,children:(0,D.jsx)(`button`,{onClick:e,className:`px-4 py-2 bg-white hover:bg-slate-100 border-[2px] border-ink-black text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none cursor-pointer uppercase`,children:`CLOSE`})})]})};export{O as GitHubSyncWindow,O as default};
 
 
algospaced-ui/dist/assets/{JourneyPath-Dg9Be99S.js → JourneyPath-BXnxFEFy.js} RENAMED
The diff for this file is too large to render. See raw diff
 
algospaced-ui/dist/assets/PrincessChamber-CXQLBBNW.js ADDED
@@ -0,0 +1 @@
 
 
1
+ import{a as e,c as t,s as n,t as r}from"./jsx-runtime-j9uSgrFF.js";import{A as i,C as a,D as o,E as s,G as c,I as l,O as u,P as d,S as f,T as p,W as m,_ as h,b as g,j as _,v,w as y,x as b,y as x,z as S}from"./index-V2pPJO9M.js";var C=c(`castle`,[[`path`,{d:`M10 5V3`,key:`1y54qe`}],[`path`,{d:`M14 5V3`,key:`m6isi`}],[`path`,{d:`M15 21v-3a3 3 0 0 0-6 0v3`,key:`lbp5hj`}],[`path`,{d:`M18 3v8`,key:`2ollhf`}],[`path`,{d:`M18 5H6`,key:`98imr9`}],[`path`,{d:`M22 11H2`,key:`1lmjae`}],[`path`,{d:`M22 9v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9`,key:`1rly83`}],[`path`,{d:`M6 3v8`,key:`csox7g`}]]),w=c(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),T=c(`rotate-ccw-clock`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),E=c(`scroll`,[[`path`,{d:`M19 17V5a2 2 0 0 0-2-2H4`,key:`zz82l3`}],[`path`,{d:`M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3`,key:`1ph1d7`}]]),D=c(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),O=c(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),k=t(e(),1),A={1:{particleType:`pollen`,particleCount:16,particleColors:[`#FDE047`,`#FEF08A`,`#86EFAC`],gradientBg:`from-[#FFFDF0] via-[#FFF9E6] to-[#FEF3C7]`,glowColor:`rgba(251, 191, 36, 0.3)`,badgeLabel:`🌾 Plains Breeze`},2:{particleType:`leaves`,particleCount:18,particleColors:[`#86EFAC`,`#4ADE80`,`#22C55E`,`#A7F3D0`],gradientBg:`from-[#F0FDF4] via-[#DCFCE7] to-[#FEF9C3]`,glowColor:`rgba(34, 197, 94, 0.3)`,badgeLabel:`🍃 Whispering Leaves`},3:{particleType:`spores`,particleCount:22,particleColors:[`#67E8F9`,`#38BDF8`,`#818CF8`,`#C084FC`],gradientBg:`from-[#F0F9FF] via-[#E0F2FE] to-[#EDE9FE]`,glowColor:`rgba(56, 189, 248, 0.35)`,badgeLabel:`✨ Crystal Spores`},4:{particleType:`snow`,particleCount:28,particleColors:[`#FFFFFF`,`#E0F2FE`,`#BAE6FD`],gradientBg:`from-[#F8FAFC] via-[#F1F5F9] to-[#E2E8F0]`,glowColor:`rgba(186, 230, 253, 0.4)`,badgeLabel:`❄️ Alpine Snowfall`},5:{particleType:`runes`,particleCount:20,particleColors:[`#E879F9`,`#C084FC`,`#A855F7`,`#F472B6`],gradientBg:`from-[#FAF5FF] via-[#F3E8FF] to-[#FCE7F3]`,glowColor:`rgba(192, 132, 252, 0.4)`,badgeLabel:`🔮 Arcane Runes`},6:{particleType:`stardust`,particleCount:35,particleColors:[`#FDE047`,`#F59E0B`,`#E11D48`,`#818CF8`],gradientBg:`from-[#FFFBEB] via-[#FEF3C7] to-[#FFE4E6]`,glowColor:`rgba(245, 158, 11, 0.5)`,badgeLabel:`👑 Spire Gates`}};function j(e){return e<=30?A[1]:e<=60?A[2]:e<=90?A[3]:e<=120?A[4]:e<150?A[5]:A[6]}var M=r();function N({emotion:e,floor:t,rhythm:n,activity:r,isLoading:i=!1}){let a=g[e]||g.smiling_warmly,o=(0,k.useMemo)(()=>j(t),[t]),s=(0,k.useMemo)(()=>{switch(n){case`dawn`:return`from-amber-400/40 via-yellow-300/30 to-rose-300/20`;case`dusk`:return`from-orange-400/40 via-purple-400/30 to-amber-300/20`;case`night`:return`from-indigo-600/40 via-blue-500/30 to-amber-500/20`;default:return`from-amber-400/30 via-yellow-300/40 to-indigo-400/30`}},[n]);return(0,M.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center my-auto w-full max-w-xl`,children:[(0,M.jsx)(`div`,{className:`absolute -inset-10 overflow-hidden pointer-events-none z-0`,children:Array.from({length:Math.min(18,o.particleCount)}).map((e,t)=>{let n=o.particleColors[t%o.particleColors.length],r=`${t*19%100}%`,i=`${6+t%5*2}s`,a=`${t*.7%4}s`,s=o.particleType===`leaves`||o.particleType===`runes`?`w-2.5 h-2.5`:`w-1.5 h-1.5`;return(0,M.jsx)(`span`,{className:`absolute rounded-full opacity-65 animate-pulse ${s}`,style:{backgroundColor:n,left:r,top:`${t*23%90}%`,boxShadow:`0 0 8px ${n}`,animationDuration:i,animationDelay:a}},t)})}),(0,M.jsxs)(`div`,{className:`relative group z-10`,children:[(0,M.jsx)(`div`,{className:`absolute -inset-2 bg-gradient-to-r ${s} rounded-2xl blur-md opacity-80 group-hover:opacity-100 transition duration-500`}),(0,M.jsxs)(`div`,{className:`relative w-36 h-44 sm:w-44 sm:h-52 bg-gradient-to-b from-amber-100 to-amber-200 border-[3px] border-ink-black rounded-xl overflow-hidden shadow-[4px_4px_0px_0px_#1E293B] transition-transform duration-300 flex items-center justify-center`,children:[(0,M.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center text-amber-700/40 pointer-events-none select-none`,children:[(0,M.jsx)(_,{className:`w-8 h-8 animate-pulse`}),(0,M.jsx)(`span`,{className:`font-arcade text-[10px] mt-2`,children:`Princess Aurelia`})]}),(0,M.jsx)(`img`,{src:a.imagePath,alt:a.label,loading:`eager`,className:`w-full h-full object-cover object-top transition-all duration-300 relative z-10 ${i?`scale-105 filter saturate-125`:`scale-100`}`,onError:e=>{let t=e.currentTarget;t.src.endsWith(`/sprites/princess/neutral.png`)?t.style.display=`none`:t.src=`/sprites/princess/neutral.png`}}),(0,M.jsxs)(`div`,{className:`absolute bottom-0 inset-x-0 bg-ink-black/85 backdrop-blur-xs text-[10px] text-amber-300 py-1 px-2 font-bold uppercase tracking-wider text-center flex items-center justify-center gap-1.5`,children:[(0,M.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${i?`bg-amber-400 animate-ping`:`bg-emerald-400`}`}),(0,M.jsx)(`span`,{children:i?`Pondering...`:a.label})]})]}),(0,M.jsx)(`div`,{className:`absolute -top-2 -right-2 bg-[#FFE24C] border-[2px] border-ink-black rounded-full p-1 shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,M.jsx)(_,{className:`w-3.5 h-3.5 text-amber-800`})})]}),r&&(0,M.jsx)(`div`,{className:`mt-2 text-center max-w-sm px-2`,children:(0,M.jsxs)(`span`,{className:`text-[10px] font-semibold text-slate-700 bg-white/85 px-2.5 py-0.5 rounded-full border border-ink-black/20 shadow-xs inline-flex items-center gap-1`,children:[(0,M.jsx)(`span`,{children:`🏰`}),(0,M.jsx)(`span`,{className:`truncate`,children:r})]})})]})}function P({text:e,characterName:t,emotion:n,isLoading:r=!1,isStreaming:i=!1,toolCalls:a,onTypingStatusChange:o}){let[s,c]=(0,k.useState)(e),[l,u]=(0,k.useState)(!1),d=(0,k.useRef)(null),f=(0,k.useRef)(e),p=(0,k.useRef)(0),m=(0,k.useRef)(o);(0,k.useEffect)(()=>{m.current=o},[o]);let h=g[n]||g.smiling_warmly,_=e=>{u(e),m.current?.(e)};return(0,k.useEffect)(()=>{if(i){d.current&&clearInterval(d.current),c(e),_(!0),e.length-p.current>=4&&(p.current=e.length,v(e.length)),f.current=e;return}if(e!==f.current&&!r){let t=f.current.length>0&&e.startsWith(f.current);if(f.current=e,d.current&&clearInterval(d.current),t)c(e),_(!1);else{c(``),_(!0);let t=0;d.current=setInterval(()=>{t<e.length?(t++,c(e.slice(0,t)),t%2==0&&e[t-1]!==` `&&v(t)):(d.current&&clearInterval(d.current),_(!1))},22)}}else!r&&e===f.current&&!i&&(c(e),l&&_(!1));return()=>{d.current&&clearInterval(d.current)}},[e,r,i]),(0,M.jsxs)(`div`,{onClick:()=>{l&&(d.current&&clearInterval(d.current),c(e),_(!1))},className:`w-full max-w-xl mt-3 sm:mt-4 relative bg-white border-[3px] border-ink-black rounded-xl p-3.5 sm:p-4 shadow-[4px_4px_0px_0px_#1E293B] transition-all cursor-pointer group select-text`,children:[(0,M.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 w-0 h-0 border-x-8 border-x-transparent border-b-8 border-b-ink-black pointer-events-none`}),(0,M.jsx)(`div`,{className:`absolute -top-2 left-1/2 -translate-x-1/2 w-0 h-0 border-x-6 border-x-transparent border-b-6 border-b-white pointer-events-none`}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-amber-100 pb-1.5 mb-2 select-none`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsxs)(`span`,{className:`font-headline-md font-bold text-xs text-amber-900 flex items-center gap-1`,children:[`👑 `,t||`Princess Aurelia`]}),(0,M.jsx)(`span`,{className:`text-[9px] bg-amber-100 text-amber-800 font-bold px-1.5 py-0.2 rounded border border-amber-200`,children:h.label})]}),l&&(0,M.jsx)(`span`,{className:`text-[9px] text-trash-gray font-medium animate-pulse`,children:`Click bubble to skip`})]}),r?(0,M.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-xs font-medium text-trash-gray select-none`,children:[(0,M.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce`}),(0,M.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.2s]`}),(0,M.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.4s]`}),(0,M.jsxs)(`span`,{className:`ml-1 text-slate-600`,children:[t||`Princess Aurelia`,` is attuning the crystal relay...`]})]}):(0,M.jsxs)(`div`,{className:`text-xs sm:text-[13px] text-ink-black font-medium leading-relaxed whitespace-pre-wrap`,children:[(e=>e.split(/(\*[^*]+\*)/g).map((e,t)=>e.startsWith(`*`)&&e.endsWith(`*`)?(0,M.jsx)(`span`,{className:`text-amber-700 italic font-semibold mr-1 inline-block`,children:e},t):(0,M.jsx)(`span`,{children:e},t)))(s),l&&(0,M.jsx)(`span`,{className:`inline-block w-1.5 h-3.5 bg-amber-500 ml-1 animate-pulse align-middle`})]}),a&&a.length>0&&!r&&(0,M.jsx)(`div`,{className:`mt-2.5 pt-2 border-t border-amber-100/80 flex flex-wrap gap-1.5 select-none`,children:a.map((e,t)=>{let n=`✨ Enchantment: ${e.name}`;return e.name===`open_app_window`&&(n=`📜 Summoned: ${e.args?.window_id||`Grimoire`}`),e.name===`set_study_timer`&&(n=`⏳ Hourglass: ${e.args?.minutes||15}m rest`),e.name===`play_ambient_sound`&&(n=`🔥 Kindled: ${e.args?.soundscape||`Soundscape`}`),e.name===`write_spire_diary`&&(n=`📖 Chronicled in Spire Diary`),(0,M.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 flex items-center gap-1 shadow-xs`,children:(0,M.jsx)(`span`,{children:n})},t)})})]})}var F=[{label:`💪 Solved a Tough One`,prompt:`I just solved a really tough problem! Felt so good getting all test cases to pass.`},{label:`😩 Feeling Stuck`,prompt:`I feel really stuck and discouraged today. It feels like everyone else gets this except me.`},{label:`☕ Need a Breather`,prompt:`My brain is pretty fried from practicing today. Can we just take a short breather?`},{label:`🌙 Life Beyond the Tower`,prompt:`What’s the first thing you want to do once we break the seals and get you out of that tower?`}];function I({suggestions:e,isLoading:t=!1,onSendMessage:n,placeholder:r=`Speak with Princess Aurelia...`}){let[i,a]=(0,k.useState)(``),o=()=>{let e=i.trim();e&&!t&&(n(e),a(``))},s=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),o())},c=Array.isArray(e)&&e.length>0;return(0,M.jsxs)(`div`,{className:`w-full flex flex-col items-center gap-2 select-none z-10`,children:[(0,M.jsx)(`div`,{className:`w-full max-w-xl flex items-center justify-center gap-1.5 flex-wrap py-1.5 px-2`,children:c?e.map((e,r)=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>n(e),disabled:t,className:`px-2.5 py-1 bg-white hover:bg-amber-100 disabled:opacity-50 border-[1.5px] border-ink-black rounded-full text-[10px] sm:text-[11px] font-bold text-slate-800 cursor-pointer shadow-[1px_1px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1`,children:[(0,M.jsx)(_,{className:`w-3 h-3 text-amber-600 shrink-0`}),(0,M.jsx)(`span`,{className:`truncate max-w-[200px]`,children:e})]},r)):F.map((e,r)=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>n(e.prompt),disabled:t,className:`px-2.5 py-1 bg-white hover:bg-amber-100 disabled:opacity-50 border-[1.5px] border-ink-black rounded-full text-[10px] sm:text-[11px] font-bold text-slate-800 cursor-pointer shadow-[1px_1px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all`,children:e.label},r))}),(0,M.jsxs)(`div`,{className:`w-full bg-white border-t-[3px] border-ink-black p-3 sm:px-4 flex items-center gap-2 shrink-0`,children:[(0,M.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),onKeyDown:s,disabled:t,placeholder:r,className:`flex-1 bg-[#FFFDF0] border-[2px] border-ink-black rounded-lg px-3.5 py-2 text-xs sm:text-sm font-medium text-ink-black placeholder-slate-400 focus:outline-none focus:border-amber-500 shadow-inner disabled:opacity-50`}),(0,M.jsxs)(`button`,{type:`button`,onClick:o,disabled:t||!i.trim(),className:`px-4 sm:px-5 py-2 bg-[#FFE24C] hover:bg-yellow-300 disabled:opacity-50 border-[2px] border-ink-black rounded-lg font-bold text-xs sm:text-sm text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center gap-1.5 shrink-0`,children:[(0,M.jsx)(D,{className:`w-3.5 h-3.5`}),(0,M.jsx)(`span`,{children:`Send`})]})]})]})}function L({currentFloor:e,onClose:t}){let n=y(e),r=Math.min(100,Math.round(e/150*100));return(0,M.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:t,children:(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl p-4 sm:p-5 max-w-md w-full shadow-[6px_6px_0px_0px_#1E293B] flex flex-col gap-3.5`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{className:`w-5 h-5 text-indigo-600`}),(0,M.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`Journey to the Big-O Spire`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,M.jsx)(s,{className:`w-4 h-4`})})]}),(0,M.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-xs font-bold font-headline-md`,children:[(0,M.jsx)(`span`,{children:`Path Progress:`}),(0,M.jsxs)(`span`,{className:`font-arcade bg-indigo-100 text-indigo-900 px-2 py-0.5 rounded border border-indigo-300`,children:[e,` / 150 Leagues`]})]}),(0,M.jsx)(`div`,{className:`w-full bg-slate-200 h-4 border-[2px] border-ink-black rounded-full overflow-hidden p-0.5`,children:(0,M.jsx)(`div`,{className:`bg-gradient-to-r from-amber-400 via-yellow-400 to-emerald-400 h-full rounded-full transition-all duration-500`,style:{width:`${r}%`}})}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] text-trash-gray font-medium`,children:[(0,M.jsxs)(`span`,{children:[`Progress: `,(0,M.jsxs)(`strong`,{children:[r,`%`]})]}),(0,M.jsxs)(`span`,{children:[`Distance to Tower: `,(0,M.jsxs)(`strong`,{children:[Math.max(0,150-e),` leagues`]})]})]})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[2px] border-ink-black rounded-lg p-3 shadow-[2px_2px_0px_0px_#1E293B] flex flex-col gap-1`,children:[(0,M.jsx)(`div`,{className:`text-[10px] font-bold uppercase text-amber-700 tracking-wider`,children:`Current Realm:`}),(0,M.jsx)(`div`,{className:`font-bold text-xs text-ink-black`,children:n.title}),(0,M.jsx)(`p`,{className:`text-[11px] text-slate-600 m-0 leading-relaxed font-medium`,children:n.description}),(0,M.jsxs)(`div`,{className:`text-[10px] text-amber-900 bg-amber-50 p-1.5 rounded border border-amber-200 italic mt-1`,children:[`📜 `,n.bgLore]})]}),(0,M.jsx)(`div`,{className:`flex items-center justify-between gap-1 text-center`,children:[{floor:30,label:`Arrays`},{floor:60,label:`Pointers`},{floor:90,label:`Trees`},{floor:120,label:`Heaps`},{floor:150,label:`Spire`}].map(t=>{let n=e>=t.floor;return(0,M.jsxs)(`div`,{className:`flex-1 p-1.5 rounded border text-[10px] flex flex-col items-center ${n?`bg-emerald-100 border-emerald-600 text-emerald-900 font-bold`:`bg-slate-100 border-slate-300 text-slate-500`}`,children:[(0,M.jsx)(`span`,{children:n?`✓`:t.floor}),(0,M.jsx)(`span`,{className:`text-[9px] truncate w-full`,children:t.label})]},t.floor)})}),(0,M.jsx)(`div`,{className:`flex items-center justify-end border-t border-slate-200 pt-2 mt-1`,children:(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Done`})})]})})}function R({unlockedLetters:e,spireChronicles:t,currentFloor:n,heroCodex:r,episodicEvents:o,recentToolTelemetry:c,onRemoveCodexItem:u,onClose:d}){let[f,h]=(0,k.useState)(`letters`),[g,v]=(0,k.useState)(e[e.length-1]||null);return(0,M.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/50 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:d,children:(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[85%] max-h-[560px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(E,{className:`w-5 h-5 text-amber-700`}),(0,M.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`The Royal Satchel`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:d,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,M.jsx)(s,{className:`w-4 h-4`})})]}),(0,M.jsxs)(`div`,{className:`flex border-b-2 border-ink-black bg-amber-100/70 shrink-0`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>h(`letters`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${f===`letters`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,M.jsx)(E,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Missives (`,e.length,`/5)`]})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>h(`diary`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${f===`diary`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,M.jsx)(m,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Chronicles (`,t.length,`)`]})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>h(`codex`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer ${f===`codex`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,M.jsx)(_,{className:`w-3.5 h-3.5 text-amber-700`}),(0,M.jsx)(`span`,{children:`Codex`})]})]}),(0,M.jsxs)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-3 min-h-0`,children:[f===`letters`&&(0,M.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1`,children:[(0,M.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto pb-1`,children:[30,60,90,120,150].map(e=>{let t=a[e],r=n>=e,i=g?.floor===e;return(0,M.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&v(t),className:`px-3 py-1 rounded-full text-[11px] font-bold border-[1.5px] border-ink-black flex items-center gap-1 shrink-0 transition-all cursor-pointer ${r?i?`bg-[#FFE24C] text-ink-black shadow-[1.5px_1.5px_0px_0px_#1E293B]`:`bg-white hover:bg-amber-100 text-slate-800`:`opacity-40 bg-slate-200 text-slate-500 cursor-not-allowed`}`,children:[r?(0,M.jsx)(`span`,{children:`📜`}):(0,M.jsx)(l,{className:`w-3 h-3`}),(0,M.jsxs)(`span`,{children:[`League `,e]})]},e)})}),g?(0,M.jsxs)(`div`,{className:`bg-[#FFF9E6] border-[2px] border-amber-900/40 rounded-lg p-4 shadow-sm flex-1 overflow-y-auto custom-scrollbar flex flex-col select-text`,children:[(0,M.jsxs)(`div`,{className:`border-b border-amber-800/20 pb-2 mb-3 flex items-center justify-between`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{className:`text-[10px] font-bold text-amber-800 uppercase tracking-wider`,children:[g.chapterTitle,` • League `,g.floor]}),(0,M.jsx)(`h5`,{className:`font-headline-md font-bold text-sm text-amber-950 m-0`,children:g.title})]}),(0,M.jsx)(`span`,{className:`text-xl`,children:`🪶`})]}),(0,M.jsx)(`p`,{className:`text-xs sm:text-[13px] text-amber-950 font-serif leading-relaxed whitespace-pre-wrap flex-1 italic`,children:g.letterText})]}):(0,M.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,M.jsx)(l,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,M.jsx)(`p`,{className:`text-xs font-medium`,children:`Conquer 30 LeetCode problems along the path to receive your first Royal Missive from Aurelia.`})]})]}),f===`diary`&&(0,M.jsx)(`div`,{className:`flex flex-col gap-2.5 flex-1`,children:t.length>0?t.map(e=>(0,M.jsxs)(`div`,{className:`p-3 bg-white border-[1.5px] border-ink-black rounded-lg shadow-xs flex flex-col gap-1 select-text`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-amber-800 font-bold border-b border-slate-100 pb-1`,children:[(0,M.jsxs)(`span`,{children:[`League `,e.floor,` along the Path`]}),(0,M.jsx)(`span`,{children:new Date(e.timestamp).toLocaleDateString()})]}),(0,M.jsxs)(`p`,{className:`text-xs text-ink-black font-medium leading-relaxed m-0 italic font-serif`,children:[`“`,e.text,`”`]})]},e.id)):(0,M.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,M.jsx)(m,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,M.jsx)(`p`,{className:`text-xs font-medium`,children:`Aurelia records entries in her Spire Chronicles autonomously as you chat, rest, and cross chapter milestones.`})]})}),f===`codex`&&(0,M.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1 select-text`,children:[(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1.5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsx)(_,{className:`w-4 h-4 text-amber-600`}),(0,M.jsx)(`h5`,{className:`font-headline-md font-bold text-xs text-ink-black m-0`,children:`Hero Codex (MemGPT & Mem0 Core Memory)`})]}),(0,M.jsx)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:`Cognitive Sync`})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs`,children:[(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,M.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Hero Alias`}),(0,M.jsx)(`span`,{className:`font-bold text-ink-black text-xs`,children:r?.heroName||`Champion`})]}),(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,M.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Target Goal`}),(0,M.jsx)(`span`,{className:`font-bold text-amber-900 text-xs`,children:r?.targetGoal||`None shared yet (mention to Aurelia!)`})]})]}),r?.preferredLanguage&&(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2 text-xs`,children:[(0,M.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Weapon of Choice (Language)`}),(0,M.jsx)(`span`,{className:`font-bold text-ink-black`,children:r.preferredLanguage})]})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-emerald-800`,children:[(0,M.jsx)(S,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Mastered Patterns (`,r?.strengths?.length||0,`)`]})]}),r?.strengths&&r.strengths.length>0?(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.strengths.map(e=>(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-300`,children:[e,u&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`strengths`,e),className:`hover:text-red-600 ml-0.5 cursor-pointer`,title:`Forget strength`,children:(0,M.jsx)(s,{className:`w-3 h-3`})})]},e))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia will note topics you conquer during your practice.`})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-rose-800`,children:[(0,M.jsx)(O,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Nemesis Patterns (`,r?.nemesisPatterns?.length||0,`)`]})]}),r?.nemesisPatterns&&r.nemesisPatterns.length>0?(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.nemesisPatterns.map(e=>(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-rose-50 text-rose-800 border border-rose-300`,children:[e,u&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`nemesisPatterns`,e),className:`hover:text-red-700 ml-0.5 cursor-pointer`,title:`Forget nemesis`,children:(0,M.jsx)(s,{className:`w-3 h-3`})})]},e))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia tracks patterns that give you trouble to help you prepare targeted drills.`})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-bold text-slate-800`,children:(0,M.jsxs)(`span`,{children:[`Personal Notes & Shared Lore (`,r?.personalNotes?.length||0,`)`]})}),r?.personalNotes&&r.personalNotes.length>0?(0,M.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.personalNotes.map(e=>(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-2 bg-slate-50 border border-slate-200 rounded text-[11px] text-slate-700`,children:[(0,M.jsxs)(`span`,{children:[`• `,e]}),u&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(`personalNotes`,e),className:`text-slate-400 hover:text-red-600 shrink-0 cursor-pointer p-0.5`,title:`Forget note`,children:(0,M.jsx)(i,{className:`w-3 h-3`})})]},e))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Share your background or routine with Aurelia and she will hold it in her memory.`})]}),o&&o.length>0&&(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,M.jsx)(`span`,{className:`text-xs font-bold text-slate-800`,children:`Episodic Memory Chain (EM-LLM)`}),(0,M.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[o.length,` events`]})]}),(0,M.jsx)(`div`,{className:`flex flex-col gap-2 max-h-40 overflow-y-auto custom-scrollbar`,children:o.slice(0,8).map(e=>(0,M.jsxs)(`div`,{className:`text-[11px] p-2 bg-[#FFFDF0] border border-amber-900/15 rounded flex flex-col gap-0.5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsx)(`span`,{className:`font-bold text-ink-black uppercase text-[9px] px-1.5 py-0.5 bg-amber-200/60 rounded`,children:e.eventType.replace(`_`,` `)}),(0,M.jsx)(`span`,{className:`text-[10px] text-slate-400`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),(0,M.jsx)(`div`,{className:`font-bold text-slate-800 mt-0.5`,children:e.title}),(0,M.jsx)(`div`,{className:`text-slate-600 text-[10px]`,children:e.description})]},e.id))})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-indigo-900`,children:[(0,M.jsx)(p,{className:`w-3.5 h-3.5 text-amber-500`}),(0,M.jsx)(`span`,{children:`Autonomous Enchantment Telemetry`})]}),(0,M.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[c?.length||0,` executed`]})]}),c&&c.length>0?(0,M.jsx)(`div`,{className:`flex flex-col gap-1.5 max-h-36 overflow-y-auto custom-scrollbar`,children:c.slice(0,10).map((e,t)=>(0,M.jsxs)(`div`,{className:`text-[11px] p-2 bg-indigo-50/50 border border-indigo-100 rounded flex items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,M.jsxs)(`span`,{className:`font-bold text-indigo-950 font-mono text-[10px] truncate`,children:[e.tool_name,`()`]}),e.args&&Object.keys(e.args).length>0&&(0,M.jsx)(`span`,{className:`text-[9px] text-slate-500 truncate`,children:JSON.stringify(e.args).slice(0,50)})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.execution_time_ms!==void 0&&(0,M.jsxs)(`span`,{className:`text-[9px] text-slate-400 flex items-center gap-0.5 font-mono`,children:[(0,M.jsx)(w,{className:`w-2.5 h-2.5`}),e.execution_time_ms,`ms`]}),(0,M.jsx)(`span`,{className:`px-1.5 py-0.2 text-[9px] font-bold rounded ${e.success?`bg-emerald-100 text-emerald-800`:`bg-rose-100 text-rose-800`}`,children:e.success?`SUCCESS`:`ERR`})]})]},t))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`No autonomous enchantments executed yet in this session.`})]})]})]}),(0,M.jsx)(`div`,{className:`bg-white border-t border-slate-200 px-4 py-2 flex items-center justify-end shrink-0`,children:(0,M.jsx)(`button`,{type:`button`,onClick:d,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Close`})})]})})}var z=n({default:()=>B});function B(){let e=f(),[t,n]=(0,k.useState)(h()),[r,i]=(0,k.useState)(!1),[a,c]=(0,k.useState)(!1),[l,p]=(0,k.useState)(!1);(0,k.useEffect)(()=>{b.syncWithBackend(),b.triggerProactiveGreeting()},[]);let m=()=>{let e=!t;n(e),x(e)},g=()=>{window.confirm(`Clear conversation transcript with Princess Aurelia?`)&&b.clearTranscript()},v=(0,k.useCallback)(e=>{b.setIsTyping(e)},[]),y=(0,k.useMemo)(()=>[...e.transcript].reverse().find(e=>e.sender===`princess`)||e.transcript[0],[e.transcript]);return(0,M.jsxs)(`div`,{className:`relative w-full h-full bg-gradient-to-b from-[#FFFDF0] via-[#FFF9E6] to-[#FFF3CD] flex flex-col select-none font-sans text-ink-black overflow-hidden`,children:[(0,M.jsxs)(`div`,{className:`h-12 bg-white/95 backdrop-blur-sm border-b-[3px] border-ink-black px-3 sm:px-4 flex items-center justify-between gap-2 shrink-0 shadow-sm z-20`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,M.jsx)(_,{className:`w-4 h-4 text-amber-500 shrink-0`}),(0,M.jsx)(`h3`,{className:`font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0 truncate`,children:e.companionSettings.name||`Princess Aurelia`})]}),(0,M.jsx)(`span`,{className:`hidden sm:inline-flex px-2 py-0.5 rounded-full bg-amber-100 border border-amber-300 text-[10px] font-bold text-amber-900 shadow-inner shrink-0`,children:e.bondTier}),(0,M.jsx)(`span`,{className:`hidden md:inline-flex px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 shrink-0`,children:e.currentRhythm.toUpperCase()})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`px-2.5 py-1 bg-amber-100 hover:bg-amber-200 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5`,title:`View Spire Journey Progress`,children:[(0,M.jsx)(C,{className:`w-3.5 h-3.5 text-indigo-700`}),(0,M.jsxs)(`span`,{className:`font-arcade text-[9px] text-indigo-950`,children:[e.currentFloor,`/150 LC`]})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`px-2.5 py-1 bg-white hover:bg-amber-50 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5`,title:`Open Royal Satchel (Missives & Diary)`,children:[(0,M.jsx)(E,{className:`w-3.5 h-3.5 text-amber-700`}),(0,M.jsx)(`span`,{className:`hidden md:inline`,children:`Satchel`}),e.unlockedLetters.length>0&&(0,M.jsx)(`span`,{className:`w-4 h-4 rounded-full bg-amber-400 text-ink-black text-[9px] font-extrabold flex items-center justify-center border border-ink-black`,children:e.unlockedLetters.length})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>p(!0),className:`p-1.5 bg-white hover:bg-slate-100 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all`,title:`View Transcript History`,children:(0,M.jsx)(T,{className:`w-3.5 h-3.5 text-slate-700`})}),(0,M.jsx)(`button`,{type:`button`,onClick:m,className:`p-1.5 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all ${t?`bg-slate-200 opacity-80`:`bg-[#FFE24C] hover:bg-yellow-300`}`,title:t?`Unmute Audio`:`Mute Audio`,children:t?(0,M.jsx)(o,{className:`w-3.5 h-3.5`}):(0,M.jsx)(u,{className:`w-3.5 h-3.5`})})]})]}),(0,M.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-start gap-3 sm:gap-4 p-3 sm:p-5 overflow-y-auto custom-scrollbar min-h-0 relative`,children:[(0,M.jsx)(N,{emotion:e.activeEmotion,floor:e.currentFloor,rhythm:e.currentRhythm,activity:e.currentActivity,isLoading:e.isLoading}),(0,M.jsx)(P,{text:y?.text||`I believe in you, champion!`,characterName:e.companionSettings.name,emotion:e.activeEmotion,isLoading:e.isLoading,isStreaming:y?.isStreaming,toolCalls:y?.toolCalls,onTypingStatusChange:v})]}),(0,M.jsx)(I,{suggestions:y?.choiceSuggestions,isLoading:e.isLoading,onSendMessage:e=>b.sendMessage(e),placeholder:`Speak with ${e.companionSettings.name||`Princess Aurelia`}...`}),r&&(0,M.jsx)(L,{currentFloor:e.currentFloor,totalSolved:e.totalSolved,onClose:()=>i(!1)}),a&&(0,M.jsx)(R,{unlockedLetters:e.unlockedLetters,spireChronicles:e.spireChronicles,currentFloor:e.currentFloor,heroCodex:e.heroCodex,episodicEvents:e.episodicEvents,recentToolTelemetry:e.recentToolTelemetry,onRemoveCodexItem:b.removeCodexItem,onClose:()=>c(!1)}),l&&(0,M.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200`,onClick:()=>p(!1),children:(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[80%] max-h-[520px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(T,{className:`w-4 h-4 text-ink-black`}),(0,M.jsxs)(`h4`,{className:`font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0`,children:[`Dialogue Transcript (`,e.transcript.length,` turns)`]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:g,className:`p-1 hover:bg-rose-100 text-rose-700 rounded text-[11px] font-bold flex items-center gap-1 cursor-pointer mr-1`,title:`Clear Chat History`,children:[(0,M.jsx)(d,{className:`w-3.5 h-3.5`}),(0,M.jsx)(`span`,{children:`Clear`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>p(!1),className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,M.jsx)(s,{className:`w-4 h-4`})})]})]}),(0,M.jsx)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-2.5`,children:e.transcript.map((t,n)=>(0,M.jsxs)(`div`,{className:`p-2.5 rounded-lg border-[2px] border-ink-black shadow-[2px_2px_0px_0px_#1E293B] max-w-[90%] ${t.sender===`princess`?`bg-white text-ink-black self-start`:`bg-[#FFE24C] text-ink-black self-end`}`,children:[(0,M.jsx)(`div`,{className:`text-[10px] font-bold font-headline-md mb-1 text-slate-600`,children:t.sender===`princess`?e.companionSettings.name:`Hero`}),(0,M.jsx)(`p`,{className:`text-xs font-medium m-0 leading-relaxed whitespace-pre-wrap select-text`,children:t.text})]},t.id||n))})]})})]})}export{z as t};
algospaced-ui/dist/assets/PrincessChamber-Cu4RP8Ry.js DELETED
@@ -1 +0,0 @@
1
- import{a as e,c as t,s as n,t as r}from"./jsx-runtime-j9uSgrFF.js";import{C as i,E as a,H as o,L as s,M as c,O as l,P as u,S as d,T as f,U as p,_ as m,b as h,g,h as _,k as v,v as y,w as b,x,y as S}from"./index-g5jVBiGr.js";var C=p(`castle`,[[`path`,{d:`M10 5V3`,key:`1y54qe`}],[`path`,{d:`M14 5V3`,key:`m6isi`}],[`path`,{d:`M15 21v-3a3 3 0 0 0-6 0v3`,key:`lbp5hj`}],[`path`,{d:`M18 3v8`,key:`2ollhf`}],[`path`,{d:`M18 5H6`,key:`98imr9`}],[`path`,{d:`M22 11H2`,key:`1lmjae`}],[`path`,{d:`M22 9v10a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9`,key:`1rly83`}],[`path`,{d:`M6 3v8`,key:`csox7g`}]]),w=p(`clock`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 6v6l4 2`,key:`mmk7yg`}]]),T=p(`rotate-ccw-clock`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),E=p(`scroll`,[[`path`,{d:`M19 17V5a2 2 0 0 0-2-2H4`,key:`zz82l3`}],[`path`,{d:`M8 21h12a2 2 0 0 0 2-2v-1a1 1 0 0 0-1-1H11a1 1 0 0 0-1 1v1a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v2a1 1 0 0 0 1 1h3`,key:`1ph1d7`}]]),D=p(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),O=p(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),k=t(e(),1),A={1:{particleType:`pollen`,particleCount:16,particleColors:[`#FDE047`,`#FEF08A`,`#86EFAC`],gradientBg:`from-[#FFFDF0] via-[#FFF9E6] to-[#FEF3C7]`,glowColor:`rgba(251, 191, 36, 0.3)`,badgeLabel:`🌾 Plains Breeze`},2:{particleType:`leaves`,particleCount:18,particleColors:[`#86EFAC`,`#4ADE80`,`#22C55E`,`#A7F3D0`],gradientBg:`from-[#F0FDF4] via-[#DCFCE7] to-[#FEF9C3]`,glowColor:`rgba(34, 197, 94, 0.3)`,badgeLabel:`🍃 Whispering Leaves`},3:{particleType:`spores`,particleCount:22,particleColors:[`#67E8F9`,`#38BDF8`,`#818CF8`,`#C084FC`],gradientBg:`from-[#F0F9FF] via-[#E0F2FE] to-[#EDE9FE]`,glowColor:`rgba(56, 189, 248, 0.35)`,badgeLabel:`✨ Crystal Spores`},4:{particleType:`snow`,particleCount:28,particleColors:[`#FFFFFF`,`#E0F2FE`,`#BAE6FD`],gradientBg:`from-[#F8FAFC] via-[#F1F5F9] to-[#E2E8F0]`,glowColor:`rgba(186, 230, 253, 0.4)`,badgeLabel:`❄️ Alpine Snowfall`},5:{particleType:`runes`,particleCount:20,particleColors:[`#E879F9`,`#C084FC`,`#A855F7`,`#F472B6`],gradientBg:`from-[#FAF5FF] via-[#F3E8FF] to-[#FCE7F3]`,glowColor:`rgba(192, 132, 252, 0.4)`,badgeLabel:`🔮 Arcane Runes`},6:{particleType:`stardust`,particleCount:35,particleColors:[`#FDE047`,`#F59E0B`,`#E11D48`,`#818CF8`],gradientBg:`from-[#FFFBEB] via-[#FEF3C7] to-[#FFE4E6]`,glowColor:`rgba(245, 158, 11, 0.5)`,badgeLabel:`👑 Spire Gates`}};function j(e){return e<=30?A[1]:e<=60?A[2]:e<=90?A[3]:e<=120?A[4]:e<150?A[5]:A[6]}var M=r();function N({emotion:e,floor:t,rhythm:n,activity:r,isLoading:i=!1}){let a=y[e]||y.smiling_warmly,o=(0,k.useMemo)(()=>j(t),[t]),s=(0,k.useMemo)(()=>{switch(n){case`dawn`:return`from-amber-400/40 via-yellow-300/30 to-rose-300/20`;case`dusk`:return`from-orange-400/40 via-purple-400/30 to-amber-300/20`;case`night`:return`from-indigo-600/40 via-blue-500/30 to-amber-500/20`;default:return`from-amber-400/30 via-yellow-300/40 to-indigo-400/30`}},[n]);return(0,M.jsxs)(`div`,{className:`relative flex flex-col items-center justify-center my-auto w-full max-w-xl`,children:[(0,M.jsx)(`div`,{className:`absolute -inset-10 overflow-hidden pointer-events-none z-0`,children:Array.from({length:Math.min(18,o.particleCount)}).map((e,t)=>{let n=o.particleColors[t%o.particleColors.length],r=`${t*19%100}%`,i=`${6+t%5*2}s`,a=`${t*.7%4}s`,s=o.particleType===`leaves`||o.particleType===`runes`?`w-2.5 h-2.5`:`w-1.5 h-1.5`;return(0,M.jsx)(`span`,{className:`absolute rounded-full opacity-65 animate-pulse ${s}`,style:{backgroundColor:n,left:r,top:`${t*23%90}%`,boxShadow:`0 0 8px ${n}`,animationDuration:i,animationDelay:a}},t)})}),(0,M.jsxs)(`div`,{className:`relative group z-10`,children:[(0,M.jsx)(`div`,{className:`absolute -inset-2 bg-gradient-to-r ${s} rounded-2xl blur-md opacity-80 group-hover:opacity-100 transition duration-500`}),(0,M.jsxs)(`div`,{className:`relative w-36 h-44 sm:w-44 sm:h-52 bg-gradient-to-b from-amber-100 to-amber-200 border-[3px] border-ink-black rounded-xl overflow-hidden shadow-[4px_4px_0px_0px_#1E293B] transition-transform duration-300 flex items-center justify-center`,children:[(0,M.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center text-amber-700/40 pointer-events-none select-none`,children:[(0,M.jsx)(v,{className:`w-8 h-8 animate-pulse`}),(0,M.jsx)(`span`,{className:`font-arcade text-[10px] mt-2`,children:`Princess Aurelia`})]}),(0,M.jsx)(`img`,{src:a.imagePath,alt:a.label,loading:`eager`,className:`w-full h-full object-cover object-top transition-all duration-300 relative z-10 ${i?`scale-105 filter saturate-125`:`scale-100`}`,onError:e=>{let t=e.currentTarget;t.src.endsWith(`/sprites/princess/neutral.png`)?t.style.display=`none`:t.src=`/sprites/princess/neutral.png`}}),(0,M.jsxs)(`div`,{className:`absolute bottom-0 inset-x-0 bg-ink-black/85 backdrop-blur-xs text-[10px] text-amber-300 py-1 px-2 font-bold uppercase tracking-wider text-center flex items-center justify-center gap-1.5`,children:[(0,M.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full ${i?`bg-amber-400 animate-ping`:`bg-emerald-400`}`}),(0,M.jsx)(`span`,{children:i?`Pondering...`:a.label})]})]}),(0,M.jsx)(`div`,{className:`absolute -top-2 -right-2 bg-[#FFE24C] border-[2px] border-ink-black rounded-full p-1 shadow-[2px_2px_0px_0px_#1E293B]`,children:(0,M.jsx)(v,{className:`w-3.5 h-3.5 text-amber-800`})})]}),r&&(0,M.jsx)(`div`,{className:`mt-2 text-center max-w-sm px-2`,children:(0,M.jsxs)(`span`,{className:`text-[10px] font-semibold text-slate-700 bg-white/85 px-2.5 py-0.5 rounded-full border border-ink-black/20 shadow-xs inline-flex items-center gap-1`,children:[(0,M.jsx)(`span`,{children:`🏰`}),(0,M.jsx)(`span`,{className:`truncate`,children:r})]})})]})}function P({text:e,characterName:t,emotion:n,isLoading:r=!1,isStreaming:i=!1,toolCalls:a,onTypingStatusChange:o}){let[s,c]=(0,k.useState)(e),[l,u]=(0,k.useState)(!1),d=(0,k.useRef)(null),f=(0,k.useRef)(e),p=(0,k.useRef)(0),m=(0,k.useRef)(o);(0,k.useEffect)(()=>{m.current=o},[o]);let h=y[n]||y.smiling_warmly,_=e=>{u(e),m.current?.(e)};return(0,k.useEffect)(()=>{if(i){d.current&&clearInterval(d.current),c(e),_(!0),e.length-p.current>=4&&(p.current=e.length,g(e.length)),f.current=e;return}if(e!==f.current&&!r){let t=f.current.length>0&&e.startsWith(f.current);if(f.current=e,d.current&&clearInterval(d.current),t)c(e),_(!1);else{c(``),_(!0);let t=0;d.current=setInterval(()=>{t<e.length?(t++,c(e.slice(0,t)),t%2==0&&e[t-1]!==` `&&g(t)):(d.current&&clearInterval(d.current),_(!1))},22)}}else!r&&e===f.current&&!i&&(c(e),l&&_(!1));return()=>{d.current&&clearInterval(d.current)}},[e,r,i]),(0,M.jsxs)(`div`,{onClick:()=>{l&&(d.current&&clearInterval(d.current),c(e),_(!1))},className:`w-full max-w-xl mt-3 sm:mt-4 relative bg-white border-[3px] border-ink-black rounded-xl p-3.5 sm:p-4 shadow-[4px_4px_0px_0px_#1E293B] transition-all cursor-pointer group select-text`,children:[(0,M.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 w-0 h-0 border-x-8 border-x-transparent border-b-8 border-b-ink-black pointer-events-none`}),(0,M.jsx)(`div`,{className:`absolute -top-2 left-1/2 -translate-x-1/2 w-0 h-0 border-x-6 border-x-transparent border-b-6 border-b-white pointer-events-none`}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-amber-100 pb-1.5 mb-2 select-none`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsxs)(`span`,{className:`font-headline-md font-bold text-xs text-amber-900 flex items-center gap-1`,children:[`👑 `,t||`Princess Aurelia`]}),(0,M.jsx)(`span`,{className:`text-[9px] bg-amber-100 text-amber-800 font-bold px-1.5 py-0.2 rounded border border-amber-200`,children:h.label})]}),l&&(0,M.jsx)(`span`,{className:`text-[9px] text-trash-gray font-medium animate-pulse`,children:`Click bubble to skip`})]}),r?(0,M.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-xs font-medium text-trash-gray select-none`,children:[(0,M.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce`}),(0,M.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.2s]`}),(0,M.jsx)(`span`,{className:`inline-block w-2 h-2 bg-amber-500 rounded-full animate-bounce [animation-delay:0.4s]`}),(0,M.jsxs)(`span`,{className:`ml-1 text-slate-600`,children:[t||`Princess Aurelia`,` is attuning the crystal relay...`]})]}):(0,M.jsxs)(`div`,{className:`text-xs sm:text-[13px] text-ink-black font-medium leading-relaxed whitespace-pre-wrap`,children:[(e=>e.split(/(\*[^*]+\*)/g).map((e,t)=>e.startsWith(`*`)&&e.endsWith(`*`)?(0,M.jsx)(`span`,{className:`text-amber-700 italic font-semibold mr-1 inline-block`,children:e},t):(0,M.jsx)(`span`,{children:e},t)))(s),l&&(0,M.jsx)(`span`,{className:`inline-block w-1.5 h-3.5 bg-amber-500 ml-1 animate-pulse align-middle`})]}),a&&a.length>0&&!r&&(0,M.jsx)(`div`,{className:`mt-2.5 pt-2 border-t border-amber-100/80 flex flex-wrap gap-1.5 select-none`,children:a.map((e,t)=>{let n=`✨ Enchantment: ${e.name}`;return e.name===`open_app_window`&&(n=`📜 Summoned: ${e.args?.window_id||`Grimoire`}`),e.name===`set_study_timer`&&(n=`⏳ Hourglass: ${e.args?.minutes||15}m rest`),e.name===`play_ambient_sound`&&(n=`🔥 Kindled: ${e.args?.soundscape||`Soundscape`}`),e.name===`write_spire_diary`&&(n=`📖 Chronicled in Spire Diary`),(0,M.jsx)(`span`,{className:`px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 flex items-center gap-1 shadow-xs`,children:(0,M.jsx)(`span`,{children:n})},t)})})]})}var F=[{label:`💪 Solved a Tough One`,prompt:`I just solved a really tough problem! Felt so good getting all test cases to pass.`},{label:`😩 Feeling Stuck`,prompt:`I feel really stuck and discouraged today. It feels like everyone else gets this except me.`},{label:`☕ Need a Breather`,prompt:`My brain is pretty fried from practicing today. Can we just take a short breather?`},{label:`🌙 Life Beyond the Tower`,prompt:`What’s the first thing you want to do once we break the seals and get you out of that tower?`}];function I({suggestions:e,isLoading:t=!1,onSendMessage:n,placeholder:r=`Speak with Princess Aurelia...`}){let[i,a]=(0,k.useState)(``),o=()=>{let e=i.trim();e&&!t&&(n(e),a(``))},s=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),o())},c=Array.isArray(e)&&e.length>0;return(0,M.jsxs)(`div`,{className:`w-full flex flex-col items-center gap-2 select-none z-10`,children:[(0,M.jsx)(`div`,{className:`w-full max-w-xl flex items-center justify-center gap-1.5 flex-wrap py-1.5 px-2`,children:c?e.map((e,r)=>(0,M.jsxs)(`button`,{type:`button`,onClick:()=>n(e),disabled:t,className:`px-2.5 py-1 bg-white hover:bg-amber-100 disabled:opacity-50 border-[1.5px] border-ink-black rounded-full text-[10px] sm:text-[11px] font-bold text-slate-800 cursor-pointer shadow-[1px_1px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1`,children:[(0,M.jsx)(v,{className:`w-3 h-3 text-amber-600 shrink-0`}),(0,M.jsx)(`span`,{className:`truncate max-w-[200px]`,children:e})]},r)):F.map((e,r)=>(0,M.jsx)(`button`,{type:`button`,onClick:()=>n(e.prompt),disabled:t,className:`px-2.5 py-1 bg-white hover:bg-amber-100 disabled:opacity-50 border-[1.5px] border-ink-black rounded-full text-[10px] sm:text-[11px] font-bold text-slate-800 cursor-pointer shadow-[1px_1px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all`,children:e.label},r))}),(0,M.jsxs)(`div`,{className:`w-full bg-white border-t-[3px] border-ink-black p-3 sm:px-4 flex items-center gap-2 shrink-0`,children:[(0,M.jsx)(`input`,{type:`text`,value:i,onChange:e=>a(e.target.value),onKeyDown:s,disabled:t,placeholder:r,className:`flex-1 bg-[#FFFDF0] border-[2px] border-ink-black rounded-lg px-3.5 py-2 text-xs sm:text-sm font-medium text-ink-black placeholder-slate-400 focus:outline-none focus:border-amber-500 shadow-inner disabled:opacity-50`}),(0,M.jsxs)(`button`,{type:`button`,onClick:o,disabled:t||!i.trim(),className:`px-4 sm:px-5 py-2 bg-[#FFE24C] hover:bg-yellow-300 disabled:opacity-50 border-[2px] border-ink-black rounded-lg font-bold text-xs sm:text-sm text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center gap-1.5 shrink-0`,children:[(0,M.jsx)(D,{className:`w-3.5 h-3.5`}),(0,M.jsx)(`span`,{children:`Send`})]})]})]})}function L({currentFloor:e,onClose:t}){let n=d(e),r=Math.min(100,Math.round(e/150*100));return(0,M.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:t,children:(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl p-4 sm:p-5 max-w-md w-full shadow-[6px_6px_0px_0px_#1E293B] flex flex-col gap-3.5`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(C,{className:`w-5 h-5 text-indigo-600`}),(0,M.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`Journey to the Big-O Spire`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,M.jsx)(b,{className:`w-4 h-4`})})]}),(0,M.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-xs font-bold font-headline-md`,children:[(0,M.jsx)(`span`,{children:`Path Progress:`}),(0,M.jsxs)(`span`,{className:`font-arcade bg-indigo-100 text-indigo-900 px-2 py-0.5 rounded border border-indigo-300`,children:[e,` / 150 Leagues`]})]}),(0,M.jsx)(`div`,{className:`w-full bg-slate-200 h-4 border-[2px] border-ink-black rounded-full overflow-hidden p-0.5`,children:(0,M.jsx)(`div`,{className:`bg-gradient-to-r from-amber-400 via-yellow-400 to-emerald-400 h-full rounded-full transition-all duration-500`,style:{width:`${r}%`}})}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-[11px] text-trash-gray font-medium`,children:[(0,M.jsxs)(`span`,{children:[`Progress: `,(0,M.jsxs)(`strong`,{children:[r,`%`]})]}),(0,M.jsxs)(`span`,{children:[`Distance to Tower: `,(0,M.jsxs)(`strong`,{children:[Math.max(0,150-e),` leagues`]})]})]})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[2px] border-ink-black rounded-lg p-3 shadow-[2px_2px_0px_0px_#1E293B] flex flex-col gap-1`,children:[(0,M.jsx)(`div`,{className:`text-[10px] font-bold uppercase text-amber-700 tracking-wider`,children:`Current Realm:`}),(0,M.jsx)(`div`,{className:`font-bold text-xs text-ink-black`,children:n.title}),(0,M.jsx)(`p`,{className:`text-[11px] text-slate-600 m-0 leading-relaxed font-medium`,children:n.description}),(0,M.jsxs)(`div`,{className:`text-[10px] text-amber-900 bg-amber-50 p-1.5 rounded border border-amber-200 italic mt-1`,children:[`📜 `,n.bgLore]})]}),(0,M.jsx)(`div`,{className:`flex items-center justify-between gap-1 text-center`,children:[{floor:30,label:`Arrays`},{floor:60,label:`Pointers`},{floor:90,label:`Trees`},{floor:120,label:`Heaps`},{floor:150,label:`Spire`}].map(t=>{let n=e>=t.floor;return(0,M.jsxs)(`div`,{className:`flex-1 p-1.5 rounded border text-[10px] flex flex-col items-center ${n?`bg-emerald-100 border-emerald-600 text-emerald-900 font-bold`:`bg-slate-100 border-slate-300 text-slate-500`}`,children:[(0,M.jsx)(`span`,{children:n?`✓`:t.floor}),(0,M.jsx)(`span`,{className:`text-[9px] truncate w-full`,children:t.label})]},t.floor)})}),(0,M.jsx)(`div`,{className:`flex items-center justify-end border-t border-slate-200 pt-2 mt-1`,children:(0,M.jsx)(`button`,{type:`button`,onClick:t,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Done`})})]})})}function R({unlockedLetters:e,spireChronicles:t,currentFloor:n,heroCodex:r,episodicEvents:a,recentToolTelemetry:c,onRemoveCodexItem:d,onClose:f}){let[p,m]=(0,k.useState)(`letters`),[h,g]=(0,k.useState)(e[e.length-1]||null);return(0,M.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/50 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200 select-none`,onClick:f,children:(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[85%] max-h-[560px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(E,{className:`w-5 h-5 text-amber-700`}),(0,M.jsx)(`h4`,{className:`font-headline-md font-bold text-sm text-ink-black m-0`,children:`The Royal Satchel`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:f,className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,M.jsx)(b,{className:`w-4 h-4`})})]}),(0,M.jsxs)(`div`,{className:`flex border-b-2 border-ink-black bg-amber-100/70 shrink-0`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>m(`letters`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${p===`letters`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,M.jsx)(E,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Missives (`,e.length,`/5)`]})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>m(`diary`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer border-r border-ink-black/20 ${p===`diary`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,M.jsx)(o,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Chronicles (`,t.length,`)`]})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>m(`codex`),className:`flex-1 py-2 text-xs font-bold font-headline-md flex items-center justify-center gap-1.5 transition-colors cursor-pointer ${p===`codex`?`bg-[#FFFDF0] text-amber-950 border-b-2 border-b-[#FFFDF0] -mb-[2px]`:`text-slate-600 hover:bg-amber-200/50`}`,children:[(0,M.jsx)(v,{className:`w-3.5 h-3.5 text-amber-700`}),(0,M.jsx)(`span`,{children:`Codex`})]})]}),(0,M.jsxs)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-3 min-h-0`,children:[p===`letters`&&(0,M.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1`,children:[(0,M.jsx)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto pb-1`,children:[30,60,90,120,150].map(e=>{let t=x[e],r=n>=e,i=h?.floor===e;return(0,M.jsxs)(`button`,{type:`button`,disabled:!r,onClick:()=>r&&g(t),className:`px-3 py-1 rounded-full text-[11px] font-bold border-[1.5px] border-ink-black flex items-center gap-1 shrink-0 transition-all cursor-pointer ${r?i?`bg-[#FFE24C] text-ink-black shadow-[1.5px_1.5px_0px_0px_#1E293B]`:`bg-white hover:bg-amber-100 text-slate-800`:`opacity-40 bg-slate-200 text-slate-500 cursor-not-allowed`}`,children:[r?(0,M.jsx)(`span`,{children:`📜`}):(0,M.jsx)(u,{className:`w-3 h-3`}),(0,M.jsxs)(`span`,{children:[`League `,e]})]},e)})}),h?(0,M.jsxs)(`div`,{className:`bg-[#FFF9E6] border-[2px] border-amber-900/40 rounded-lg p-4 shadow-sm flex-1 overflow-y-auto custom-scrollbar flex flex-col select-text`,children:[(0,M.jsxs)(`div`,{className:`border-b border-amber-800/20 pb-2 mb-3 flex items-center justify-between`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsxs)(`div`,{className:`text-[10px] font-bold text-amber-800 uppercase tracking-wider`,children:[h.chapterTitle,` • League `,h.floor]}),(0,M.jsx)(`h5`,{className:`font-headline-md font-bold text-sm text-amber-950 m-0`,children:h.title})]}),(0,M.jsx)(`span`,{className:`text-xl`,children:`🪶`})]}),(0,M.jsx)(`p`,{className:`text-xs sm:text-[13px] text-amber-950 font-serif leading-relaxed whitespace-pre-wrap flex-1 italic`,children:h.letterText})]}):(0,M.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,M.jsx)(u,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,M.jsx)(`p`,{className:`text-xs font-medium`,children:`Conquer 30 LeetCode problems along the path to receive your first Royal Missive from Aurelia.`})]})]}),p===`diary`&&(0,M.jsx)(`div`,{className:`flex flex-col gap-2.5 flex-1`,children:t.length>0?t.map(e=>(0,M.jsxs)(`div`,{className:`p-3 bg-white border-[1.5px] border-ink-black rounded-lg shadow-xs flex flex-col gap-1 select-text`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-amber-800 font-bold border-b border-slate-100 pb-1`,children:[(0,M.jsxs)(`span`,{children:[`League `,e.floor,` along the Path`]}),(0,M.jsx)(`span`,{children:new Date(e.timestamp).toLocaleDateString()})]}),(0,M.jsxs)(`p`,{className:`text-xs text-ink-black font-medium leading-relaxed m-0 italic font-serif`,children:[`“`,e.text,`”`]})]},e.id)):(0,M.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center p-6 text-slate-500`,children:[(0,M.jsx)(o,{className:`w-8 h-8 mb-2 text-slate-400`}),(0,M.jsx)(`p`,{className:`text-xs font-medium`,children:`Aurelia records entries in her Spire Chronicles autonomously as you chat, rest, and cross chapter milestones.`})]})}),p===`codex`&&(0,M.jsxs)(`div`,{className:`flex flex-col gap-3 flex-1 select-text`,children:[(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1.5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,M.jsx)(v,{className:`w-4 h-4 text-amber-600`}),(0,M.jsx)(`h5`,{className:`font-headline-md font-bold text-xs text-ink-black m-0`,children:`Hero Codex (MemGPT & Mem0 Core Memory)`})]}),(0,M.jsx)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:`Cognitive Sync`})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2 text-xs`,children:[(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,M.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Hero Alias`}),(0,M.jsx)(`span`,{className:`font-bold text-ink-black text-xs`,children:r?.heroName||`Champion`})]}),(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2`,children:[(0,M.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Target Goal`}),(0,M.jsx)(`span`,{className:`font-bold text-amber-900 text-xs`,children:r?.targetGoal||`None shared yet (mention to Aurelia!)`})]})]}),r?.preferredLanguage&&(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border border-amber-900/20 rounded p-2 text-xs`,children:[(0,M.jsx)(`span`,{className:`text-[10px] font-bold text-slate-500 uppercase tracking-wider block`,children:`Weapon of Choice (Language)`}),(0,M.jsx)(`span`,{className:`font-bold text-ink-black`,children:r.preferredLanguage})]})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-emerald-800`,children:[(0,M.jsx)(s,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Mastered Patterns (`,r?.strengths?.length||0,`)`]})]}),r?.strengths&&r.strengths.length>0?(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.strengths.map(e=>(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-emerald-50 text-emerald-800 border border-emerald-300`,children:[e,d&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(`strengths`,e),className:`hover:text-red-600 ml-0.5 cursor-pointer`,title:`Forget strength`,children:(0,M.jsx)(b,{className:`w-3 h-3`})})]},e))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia will note topics you conquer during your practice.`})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-rose-800`,children:[(0,M.jsx)(O,{className:`w-3.5 h-3.5`}),(0,M.jsxs)(`span`,{children:[`Nemesis Patterns (`,r?.nemesisPatterns?.length||0,`)`]})]}),r?.nemesisPatterns&&r.nemesisPatterns.length>0?(0,M.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:r.nemesisPatterns.map(e=>(0,M.jsxs)(`span`,{className:`inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold bg-rose-50 text-rose-800 border border-rose-300`,children:[e,d&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(`nemesisPatterns`,e),className:`hover:text-red-700 ml-0.5 cursor-pointer`,title:`Forget nemesis`,children:(0,M.jsx)(b,{className:`w-3 h-3`})})]},e))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Aurelia tracks patterns that give you trouble to help you prepare targeted drills.`})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsx)(`div`,{className:`text-xs font-bold text-slate-800`,children:(0,M.jsxs)(`span`,{children:[`Personal Notes & Shared Lore (`,r?.personalNotes?.length||0,`)`]})}),r?.personalNotes&&r.personalNotes.length>0?(0,M.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.personalNotes.map(e=>(0,M.jsxs)(`div`,{className:`flex items-start justify-between gap-2 p-2 bg-slate-50 border border-slate-200 rounded text-[11px] text-slate-700`,children:[(0,M.jsxs)(`span`,{children:[`• `,e]}),d&&(0,M.jsx)(`button`,{type:`button`,onClick:()=>d(`personalNotes`,e),className:`text-slate-400 hover:text-red-600 shrink-0 cursor-pointer p-0.5`,title:`Forget note`,children:(0,M.jsx)(l,{className:`w-3 h-3`})})]},e))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`Share your background or routine with Aurelia and she will hold it in her memory.`})]}),a&&a.length>0&&(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,M.jsx)(`span`,{className:`text-xs font-bold text-slate-800`,children:`Episodic Memory Chain (EM-LLM)`}),(0,M.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[a.length,` events`]})]}),(0,M.jsx)(`div`,{className:`flex flex-col gap-2 max-h-40 overflow-y-auto custom-scrollbar`,children:a.slice(0,8).map(e=>(0,M.jsxs)(`div`,{className:`text-[11px] p-2 bg-[#FFFDF0] border border-amber-900/15 rounded flex flex-col gap-0.5`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsx)(`span`,{className:`font-bold text-ink-black uppercase text-[9px] px-1.5 py-0.5 bg-amber-200/60 rounded`,children:e.eventType.replace(`_`,` `)}),(0,M.jsx)(`span`,{className:`text-[10px] text-slate-400`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})})]}),(0,M.jsx)(`div`,{className:`font-bold text-slate-800 mt-0.5`,children:e.title}),(0,M.jsx)(`div`,{className:`text-slate-600 text-[10px]`,children:e.description})]},e.id))})]}),(0,M.jsxs)(`div`,{className:`bg-white border-[1.5px] border-ink-black rounded-lg p-3 shadow-xs flex flex-col gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-100 pb-1`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-bold text-indigo-900`,children:[(0,M.jsx)(i,{className:`w-3.5 h-3.5 text-amber-500`}),(0,M.jsx)(`span`,{children:`Autonomous Enchantment Telemetry`})]}),(0,M.jsxs)(`span`,{className:`text-[10px] text-slate-400 font-mono`,children:[c?.length||0,` executed`]})]}),c&&c.length>0?(0,M.jsx)(`div`,{className:`flex flex-col gap-1.5 max-h-36 overflow-y-auto custom-scrollbar`,children:c.slice(0,10).map((e,t)=>(0,M.jsxs)(`div`,{className:`text-[11px] p-2 bg-indigo-50/50 border border-indigo-100 rounded flex items-center justify-between gap-2`,children:[(0,M.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,M.jsxs)(`span`,{className:`font-bold text-indigo-950 font-mono text-[10px] truncate`,children:[e.tool_name,`()`]}),e.args&&Object.keys(e.args).length>0&&(0,M.jsx)(`span`,{className:`text-[9px] text-slate-500 truncate`,children:JSON.stringify(e.args).slice(0,50)})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[e.execution_time_ms!==void 0&&(0,M.jsxs)(`span`,{className:`text-[9px] text-slate-400 flex items-center gap-0.5 font-mono`,children:[(0,M.jsx)(w,{className:`w-2.5 h-2.5`}),e.execution_time_ms,`ms`]}),(0,M.jsx)(`span`,{className:`px-1.5 py-0.2 text-[9px] font-bold rounded ${e.success?`bg-emerald-100 text-emerald-800`:`bg-rose-100 text-rose-800`}`,children:e.success?`SUCCESS`:`ERR`})]})]},t))}):(0,M.jsx)(`p`,{className:`text-[11px] text-slate-400 italic m-0`,children:`No autonomous enchantments executed yet in this session.`})]})]})]}),(0,M.jsx)(`div`,{className:`bg-white border-t border-slate-200 px-4 py-2 flex items-center justify-end shrink-0`,children:(0,M.jsx)(`button`,{type:`button`,onClick:f,className:`px-4 py-1.5 bg-white hover:bg-slate-100 border-[1.5px] border-ink-black rounded font-bold text-xs text-ink-black cursor-pointer shadow-xs active:translate-y-0.5`,children:`Close`})})]})})}var z=n({default:()=>B});function B(){let e=h(),[t,n]=(0,k.useState)(_()),[r,i]=(0,k.useState)(!1),[o,s]=(0,k.useState)(!1),[l,u]=(0,k.useState)(!1);(0,k.useEffect)(()=>{S.syncWithBackend(),S.triggerProactiveGreeting()},[]);let d=()=>{let e=!t;n(e),m(e)},p=()=>{window.confirm(`Clear conversation transcript with Princess Aurelia?`)&&S.clearTranscript()},g=(0,k.useCallback)(e=>{S.setIsTyping(e)},[]),y=(0,k.useMemo)(()=>[...e.transcript].reverse().find(e=>e.sender===`princess`)||e.transcript[0],[e.transcript]);return(0,M.jsxs)(`div`,{className:`relative w-full h-full bg-gradient-to-b from-[#FFFDF0] via-[#FFF9E6] to-[#FFF3CD] flex flex-col select-none font-sans text-ink-black overflow-hidden`,children:[(0,M.jsxs)(`div`,{className:`h-12 bg-white/95 backdrop-blur-sm border-b-[3px] border-ink-black px-3 sm:px-4 flex items-center justify-between gap-2 shrink-0 shadow-sm z-20`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,M.jsx)(v,{className:`w-4 h-4 text-amber-500 shrink-0`}),(0,M.jsx)(`h3`,{className:`font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0 truncate`,children:e.companionSettings.name||`Princess Aurelia`})]}),(0,M.jsx)(`span`,{className:`hidden sm:inline-flex px-2 py-0.5 rounded-full bg-amber-100 border border-amber-300 text-[10px] font-bold text-amber-900 shadow-inner shrink-0`,children:e.bondTier}),(0,M.jsx)(`span`,{className:`hidden md:inline-flex px-2 py-0.5 rounded-full bg-indigo-50 border border-indigo-200 text-[10px] font-bold text-indigo-800 shrink-0`,children:e.currentRhythm.toUpperCase()})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:()=>i(!0),className:`px-2.5 py-1 bg-amber-100 hover:bg-amber-200 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5`,title:`View Spire Journey Progress`,children:[(0,M.jsx)(C,{className:`w-3.5 h-3.5 text-indigo-700`}),(0,M.jsxs)(`span`,{className:`font-arcade text-[9px] text-indigo-950`,children:[e.currentFloor,`/150 LC`]})]}),(0,M.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`px-2.5 py-1 bg-white hover:bg-amber-50 border-[2px] border-ink-black rounded font-bold text-[11px] text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all flex items-center gap-1.5`,title:`Open Royal Satchel (Missives & Diary)`,children:[(0,M.jsx)(E,{className:`w-3.5 h-3.5 text-amber-700`}),(0,M.jsx)(`span`,{className:`hidden md:inline`,children:`Satchel`}),e.unlockedLetters.length>0&&(0,M.jsx)(`span`,{className:`w-4 h-4 rounded-full bg-amber-400 text-ink-black text-[9px] font-extrabold flex items-center justify-center border border-ink-black`,children:e.unlockedLetters.length})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(!0),className:`p-1.5 bg-white hover:bg-slate-100 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all`,title:`View Transcript History`,children:(0,M.jsx)(T,{className:`w-3.5 h-3.5 text-slate-700`})}),(0,M.jsx)(`button`,{type:`button`,onClick:d,className:`p-1.5 border-[2px] border-ink-black rounded text-ink-black cursor-pointer shadow-[1.5px_1.5px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all ${t?`bg-slate-200 opacity-80`:`bg-[#FFE24C] hover:bg-yellow-300`}`,title:t?`Unmute Audio`:`Mute Audio`,children:t?(0,M.jsx)(f,{className:`w-3.5 h-3.5`}):(0,M.jsx)(a,{className:`w-3.5 h-3.5`})})]})]}),(0,M.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-start gap-3 sm:gap-4 p-3 sm:p-5 overflow-y-auto custom-scrollbar min-h-0 relative`,children:[(0,M.jsx)(N,{emotion:e.activeEmotion,floor:e.currentFloor,rhythm:e.currentRhythm,activity:e.currentActivity,isLoading:e.isLoading}),(0,M.jsx)(P,{text:y?.text||`I believe in you, champion!`,characterName:e.companionSettings.name,emotion:e.activeEmotion,isLoading:e.isLoading,isStreaming:y?.isStreaming,toolCalls:y?.toolCalls,onTypingStatusChange:g})]}),(0,M.jsx)(I,{suggestions:y?.choiceSuggestions,isLoading:e.isLoading,onSendMessage:e=>S.sendMessage(e),placeholder:`Speak with ${e.companionSettings.name||`Princess Aurelia`}...`}),r&&(0,M.jsx)(L,{currentFloor:e.currentFloor,totalSolved:e.totalSolved,onClose:()=>i(!1)}),o&&(0,M.jsx)(R,{unlockedLetters:e.unlockedLetters,spireChronicles:e.spireChronicles,currentFloor:e.currentFloor,heroCodex:e.heroCodex,episodicEvents:e.episodicEvents,recentToolTelemetry:e.recentToolTelemetry,onRemoveCodexItem:S.removeCodexItem,onClose:()=>s(!1)}),l&&(0,M.jsx)(`div`,{className:`absolute inset-0 z-50 bg-ink-black/40 backdrop-blur-xs flex items-center justify-center p-3 sm:p-4 animate-in fade-in duration-200`,onClick:()=>u(!1),children:(0,M.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black rounded-xl max-w-lg w-full h-[80%] max-h-[520px] shadow-[6px_6px_0px_0px_#1E293B] flex flex-col overflow-hidden`,onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`bg-white border-b-[2px] border-ink-black px-4 py-2.5 flex items-center justify-between shrink-0`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(T,{className:`w-4 h-4 text-ink-black`}),(0,M.jsxs)(`h4`,{className:`font-headline-md font-bold text-xs sm:text-sm text-ink-black m-0`,children:[`Dialogue Transcript (`,e.transcript.length,` turns)`]})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,M.jsxs)(`button`,{type:`button`,onClick:p,className:`p-1 hover:bg-rose-100 text-rose-700 rounded text-[11px] font-bold flex items-center gap-1 cursor-pointer mr-1`,title:`Clear Chat History`,children:[(0,M.jsx)(c,{className:`w-3.5 h-3.5`}),(0,M.jsx)(`span`,{children:`Clear`})]}),(0,M.jsx)(`button`,{type:`button`,onClick:()=>u(!1),className:`p-1 hover:bg-slate-200 rounded text-slate-700 cursor-pointer`,title:`Close`,children:(0,M.jsx)(b,{className:`w-4 h-4`})})]})]}),(0,M.jsx)(`div`,{className:`flex-1 p-3 sm:p-4 overflow-y-auto custom-scrollbar flex flex-col gap-2.5`,children:e.transcript.map((t,n)=>(0,M.jsxs)(`div`,{className:`p-2.5 rounded-lg border-[2px] border-ink-black shadow-[2px_2px_0px_0px_#1E293B] max-w-[90%] ${t.sender===`princess`?`bg-white text-ink-black self-start`:`bg-[#FFE24C] text-ink-black self-end`}`,children:[(0,M.jsx)(`div`,{className:`text-[10px] font-bold font-headline-md mb-1 text-slate-600`,children:t.sender===`princess`?e.companionSettings.name:`Hero`}),(0,M.jsx)(`p`,{className:`text-xs font-medium m-0 leading-relaxed whitespace-pre-wrap select-text`,children:t.text})]},t.id||n))})]})})]})}export{z as t};
 
 
algospaced-ui/dist/assets/{PythonChallenge-Bfcp7_2V.js → PythonChallenge-3lpSHvfF.js} RENAMED
@@ -1,4 +1,4 @@
1
- import{a as e,c as t,i as n,t as r}from"./jsx-runtime-j9uSgrFF.js";import"./index-g5jVBiGr.js";var i=t(e(),1),a=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15<s.length?s.slice(a,a+15)+`…`:s.slice(a);r+=l+c+u}super(r),this.name=`ParseError`,this.position=void 0,this.length=void 0,this.rawMessage=void 0,Object.setPrototypeOf(this,e.prototype),this.position=i,i!=null&&a!=null&&(this.length=a-i),this.rawMessage=t}},o=/([A-Z])/g,s=e=>e.replace(o,`-$1`).toLowerCase(),c={"&":`&amp;`,">":`&gt;`,"<":`&lt;`,'"':`&quot;`,"'":`&#x27;`},l=/[&><"']/g,u=e=>String(e).replace(l,e=>c[e]),d=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?d(e.body[0]):e:e.type===`font`?d(e.body):e,f=new Set([`mathord`,`textord`,`atom`]),p=e=>f.has(d(e).type),m=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},h={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format <type>`},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color <color>`,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro <def>`,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness <size>`,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size <n>`,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand <n>`,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function g(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function _(e){return Object.prototype.hasOwnProperty.call(e,`default`)&&e.default!==void 0?e.default:g(Array.isArray(e.type)?e.type[0]:e.type)}function v(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,a=Object.prototype.hasOwnProperty.call(r,`processor`)?r.processor:void 0;e[t]=i===void 0?_(r):a?a(i):i}var y=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(h)){var n=h[t];n&&v(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),r&&r!==`ignore`){if(r===!0||r===`error`)throw new a(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=m(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},b=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return ne[re[this.id]]}sub(){return ne[ie[this.id]]}fracNum(){return ne[ae[this.id]]}fracDen(){return ne[oe[this.id]]}cramp(){return ne[se[this.id]]}text(){return ne[ce[this.id]]}isTight(){return this.size>=2}},x=0,S=1,C=2,w=3,ee=4,T=5,te=6,E=7,ne=[new b(x,0,!1),new b(S,0,!0),new b(C,1,!1),new b(w,1,!0),new b(ee,2,!1),new b(T,2,!0),new b(te,3,!1),new b(E,3,!0)],re=[ee,T,ee,T,te,E,te,E],ie=[T,T,T,T,E,E,E,E],ae=[C,w,ee,T,te,E,te,E],oe=[w,w,T,T,E,E,E,E],se=[S,S,w,w,T,T,E,E],ce=[x,S,C,w,C,w,C,w],D={DISPLAY:ne[x],TEXT:ne[C],SCRIPT:ne[ee],SCRIPTSCRIPT:ne[te]},le=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function ue(e){for(var t=0;t<le.length;t++)for(var n=le[t],r=0;r<n.blocks.length;r++){var i=n.blocks[r];if(e>=i[0]&&e<=i[1])return n.name}return null}var de=[];le.forEach(e=>e.blocks.forEach(e=>de.push(...e)));function fe(e){for(var t=0;t<de.length;t+=2)if(e>=de[t]&&e<=de[t+1])return!0;return!1}var pe=e=>e+` `+e,me=80,he=function(e,t){return`M95,`+(622+e+t)+`
2
  c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
3
  c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54
4
  c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10
 
1
+ import{a as e,c as t,i as n,t as r}from"./jsx-runtime-j9uSgrFF.js";import"./index-V2pPJO9M.js";var i=t(e(),1),a=class e extends Error{constructor(t,n){var r=`KaTeX parse error: `+t,i,a,o=n&&n.loc;if(o&&o.start<=o.end){var s=o.lexer.input;i=o.start,a=o.end,i===s.length?r+=` at end of input: `:r+=` at position `+(i+1)+`: `;var c=s.slice(i,a).replace(/[^]/g,`$&̲`),l=i>15?`…`+s.slice(i-15,i):s.slice(0,i),u=a+15<s.length?s.slice(a,a+15)+`…`:s.slice(a);r+=l+c+u}super(r),this.name=`ParseError`,this.position=void 0,this.length=void 0,this.rawMessage=void 0,Object.setPrototypeOf(this,e.prototype),this.position=i,i!=null&&a!=null&&(this.length=a-i),this.rawMessage=t}},o=/([A-Z])/g,s=e=>e.replace(o,`-$1`).toLowerCase(),c={"&":`&amp;`,">":`&gt;`,"<":`&lt;`,'"':`&quot;`,"'":`&#x27;`},l=/[&><"']/g,u=e=>String(e).replace(l,e=>c[e]),d=e=>e.type===`ordgroup`||e.type===`color`?e.body.length===1?d(e.body[0]):e:e.type===`font`?d(e.body):e,f=new Set([`mathord`,`textord`,`atom`]),p=e=>f.has(d(e).type),m=e=>{var t=/^[\x00-\x20]*([^\\/#?]*?)(:|&#0*58|&#x0*3a|&colon)/i.exec(e);return t?t[2]!==`:`||!/^[a-zA-Z][a-zA-Z0-9+\-.]*$/.test(t[1])?null:t[1].toLowerCase():`_relative`},h={displayMode:{type:`boolean`,description:`Render math in display mode, which puts the math in display style (so \\int and \\sum are large, for example), and centers the math on the page on its own line.`,cli:`-d, --display-mode`},output:{type:{enum:[`htmlAndMathml`,`html`,`mathml`]},description:`Determines the markup language of the output.`,cli:`-F, --format <type>`},leqno:{type:`boolean`,description:`Render display math in leqno style (left-justified tags).`},fleqn:{type:`boolean`,description:`Render display math flush left.`},throwOnError:{type:`boolean`,default:!0,cli:`-t, --no-throw-on-error`,cliDescription:`Render errors (in the color given by --error-color) instead of throwing a ParseError exception when encountering an error.`},errorColor:{type:`string`,default:`#cc0000`,cli:`-c, --error-color <color>`,cliDescription:`A color string given in the format 'rgb' or 'rrggbb' (no #). This option determines the color of errors rendered by the -t option.`,cliProcessor:e=>`#`+e},macros:{type:`object`,cli:`-m, --macro <def>`,cliDescription:`Define custom macro of the form '\\foo:expansion' (use multiple -m arguments for multiple macros).`,cliDefault:[],cliProcessor:(e,t)=>(t.push(e),t)},minRuleThickness:{type:`number`,description:"Specifies a minimum thickness, in ems, for fraction lines, `\\sqrt` top lines, `{array}` vertical lines, `\\hline`, `\\hdashline`, `\\underline`, `\\overline`, and the borders of `\\fbox`, `\\boxed`, and `\\fcolorbox`.",processor:e=>Math.max(0,e),cli:`--min-rule-thickness <size>`,cliProcessor:parseFloat},colorIsTextColor:{type:`boolean`,description:`Makes \\color behave like LaTeX's 2-argument \\textcolor, instead of LaTeX's one-argument \\color mode change.`,cli:`-b, --color-is-text-color`},strict:{type:[{enum:[`warn`,`ignore`,`error`]},`boolean`,`function`],description:`Turn on strict / LaTeX faithfulness mode, which throws an error if the input uses features that are not supported by LaTeX.`,cli:`-S, --strict`,cliDefault:!1},trust:{type:[`boolean`,`function`],description:`Trust the input, enabling all HTML features such as \\url.`,cli:`-T, --trust`},maxSize:{type:`number`,default:1/0,description:`If non-zero, all user-specified sizes, e.g. in \\rule{500em}{500em}, will be capped to maxSize ems. Otherwise, elements and spaces can be arbitrarily large`,processor:e=>Math.max(0,e),cli:`-s, --max-size <n>`,cliProcessor:parseInt},maxExpand:{type:`number`,default:1e3,description:`Limit the number of macro expansions to the specified number, to prevent e.g. infinite macro loops. If set to Infinity, the macro expander will try to fully expand as in LaTeX.`,processor:e=>Math.max(0,e),cli:`-e, --max-expand <n>`,cliProcessor:e=>e===`Infinity`?1/0:parseInt(e)},globalGroup:{type:`boolean`,cli:!1}};function g(e){if(typeof e!=`string`)return e.enum[0];switch(e){case`boolean`:return!1;case`string`:return``;case`number`:return 0;case`object`:return{};default:throw Error(`Unexpected schema type; settings must declare an explicit default.`)}}function _(e){return Object.prototype.hasOwnProperty.call(e,`default`)&&e.default!==void 0?e.default:g(Array.isArray(e.type)?e.type[0]:e.type)}function v(e,t,n,r){var i=Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0,a=Object.prototype.hasOwnProperty.call(r,`processor`)?r.processor:void 0;e[t]=i===void 0?_(r):a?a(i):i}var y=class{constructor(e){e===void 0&&(e={}),this.displayMode=void 0,this.output=void 0,this.leqno=void 0,this.fleqn=void 0,this.throwOnError=void 0,this.errorColor=void 0,this.macros=void 0,this.minRuleThickness=void 0,this.colorIsTextColor=void 0,this.strict=void 0,this.trust=void 0,this.maxSize=void 0,this.maxExpand=void 0,this.globalGroup=void 0,e||={};for(var t of Object.keys(h)){var n=h[t];n&&v(this,t,e,n)}}reportNonstrict(e,t,n){var r=this.strict;if(typeof r==`function`&&(r=r(e,t,n)),r&&r!==`ignore`){if(r===!0||r===`error`)throw new a(`LaTeX-incompatible input and strict mode is set to 'error': `+(t+` [`+e+`]`),n);r===`warn`?typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)):typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`))}}useStrictBehavior(e,t,n){var r=this.strict;if(typeof r==`function`)try{r=r(e,t,n)}catch{r=`error`}return!r||r===`ignore`?!1:r===!0||r===`error`?!0:r===`warn`?(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to 'warn': `+(t+` [`+e+`]`)),!1):(typeof console<`u`&&console.warn(`LaTeX-incompatible input and strict mode is set to `+(`unrecognized '`+r+`': `+t+` [`+e+`]`)),!1)}isTrusted(e){if(`url`in e&&e.url&&!e.protocol){var t=m(e.url);if(t==null)return!1;e.protocol=t}return!!(typeof this.trust==`function`?this.trust(e):this.trust)}},b=class{constructor(e,t,n){this.id=void 0,this.size=void 0,this.cramped=void 0,this.id=e,this.size=t,this.cramped=n}sup(){return ne[re[this.id]]}sub(){return ne[ie[this.id]]}fracNum(){return ne[ae[this.id]]}fracDen(){return ne[oe[this.id]]}cramp(){return ne[se[this.id]]}text(){return ne[ce[this.id]]}isTight(){return this.size>=2}},x=0,S=1,C=2,w=3,ee=4,T=5,te=6,E=7,ne=[new b(x,0,!1),new b(S,0,!0),new b(C,1,!1),new b(w,1,!0),new b(ee,2,!1),new b(T,2,!0),new b(te,3,!1),new b(E,3,!0)],re=[ee,T,ee,T,te,E,te,E],ie=[T,T,T,T,E,E,E,E],ae=[C,w,ee,T,te,E,te,E],oe=[w,w,T,T,E,E,E,E],se=[S,S,w,w,T,T,E,E],ce=[x,S,C,w,C,w,C,w],D={DISPLAY:ne[x],TEXT:ne[C],SCRIPT:ne[ee],SCRIPTSCRIPT:ne[te]},le=[{name:`latin`,blocks:[[256,591],[768,879]]},{name:`cyrillic`,blocks:[[1024,1279]]},{name:`armenian`,blocks:[[1328,1423]]},{name:`brahmic`,blocks:[[2304,4255]]},{name:`georgian`,blocks:[[4256,4351]]},{name:`cjk`,blocks:[[12288,12543],[19968,40879],[65280,65376]]},{name:`hangul`,blocks:[[44032,55215]]}];function ue(e){for(var t=0;t<le.length;t++)for(var n=le[t],r=0;r<n.blocks.length;r++){var i=n.blocks[r];if(e>=i[0]&&e<=i[1])return n.name}return null}var de=[];le.forEach(e=>e.blocks.forEach(e=>de.push(...e)));function fe(e){for(var t=0;t<de.length;t+=2)if(e>=de[t]&&e<=de[t+1])return!0;return!1}var pe=e=>e+` `+e,me=80,he=function(e,t){return`M95,`+(622+e+t)+`
2
  c-2.7,0,-7.17,-2.7,-13.5,-8c-5.8,-5.3,-9.5,-10,-9.5,-14
3
  c0,-2,0.3,-3.3,1,-4c1.3,-2.7,23.83,-20.7,67.5,-54
4
  c44.2,-33.3,65.8,-50.3,66.5,-51c1.3,-1.3,3,-2,5,-2c4.7,0,8.7,3.3,12,10
algospaced-ui/dist/assets/ReviewQueue-BCTxdw81.js DELETED
The diff for this file is too large to render. See raw diff
 
algospaced-ui/dist/assets/ReviewQueue-CYwGYMOV.js ADDED
The diff for this file is too large to render. See raw diff
 
algospaced-ui/dist/assets/Settings-C3gzd0DF.js ADDED
@@ -0,0 +1 @@
 
 
1
+ import{a as e,c as t,t as n}from"./jsx-runtime-j9uSgrFF.js";import{t as r}from"./circle-alert-BL6bvZTM.js";import{t as i}from"./external-link-BGZfX5Bi.js";import{a,d as ee,f as o,i as s,n as c,r as l,s as u,t as d,u as f}from"./githubSyncService-CsqBgIfT.js";import{t as p}from"./info-CAmdZoA6.js";import{t as m}from"./save-BgzMM0iu.js";import{F as h,G as g,M as _,P as v,R as y,T as b,f as x,g as S,h as C,j as te,k as ne,m as w,p as T,y as E,z as D}from"./index-V2pPJO9M.js";var O=g(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),k=g(`key`,[[`path`,{d:`m2 21 9.6-9.6`,key:`9l79m3`}],[`path`,{d:`m7.5 15.5 2.3 2.3a1 1 0 0 1 0 1.4l-2.1 2.1a1 1 0 0 1-1.4 0L4 19`,key:`fw8biw`}],[`circle`,{cx:`15.5`,cy:`7.5`,r:`5.5`,key:`4wxmhb`}]]),A=t(e(),1),j=n(),M=[{id:`default`,name:`Default`,desc:`Subject to Availability`},{id:`groq`,name:`Groq`,badge:`Fastest`,desc:`Llama 3.3 & Qwen`,keyPrefix:`gsk_...`,portalUrl:`https://console.groq.com/keys`},{id:`gemini`,name:`Google Gemini`,desc:`Gemini 2.5 / 3.5`,keyPrefix:`AIzaSy...`,portalUrl:`https://aistudio.google.com/app/apikey`},{id:`openrouter`,name:`OpenRouter`,desc:`Multi-Provider`,keyPrefix:`sk-or-v1-...`,portalUrl:`https://openrouter.ai/keys`}];function N(){let[e,t]=(0,A.useState)(()=>localStorage.getItem(`algospaced_custom_ai_provider`)||`default`),[n,g]=(0,A.useState)(()=>localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``),[N,re]=(0,A.useState)(!1),[P,F]=(0,A.useState)(null),[I,L]=(0,A.useState)(()=>x()),[R,z]=(0,A.useState)(null),[B,V]=(0,A.useState)(()=>T().currentFloor),[H,U]=(0,A.useState)(()=>l()),[W,G]=(0,A.useState)(()=>s()),[K,q]=(0,A.useState)(!1),[J,Y]=(0,A.useState)(null),X=!!(H.token&&(H.username||W?.login)),Z=!!(n.trim()&&e!=="default"),Q=e!=="default"&&!n.trim(),$=M.find(t=>t.id===e),ie=e=>{t(e),localStorage.setItem(`algospaced_custom_ai_provider`,e),F(e==="default"?{type:`info`,text:`Switched to Server Default (Shared Pool).`}:{type:`info`,text:`Switched to ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3)},ae=()=>{let t=n.trim();if(!t){F({type:`error`,text:`Please enter an API key for ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3);return}localStorage.setItem(`algospaced_custom_api_key`,t),localStorage.setItem(`sandbox_gemini_api_key`,t),localStorage.setItem(`algospaced_custom_ai_provider`,e),F({type:`success`,text:`${e.toUpperCase()} API key saved successfully.`}),setTimeout(()=>F(null),3e3)},oe=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),g(``),F({type:`info`,text:`Cleared custom API key.`}),setTimeout(()=>F(null),3e3)},se=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),localStorage.setItem(`algospaced_custom_ai_provider`,`default`),g(``),t(`default`),F({type:`info`,text:`Reset to Server Default provider.`}),setTimeout(()=>F(null),3e3)},ce=()=>{C(I),z({type:`success`,text:`Princess Companion settings saved!`}),setTimeout(()=>z(null),3e3)},le=()=>{L(S),C(S),z({type:`info`,text:`Reset companion to default settings.`}),setTimeout(()=>z(null),3e3)},ue=()=>{if(window.confirm(`Are you sure you want to reset your Spire Journey progress back to 0 problems?`)){let e=w();V(e.currentFloor),z({type:`info`,text:`Spire journey progress reset to 0 problems.`}),setTimeout(()=>z(null),3e3)}},de=async()=>{q(!0),Y(null);try{let{token:e,user:t}=await c();G(t);let n=l();U(n);try{await a(e,n.repoName,n.isPrivate)}catch{}Y({type:`success`,text:`Connected to GitHub as @${t.login}!`}),setTimeout(()=>Y(null),4e3)}catch(e){Y({type:`error`,text:e.message||`GitHub connection failed.`}),setTimeout(()=>Y(null),5e3)}finally{q(!1)}},fe=()=>{d(),U(l()),G(null),Y({type:`info`,text:`Disconnected from GitHub.`}),setTimeout(()=>Y(null),3e3)},pe=e=>{u({autoCommit:e}),U(t=>({...t,autoCommit:e})),Y({type:`info`,text:e?`Auto-commit enabled for review submissions.`:`Auto-commit disabled.`}),setTimeout(()=>Y(null),3e3)};return(0,j.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-5 sm:p-6 flex flex-col gap-4 select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-0.5 border-b-[3px] border-ink-black pb-2.5`,children:[(0,j.jsxs)(`h3`,{className:`font-headline-md font-bold text-sm m-0 flex items-center gap-2 tracking-wide`,children:[(0,j.jsx)(k,{className:`w-4 h-4 text-ink-black`}),`API & AI Configuration`]}),(0,j.jsx)(`p`,{className:`text-[11px] text-trash-gray font-medium m-0`,children:`Configure your AI model provider..`})]}),(0,j.jsx)(`div`,{className:`px-4 py-3 border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] transition-all ${Z?`bg-emerald-50`:Q?`bg-rose-50`:`bg-amber-50/70`}`,children:(0,j.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[Z?(0,j.jsx)(b,{className:`w-4 h-4 text-emerald-600 shrink-0`}):Q?(0,j.jsx)(r,{className:`w-4 h-4 text-rose-600 shrink-0`}):(0,j.jsx)(O,{className:`w-4 h-4 text-amber-600 shrink-0`}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:`text-xs font-bold font-headline-md text-ink-black flex items-center gap-1.5`,children:(0,j.jsxs)(`span`,{children:[`Active:`,` `,Z?`${e.toUpperCase()} (Custom Key)`:Q?`${e.toUpperCase()} (Key Required)`:`Default`]})}),(0,j.jsx)(`div`,{className:`text-[10px] text-trash-gray font-medium`,children:Z?`Requests are routed directly through your personal API key.`:Q?`Enter your API key below to activate this provider.`:`Using basic, free built-in developer keys with auto-failover.`})]})]}),(0,j.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${Z?`bg-emerald-300 text-emerald-950`:Q?`bg-rose-300 text-rose-950`:`bg-amber-200 text-amber-950`}`,children:Z?`ACTIVE`:Q?`NEEDS KEY`:`LIMITED`})]})}),(0,j.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider mb-2 font-headline-md flex items-center gap-1.5`,children:[(0,j.jsx)(O,{className:`w-3.5 h-3.5 text-ink-black`}),`Select Provider`]}),(0,j.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:M.map(t=>{let n=e===t.id;return(0,j.jsxs)(`button`,{type:`button`,onClick:()=>ie(t.id),className:`p-2.5 border-[2px] text-left transition-all cursor-pointer flex flex-col justify-between rounded ${n?`border-ink-black bg-[#ffe24c] shadow-[2px_2px_0px_0px_#1E293B] font-bold`:`border-slate-300 bg-slate-50 hover:bg-slate-100 text-slate-700`}`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,j.jsx)(`span`,{className:`text-xs font-bold font-headline-md`,children:t.name}),t.badge&&(0,j.jsx)(`span`,{className:`text-[8px] font-bold uppercase px-1 py-0.2 bg-orange-100 text-orange-700 rounded border border-orange-300`,children:t.badge})]}),(0,j.jsx)(`span`,{className:`text-[9px] mt-1 text-slate-600 leading-tight block`,children:t.desc})]},t.id)})})]}),e==="default"?(0,j.jsxs)(`div`,{className:`p-3.5 bg-slate-50 border border-slate-200 rounded flex items-start gap-3`,children:[(0,j.jsx)(ne,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs text-slate-700`,children:[(0,j.jsxs)(`span`,{className:`font-bold text-ink-black`,children:[`Shared Quotas (`,(0,j.jsx)(`i`,{children:`limited`}),`)`]}),(0,j.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0 leading-relaxed`,children:`Powered by shared, basic developer keys. Because limits are shared with everyone, requests may fail. Use your own provider keys above for stable performance.`})]})]}):(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1.5`,children:[(0,j.jsx)(k,{className:`w-3.5 h-3.5 text-ink-black`}),$?.name,` API Key`]}),$?.portalUrl&&(0,j.jsxs)(`a`,{href:$.portalUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-[10px] text-sky-600 hover:text-sky-800 font-medium flex items-center gap-1 no-underline`,children:[(0,j.jsx)(`span`,{children:`Get API Key`}),(0,j.jsx)(i,{className:`w-3 h-3`})]})]}),(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`input`,{type:N?`text`:`password`,value:n,onChange:e=>g(e.target.value),placeholder:`Enter ${$?.keyPrefix||`API Key`}`,className:`w-full bg-white border-[2px] border-ink-black rounded py-2 pl-3 pr-9 text-ink-black placeholder-slate-400 focus:outline-none focus:border-sky-600 text-xs font-code-mono`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>re(!N),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-trash-gray hover:text-ink-black cursor-pointer bg-transparent border-0 outline-none p-1`,title:N?`Hide API key`:`Show API key`,children:N?(0,j.jsx)(o,{className:`w-3.5 h-3.5`}):(0,j.jsx)(ee,{className:`w-3.5 h-3.5`})})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-trash-gray font-medium`,children:[(0,j.jsx)(_,{className:`w-3.5 h-3.5 text-emerald-600 shrink-0`}),(0,j.jsx)(`span`,{children:`Stored locally in your browser. Sent directly via request headers.`})]}),(0,j.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,j.jsxs)(`button`,{onClick:ae,className:`flex-1 flex items-center justify-center gap-1.5 py-2 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,j.jsx)(m,{className:`w-3.5 h-3.5`}),`Save Key`]}),n&&(0,j.jsx)(`button`,{onClick:oe,className:`px-3 py-2 border-[2px] border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 hover:text-rose-600 shadow-[2px_2px_0px_0px_rgba(0,0,0,0.05)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:`Clear Key`})]})]}),P&&(0,j.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${P.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:P.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[P.type===`success`?(0,j.jsx)(D,{className:`w-3.5 h-3.5 shrink-0`}):P.type===`error`?(0,j.jsx)(r,{className:`w-3.5 h-3.5 shrink-0`}):(0,j.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}),P.text]}),e!=="default"&&(0,j.jsx)(`div`,{className:`pt-2 border-t border-slate-200 flex justify-end`,children:(0,j.jsxs)(`button`,{onClick:se,className:`flex items-center gap-1.5 py-1.5 px-3 border border-slate-300 bg-slate-50 hover:bg-slate-100 text-[11px] font-bold text-slate-600 hover:text-ink-black transition-all cursor-pointer rounded`,children:[(0,j.jsx)(v,{className:`w-3 h-3 text-slate-500`}),`Reset to Server Default`]})})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,j.jsx)(`div`,{className:`w-8 h-8 rounded bg-[#24292e] border-[2px] border-ink-black flex items-center justify-center text-white shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,j.jsx)(f,{className:`w-4 h-4 text-white`})}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0 flex items-center gap-2`,children:`GitHub Solutions Sync & Auto-Commit`}),(0,j.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Sync solutions to personal GitHub repository and commit automatically on submission`})]})]}),(0,j.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${X?`bg-emerald-300 text-emerald-950`:`bg-slate-200 text-slate-800`}`,children:X?`CONNECTED`:`DISCONNECTED`})]}),X?(0,j.jsxs)(`div`,{className:`space-y-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-3 bg-slate-50 border border-slate-200 rounded`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[W?.avatar_url&&(0,j.jsx)(`img`,{src:W.avatar_url,alt:W.login,className:`w-7 h-7 rounded-full border border-ink-black`}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`span`,{className:`text-xs font-bold text-ink-black`,children:[`@`,W?.login||H.username]}),(0,j.jsxs)(`span`,{className:`text-[11px] text-slate-600 font-mono block`,children:[H.username,`/`,H.repoName,` (`,H.branch,`)`]})]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`a`,{href:`https://github.com/${H.username}/${H.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-slate-100 text-ink-black border border-slate-300 rounded no-underline flex items-center gap-1 cursor-pointer`,children:[(0,j.jsx)(i,{className:`w-3 h-3`}),(0,j.jsx)(`span`,{children:`View Repo`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:fe,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-rose-50 text-rose-700 border border-rose-300 rounded cursor-pointer`,children:`Disconnect`})]})]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-emerald-50/50 border border-emerald-300 rounded cursor-pointer`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:H.autoCommit,onChange:e=>pe(e.target.checked),className:`w-4 h-4 accent-emerald-600 cursor-pointer`}),(0,j.jsxs)(`div`,{className:`text-xs`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,j.jsxs)(`span`,{className:`text-[10px] text-trash-gray`,children:[`Automatically pushes your code to `,H.repoName,` whenever you grade a review card.`]})]})]})]}):(0,j.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 p-3.5 bg-slate-50 border border-slate-200 rounded`,children:[(0,j.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,j.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Connect your GitHub Account (1-Click OAuth)`}),(0,j.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0`,children:`Grant repository access to automatically sync your DSA problem solutions as you study.`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:de,disabled:K,className:`px-4 py-2 bg-[#24292e] hover:bg-black text-white text-xs font-bold uppercase rounded border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none flex items-center gap-2 shrink-0 cursor-pointer disabled:opacity-50`,children:K?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(h,{className:`w-3.5 h-3.5 animate-spin`}),(0,j.jsx)(`span`,{children:`CONNECTING...`})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(f,{className:`w-3.5 h-3.5 text-yellow-300`}),(0,j.jsx)(`span`,{children:`CONNECT GITHUB`})]})})]}),J&&(0,j.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${J.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:J.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[J.type===`success`?(0,j.jsx)(D,{className:`w-3.5 h-3.5 shrink-0`}):J.type===`error`?(0,j.jsx)(r,{className:`w-3.5 h-3.5 shrink-0`}):(0,j.jsx)(p,{className:`w-3.5 h-3.5 shrink-0`}),J.text]})]}),(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`div`,{className:`w-7 h-7 rounded bg-[#FFE24C] border-[2px] border-ink-black flex items-center justify-center shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,j.jsx)(te,{className:`w-4 h-4 text-ink-black`})}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0`,children:`Princess AI Companion & RPG Settings`}),(0,j.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Trapped Princess Persona, Study Break Timer & 8-bit RPG Audio`})]})]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,j.jsx)(`span`,{className:`text-[11px] font-bold text-ink-black font-headline-md uppercase`,children:I.enabled?`Enabled`:`Disabled`}),(0,j.jsx)(`input`,{type:`checkbox`,checked:I.enabled,onChange:e=>L(t=>({...t,enabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`})]})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Companion Name`}),(0,j.jsx)(`input`,{type:`text`,value:I.name,onChange:e=>L(t=>({...t,name:e.target.value})),placeholder:`e.g. Princess Aurelia`,className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1`,children:[(0,j.jsx)(y,{className:`w-3.5 h-3.5 text-amber-700`}),`Study Break Reminder`]}),(0,j.jsxs)(`select`,{value:I.breakIntervalMinutes,onChange:e=>L(t=>({...t,breakIntervalMinutes:Number(e.target.value)})),className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 cursor-pointer`,children:[(0,j.jsx)(`option`,{value:25,children:`Every 25 Minutes (Classic Pomodoro)`}),(0,j.jsx)(`option`,{value:45,children:`Every 45 Minutes`}),(0,j.jsx)(`option`,{value:60,children:`Every 60 Minutes`}),(0,j.jsx)(`option`,{value:0,children:`Disabled (No automatic break popups)`})]})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Princess Backstory & Persona Prompt`}),(0,j.jsx)(`textarea`,{rows:2,value:I.backstory,onChange:e=>L(t=>({...t,backstory:e.target.value})),placeholder:`Describe her background, tone, and connection to your DSA studies...`,className:`bg-white border-[2px] border-ink-black rounded p-2.5 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 resize-y`})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,j.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:I.soundEnabled,onChange:e=>{let t=e.target.checked;L(e=>({...e,soundEnabled:t})),E(!t)},className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,j.jsxs)(`div`,{className:`text-xs`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`8-bit Sound Effects`}),(0,j.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Typewriter blips, chimes & fanfare`})]})]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:I.autoPopupEnabled,onChange:e=>L(t=>({...t,autoPopupEnabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,j.jsxs)(`div`,{className:`text-xs`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Spontaneous RPG Popups`}),(0,j.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Speech bubbles for breaks & milestones`})]})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-slate-200`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:ce,className:`flex items-center gap-1.5 py-2 px-4 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,j.jsx)(m,{className:`w-3.5 h-3.5`}),`Save Companion Settings`]}),(0,j.jsx)(`button`,{type:`button`,onClick:le,className:`py-2 px-3 border border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 transition-all cursor-pointer rounded`,children:`Default Persona`})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:ue,className:`flex items-center gap-1 py-1.5 px-3 border border-rose-300 bg-rose-50 hover:bg-rose-100 text-rose-700 text-[11px] font-bold transition-all cursor-pointer rounded`,children:[(0,j.jsx)(v,{className:`w-3 h-3 text-rose-500`}),(0,j.jsxs)(`span`,{children:[`Reset Journey (`,B,`/150 LC)`]})]})]}),R&&(0,j.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${R.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[(0,j.jsx)(D,{className:`w-3.5 h-3.5 shrink-0`}),R.text]})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-2.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,j.jsx)(p,{className:`w-3.5 h-3.5 text-[#0ea5e9]`}),(0,j.jsx)(`h4`,{className:`text-xs font-bold uppercase font-headline-md m-0`,children:`Get Free API Keys`})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-2 text-[10px]`,children:[(0,j.jsxs)(`a`,{href:`https://console.groq.com/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,j.jsx)(`span`,{children:`Groq Cloud`}),(0,j.jsx)(i,{className:`w-3 h-3 text-slate-400`})]}),(0,j.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Fast inference with generous free rate limits.`})]}),(0,j.jsxs)(`a`,{href:`https://aistudio.google.com/app/apikey`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,j.jsx)(`span`,{children:`Google AI Studio`}),(0,j.jsx)(i,{className:`w-3 h-3 text-slate-400`})]}),(0,j.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Free Gemini Flash API quota.`})]}),(0,j.jsxs)(`a`,{href:`https://openrouter.ai/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,j.jsx)(`span`,{children:`OpenRouter`}),(0,j.jsx)(i,{className:`w-3 h-3 text-slate-400`})]}),(0,j.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Unified API for open-weights models.`})]})]})]})]})}export{N as default};
algospaced-ui/dist/assets/Settings-Cz_GHQn5.js DELETED
@@ -1 +0,0 @@
1
- import{a as e,c as t,t as n}from"./jsx-runtime-j9uSgrFF.js";import{n as r,r as i,t as ee}from"./eye-DeJ_5v51.js";import{t as a}from"./external-link-yb1gedrc.js";import{a as o,i as s,n as te,r as c,s as l,t as u,u as d}from"./githubSyncService--4Z5jmjP.js";import{t as f}from"./info-CU16dSEt.js";import{t as p}from"./save-CdpRk537.js";import{A as m,C as h,D as ne,I as g,L as _,M as v,N as y,U as b,_ as x,d as S,f as C,k as w,m as T,p as E,u as D}from"./index-g5jVBiGr.js";var O=b(`cpu`,[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]),k=b(`key`,[[`path`,{d:`m2 21 9.6-9.6`,key:`9l79m3`}],[`path`,{d:`m7.5 15.5 2.3 2.3a1 1 0 0 1 0 1.4l-2.1 2.1a1 1 0 0 1-1.4 0L4 19`,key:`fw8biw`}],[`circle`,{cx:`15.5`,cy:`7.5`,r:`5.5`,key:`4wxmhb`}]]),A=t(e(),1),j=n(),M=[{id:`default`,name:`Default`,desc:`Subject to Availability`},{id:`groq`,name:`Groq`,badge:`Fastest`,desc:`Llama 3.3 & Qwen`,keyPrefix:`gsk_...`,portalUrl:`https://console.groq.com/keys`},{id:`gemini`,name:`Google Gemini`,desc:`Gemini 2.5 / 3.5`,keyPrefix:`AIzaSy...`,portalUrl:`https://aistudio.google.com/app/apikey`},{id:`openrouter`,name:`OpenRouter`,desc:`Multi-Provider`,keyPrefix:`sk-or-v1-...`,portalUrl:`https://openrouter.ai/keys`}];function N(){let[e,t]=(0,A.useState)(()=>localStorage.getItem(`algospaced_custom_ai_provider`)||`default`),[n,b]=(0,A.useState)(()=>localStorage.getItem(`algospaced_custom_api_key`)||localStorage.getItem(`sandbox_gemini_api_key`)||``),[N,re]=(0,A.useState)(!1),[P,F]=(0,A.useState)(null),[I,L]=(0,A.useState)(()=>D()),[R,z]=(0,A.useState)(null),[B,V]=(0,A.useState)(()=>S().currentFloor),[H,U]=(0,A.useState)(()=>c()),[W,G]=(0,A.useState)(()=>s()),[K,q]=(0,A.useState)(!1),[J,Y]=(0,A.useState)(null),X=!!(H.token&&(H.username||W?.login)),Z=!!(n.trim()&&e!=="default"),Q=e!=="default"&&!n.trim(),$=M.find(t=>t.id===e),ie=e=>{t(e),localStorage.setItem(`algospaced_custom_ai_provider`,e),F(e==="default"?{type:`info`,text:`Switched to Server Default (Shared Pool).`}:{type:`info`,text:`Switched to ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3)},ae=()=>{let t=n.trim();if(!t){F({type:`error`,text:`Please enter an API key for ${e.toUpperCase()}.`}),setTimeout(()=>F(null),3e3);return}localStorage.setItem(`algospaced_custom_api_key`,t),localStorage.setItem(`sandbox_gemini_api_key`,t),localStorage.setItem(`algospaced_custom_ai_provider`,e),F({type:`success`,text:`${e.toUpperCase()} API key saved successfully.`}),setTimeout(()=>F(null),3e3)},oe=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),b(``),F({type:`info`,text:`Cleared custom API key.`}),setTimeout(()=>F(null),3e3)},se=()=>{localStorage.removeItem(`algospaced_custom_api_key`),localStorage.removeItem(`sandbox_gemini_api_key`),localStorage.setItem(`algospaced_custom_ai_provider`,`default`),b(``),t(`default`),F({type:`info`,text:`Reset to Server Default provider.`}),setTimeout(()=>F(null),3e3)},ce=()=>{E(I),z({type:`success`,text:`Princess Companion settings saved!`}),setTimeout(()=>z(null),3e3)},le=()=>{L(T),E(T),z({type:`info`,text:`Reset companion to default settings.`}),setTimeout(()=>z(null),3e3)},ue=()=>{if(window.confirm(`Are you sure you want to reset your Spire Journey progress back to 0 problems?`)){let e=C();V(e.currentFloor),z({type:`info`,text:`Spire journey progress reset to 0 problems.`}),setTimeout(()=>z(null),3e3)}},de=async()=>{q(!0),Y(null);try{let{token:e,user:t}=await te();G(t);let n=c();U(n);try{await o(e,n.repoName,n.isPrivate)}catch{}Y({type:`success`,text:`Connected to GitHub as @${t.login}!`}),setTimeout(()=>Y(null),4e3)}catch(e){Y({type:`error`,text:e.message||`GitHub connection failed.`}),setTimeout(()=>Y(null),5e3)}finally{q(!1)}},fe=()=>{u(),U(c()),G(null),Y({type:`info`,text:`Disconnected from GitHub.`}),setTimeout(()=>Y(null),3e3)},pe=e=>{l({autoCommit:e}),U(t=>({...t,autoCommit:e})),Y({type:`info`,text:e?`Auto-commit enabled for review submissions.`:`Auto-commit disabled.`}),setTimeout(()=>Y(null),3e3)};return(0,j.jsxs)(`div`,{className:`w-full h-full bg-[#fdf8e1] p-5 sm:p-6 flex flex-col gap-4 select-none font-sans text-ink-black overflow-y-auto custom-scrollbar`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-0.5 border-b-[3px] border-ink-black pb-2.5`,children:[(0,j.jsxs)(`h3`,{className:`font-headline-md font-bold text-sm m-0 flex items-center gap-2 tracking-wide`,children:[(0,j.jsx)(k,{className:`w-4 h-4 text-ink-black`}),`API & AI Configuration`]}),(0,j.jsx)(`p`,{className:`text-[11px] text-trash-gray font-medium m-0`,children:`Configure your AI model provider..`})]}),(0,j.jsx)(`div`,{className:`px-4 py-3 border-[3px] border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] transition-all ${Z?`bg-emerald-50`:Q?`bg-rose-50`:`bg-amber-50/70`}`,children:(0,j.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[Z?(0,j.jsx)(h,{className:`w-4 h-4 text-emerald-600 shrink-0`}):Q?(0,j.jsx)(i,{className:`w-4 h-4 text-rose-600 shrink-0`}):(0,j.jsx)(O,{className:`w-4 h-4 text-amber-600 shrink-0`}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`div`,{className:`text-xs font-bold font-headline-md text-ink-black flex items-center gap-1.5`,children:(0,j.jsxs)(`span`,{children:[`Active:`,` `,Z?`${e.toUpperCase()} (Custom Key)`:Q?`${e.toUpperCase()} (Key Required)`:`Default`]})}),(0,j.jsx)(`div`,{className:`text-[10px] text-trash-gray font-medium`,children:Z?`Requests are routed directly through your personal API key.`:Q?`Enter your API key below to activate this provider.`:`Using basic, free built-in developer keys with auto-failover.`})]})]}),(0,j.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${Z?`bg-emerald-300 text-emerald-950`:Q?`bg-rose-300 text-rose-950`:`bg-amber-200 text-amber-950`}`,children:Z?`ACTIVE`:Q?`NEEDS KEY`:`LIMITED`})]})}),(0,j.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider mb-2 font-headline-md flex items-center gap-1.5`,children:[(0,j.jsx)(O,{className:`w-3.5 h-3.5 text-ink-black`}),`Select Provider`]}),(0,j.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:M.map(t=>{let n=e===t.id;return(0,j.jsxs)(`button`,{type:`button`,onClick:()=>ie(t.id),className:`p-2.5 border-[2px] text-left transition-all cursor-pointer flex flex-col justify-between rounded ${n?`border-ink-black bg-[#ffe24c] shadow-[2px_2px_0px_0px_#1E293B] font-bold`:`border-slate-300 bg-slate-50 hover:bg-slate-100 text-slate-700`}`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between w-full`,children:[(0,j.jsx)(`span`,{className:`text-xs font-bold font-headline-md`,children:t.name}),t.badge&&(0,j.jsx)(`span`,{className:`text-[8px] font-bold uppercase px-1 py-0.2 bg-orange-100 text-orange-700 rounded border border-orange-300`,children:t.badge})]}),(0,j.jsx)(`span`,{className:`text-[9px] mt-1 text-slate-600 leading-tight block`,children:t.desc})]},t.id)})})]}),e==="default"?(0,j.jsxs)(`div`,{className:`p-3.5 bg-slate-50 border border-slate-200 rounded flex items-start gap-3`,children:[(0,j.jsx)(ne,{className:`w-4 h-4 text-amber-500 shrink-0 mt-0.5`}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1 text-xs text-slate-700`,children:[(0,j.jsxs)(`span`,{className:`font-bold text-ink-black`,children:[`Shared Quotas (`,(0,j.jsx)(`i`,{children:`limited`}),`)`]}),(0,j.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0 leading-relaxed`,children:`Powered by shared, basic developer keys. Because limits are shared with everyone, requests may fail. Use your own provider keys above for stable performance.`})]})]}):(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,j.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1.5`,children:[(0,j.jsx)(k,{className:`w-3.5 h-3.5 text-ink-black`}),$?.name,` API Key`]}),$?.portalUrl&&(0,j.jsxs)(`a`,{href:$.portalUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-[10px] text-sky-600 hover:text-sky-800 font-medium flex items-center gap-1 no-underline`,children:[(0,j.jsx)(`span`,{children:`Get API Key`}),(0,j.jsx)(a,{className:`w-3 h-3`})]})]}),(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`input`,{type:N?`text`:`password`,value:n,onChange:e=>b(e.target.value),placeholder:`Enter ${$?.keyPrefix||`API Key`}`,className:`w-full bg-white border-[2px] border-ink-black rounded py-2 pl-3 pr-9 text-ink-black placeholder-slate-400 focus:outline-none focus:border-sky-600 text-xs font-code-mono`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>re(!N),className:`absolute right-2.5 top-1/2 -translate-y-1/2 text-trash-gray hover:text-ink-black cursor-pointer bg-transparent border-0 outline-none p-1`,title:N?`Hide API key`:`Show API key`,children:N?(0,j.jsx)(r,{className:`w-3.5 h-3.5`}):(0,j.jsx)(ee,{className:`w-3.5 h-3.5`})})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-trash-gray font-medium`,children:[(0,j.jsx)(m,{className:`w-3.5 h-3.5 text-emerald-600 shrink-0`}),(0,j.jsx)(`span`,{children:`Stored locally in your browser. Sent directly via request headers.`})]}),(0,j.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[(0,j.jsxs)(`button`,{onClick:ae,className:`flex-1 flex items-center justify-center gap-1.5 py-2 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,j.jsx)(p,{className:`w-3.5 h-3.5`}),`Save Key`]}),n&&(0,j.jsx)(`button`,{onClick:oe,className:`px-3 py-2 border-[2px] border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 hover:text-rose-600 shadow-[2px_2px_0px_0px_rgba(0,0,0,0.05)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:`Clear Key`})]})]}),P&&(0,j.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${P.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:P.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[P.type===`success`?(0,j.jsx)(_,{className:`w-3.5 h-3.5 shrink-0`}):P.type===`error`?(0,j.jsx)(i,{className:`w-3.5 h-3.5 shrink-0`}):(0,j.jsx)(f,{className:`w-3.5 h-3.5 shrink-0`}),P.text]}),e!=="default"&&(0,j.jsx)(`div`,{className:`pt-2 border-t border-slate-200 flex justify-end`,children:(0,j.jsxs)(`button`,{onClick:se,className:`flex items-center gap-1.5 py-1.5 px-3 border border-slate-300 bg-slate-50 hover:bg-slate-100 text-[11px] font-bold text-slate-600 hover:text-ink-black transition-all cursor-pointer rounded`,children:[(0,j.jsx)(v,{className:`w-3 h-3 text-slate-500`}),`Reset to Server Default`]})})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,j.jsx)(`div`,{className:`w-8 h-8 rounded bg-[#24292e] border-[2px] border-ink-black flex items-center justify-center text-white shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,j.jsx)(d,{className:`w-4 h-4 text-white`})}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0 flex items-center gap-2`,children:`GitHub Solutions Sync & Auto-Commit`}),(0,j.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Sync solutions to personal GitHub repository and commit automatically on submission`})]})]}),(0,j.jsx)(`span`,{className:`px-2 py-0.5 text-[9px] font-bold font-arcade uppercase border-2 border-ink-black shrink-0 ${X?`bg-emerald-300 text-emerald-950`:`bg-slate-200 text-slate-800`}`,children:X?`CONNECTED`:`DISCONNECTED`})]}),X?(0,j.jsxs)(`div`,{className:`space-y-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-2 p-3 bg-slate-50 border border-slate-200 rounded`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[W?.avatar_url&&(0,j.jsx)(`img`,{src:W.avatar_url,alt:W.login,className:`w-7 h-7 rounded-full border border-ink-black`}),(0,j.jsxs)(`div`,{children:[(0,j.jsxs)(`span`,{className:`text-xs font-bold text-ink-black`,children:[`@`,W?.login||H.username]}),(0,j.jsxs)(`span`,{className:`text-[11px] text-slate-600 font-mono block`,children:[H.username,`/`,H.repoName,` (`,H.branch,`)`]})]})]}),(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`a`,{href:`https://github.com/${H.username}/${H.repoName}`,target:`_blank`,rel:`noopener noreferrer`,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-slate-100 text-ink-black border border-slate-300 rounded no-underline flex items-center gap-1 cursor-pointer`,children:[(0,j.jsx)(a,{className:`w-3 h-3`}),(0,j.jsx)(`span`,{children:`View Repo`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:fe,className:`px-2.5 py-1 text-[11px] font-bold bg-white hover:bg-rose-50 text-rose-700 border border-rose-300 rounded cursor-pointer`,children:`Disconnect`})]})]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-emerald-50/50 border border-emerald-300 rounded cursor-pointer`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:H.autoCommit,onChange:e=>pe(e.target.checked),className:`w-4 h-4 accent-emerald-600 cursor-pointer`}),(0,j.jsxs)(`div`,{className:`text-xs`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Auto-commit on every submission`}),(0,j.jsxs)(`span`,{className:`text-[10px] text-trash-gray`,children:[`Automatically pushes your code to `,H.repoName,` whenever you grade a review card.`]})]})]})]}):(0,j.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 p-3.5 bg-slate-50 border border-slate-200 rounded`,children:[(0,j.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,j.jsx)(`span`,{className:`text-xs font-bold text-ink-black block`,children:`Connect your GitHub Account (1-Click OAuth)`}),(0,j.jsx)(`p`,{className:`text-[11px] text-trash-gray m-0`,children:`Grant repository access to automatically sync your DSA problem solutions as you study.`})]}),(0,j.jsx)(`button`,{type:`button`,onClick:de,disabled:K,className:`px-4 py-2 bg-[#24292e] hover:bg-black text-white text-xs font-bold uppercase rounded border-2 border-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none flex items-center gap-2 shrink-0 cursor-pointer disabled:opacity-50`,children:K?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(y,{className:`w-3.5 h-3.5 animate-spin`}),(0,j.jsx)(`span`,{children:`CONNECTING...`})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(d,{className:`w-3.5 h-3.5 text-yellow-300`}),(0,j.jsx)(`span`,{children:`CONNECT GITHUB`})]})})]}),J&&(0,j.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${J.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:J.type===`error`?`bg-rose-100 border-rose-600 text-rose-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[J.type===`success`?(0,j.jsx)(_,{className:`w-3.5 h-3.5 shrink-0`}):J.type===`error`?(0,j.jsx)(i,{className:`w-3.5 h-3.5 shrink-0`}):(0,j.jsx)(f,{className:`w-3.5 h-3.5 shrink-0`}),J.text]})]}),(0,j.jsxs)(`div`,{className:`bg-[#FFFDF0] border-[3px] border-ink-black p-4 sm:p-5 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between border-b-[2px] border-ink-black pb-3`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsx)(`div`,{className:`w-7 h-7 rounded bg-[#FFE24C] border-[2px] border-ink-black flex items-center justify-center shadow-[1px_1px_0px_0px_#1E293B]`,children:(0,j.jsx)(w,{className:`w-4 h-4 text-ink-black`})}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`h4`,{className:`font-headline-md font-bold text-xs uppercase text-ink-black m-0`,children:`Princess AI Companion & RPG Settings`}),(0,j.jsx)(`p`,{className:`text-[10px] text-trash-gray font-medium m-0`,children:`Trapped Princess Persona, Study Break Timer & 8-bit RPG Audio`})]})]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,j.jsx)(`span`,{className:`text-[11px] font-bold text-ink-black font-headline-md uppercase`,children:I.enabled?`Enabled`:`Disabled`}),(0,j.jsx)(`input`,{type:`checkbox`,checked:I.enabled,onChange:e=>L(t=>({...t,enabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`})]})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Companion Name`}),(0,j.jsx)(`input`,{type:`text`,value:I.name,onChange:e=>L(t=>({...t,name:e.target.value})),placeholder:`e.g. Princess Aurelia`,className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsxs)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md flex items-center gap-1`,children:[(0,j.jsx)(g,{className:`w-3.5 h-3.5 text-amber-700`}),`Study Break Reminder`]}),(0,j.jsxs)(`select`,{value:I.breakIntervalMinutes,onChange:e=>L(t=>({...t,breakIntervalMinutes:Number(e.target.value)})),className:`bg-white border-[2px] border-ink-black rounded py-2 px-3 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 cursor-pointer`,children:[(0,j.jsx)(`option`,{value:25,children:`Every 25 Minutes (Classic Pomodoro)`}),(0,j.jsx)(`option`,{value:45,children:`Every 45 Minutes`}),(0,j.jsx)(`option`,{value:60,children:`Every 60 Minutes`}),(0,j.jsx)(`option`,{value:0,children:`Disabled (No automatic break popups)`})]})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,j.jsx)(`label`,{className:`block text-xs font-bold text-ink-black uppercase tracking-wider font-headline-md`,children:`Princess Backstory & Persona Prompt`}),(0,j.jsx)(`textarea`,{rows:2,value:I.backstory,onChange:e=>L(t=>({...t,backstory:e.target.value})),placeholder:`Describe her background, tone, and connection to your DSA studies...`,className:`bg-white border-[2px] border-ink-black rounded p-2.5 text-ink-black text-xs font-sans font-medium focus:outline-none focus:border-amber-600 resize-y`})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 pt-1`,children:[(0,j.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:I.soundEnabled,onChange:e=>{let t=e.target.checked;L(e=>({...e,soundEnabled:t})),x(!t)},className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,j.jsxs)(`div`,{className:`text-xs`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`8-bit Sound Effects`}),(0,j.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Typewriter blips, chimes & fanfare`})]})]}),(0,j.jsxs)(`label`,{className:`flex items-center gap-2.5 p-2.5 bg-white border border-slate-300 rounded cursor-pointer hover:border-ink-black transition-all`,children:[(0,j.jsx)(`input`,{type:`checkbox`,checked:I.autoPopupEnabled,onChange:e=>L(t=>({...t,autoPopupEnabled:e.target.checked})),className:`w-4 h-4 accent-amber-500 cursor-pointer`}),(0,j.jsxs)(`div`,{className:`text-xs`,children:[(0,j.jsx)(`span`,{className:`font-bold text-ink-black block`,children:`Spontaneous RPG Popups`}),(0,j.jsx)(`span`,{className:`text-[10px] text-trash-gray`,children:`Speech bubbles for breaks & milestones`})]})]})]}),(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 pt-2 border-t border-slate-200`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:ce,className:`flex items-center gap-1.5 py-2 px-4 border-[2px] border-ink-black bg-[#ffe24c] hover:bg-yellow-300 text-xs font-bold text-ink-black shadow-[2px_2px_0px_0px_#1E293B] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer rounded uppercase`,children:[(0,j.jsx)(p,{className:`w-3.5 h-3.5`}),`Save Companion Settings`]}),(0,j.jsx)(`button`,{type:`button`,onClick:le,className:`py-2 px-3 border border-slate-300 bg-white hover:bg-slate-50 text-xs font-bold text-slate-700 transition-all cursor-pointer rounded`,children:`Default Persona`})]}),(0,j.jsxs)(`button`,{type:`button`,onClick:ue,className:`flex items-center gap-1 py-1.5 px-3 border border-rose-300 bg-rose-50 hover:bg-rose-100 text-rose-700 text-[11px] font-bold transition-all cursor-pointer rounded`,children:[(0,j.jsx)(v,{className:`w-3 h-3 text-rose-500`}),(0,j.jsxs)(`span`,{children:[`Reset Journey (`,B,`/150 LC)`]})]})]}),R&&(0,j.jsxs)(`div`,{className:`p-2.5 border-[2px] border-ink-black text-xs font-medium rounded flex items-center gap-2 ${R.type===`success`?`bg-emerald-100 border-emerald-600 text-emerald-900`:`bg-sky-100 border-sky-600 text-sky-900`}`,children:[(0,j.jsx)(_,{className:`w-3.5 h-3.5 shrink-0`}),R.text]})]}),(0,j.jsxs)(`div`,{className:`bg-white border-[3px] border-ink-black p-4 shadow-[4px_4px_0px_0px_rgba(30,41,59,1)] flex flex-col gap-2.5`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,j.jsx)(f,{className:`w-3.5 h-3.5 text-[#0ea5e9]`}),(0,j.jsx)(`h4`,{className:`text-xs font-bold uppercase font-headline-md m-0`,children:`Get Free API Keys`})]}),(0,j.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-2 text-[10px]`,children:[(0,j.jsxs)(`a`,{href:`https://console.groq.com/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,j.jsx)(`span`,{children:`Groq Cloud`}),(0,j.jsx)(a,{className:`w-3 h-3 text-slate-400`})]}),(0,j.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Fast inference with generous free rate limits.`})]}),(0,j.jsxs)(`a`,{href:`https://aistudio.google.com/app/apikey`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,j.jsx)(`span`,{children:`Google AI Studio`}),(0,j.jsx)(a,{className:`w-3 h-3 text-slate-400`})]}),(0,j.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Free Gemini Flash API quota.`})]}),(0,j.jsxs)(`a`,{href:`https://openrouter.ai/keys`,target:`_blank`,rel:`noopener noreferrer`,className:`p-2.5 border border-slate-200 hover:border-ink-black hover:bg-slate-50 rounded flex flex-col justify-between gap-1 transition-all no-underline text-inherit cursor-pointer`,children:[(0,j.jsxs)(`div`,{className:`flex items-center justify-between font-bold text-ink-black`,children:[(0,j.jsx)(`span`,{children:`OpenRouter`}),(0,j.jsx)(a,{className:`w-3 h-3 text-slate-400`})]}),(0,j.jsx)(`p`,{className:`m-0 text-trash-gray leading-normal`,children:`Unified API for open-weights models.`})]})]})]})]})}export{N as default};
 
 
algospaced-ui/dist/assets/circle-alert-BL6bvZTM.js ADDED
@@ -0,0 +1 @@
 
 
1
+ import{G as e}from"./index-V2pPJO9M.js";var t=e(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]);export{t};
algospaced-ui/dist/assets/{confetti.module-BEqdENp8.js → confetti.module-nUzO7Zin.js} RENAMED
@@ -1,2 +1,2 @@
1
- import{U as e}from"./index-g5jVBiGr.js";var t=e(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),n=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),r=e(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),i=e(`trophy`,[[`path`,{d:`M10 14.66V17a1 1 0 0 1-1 1 2 2 0 0 0-2 2v2`,key:`pwuv1l`}],[`path`,{d:`M14 14.66V17a1 1 0 0 0 1 1 2 2 0 0 1 2 2v2`,key:`1y54w1`}],[`path`,{d:`M17.916 10H19.5A2.5 2.5 0 0 0 22 7.5V5a1 1 0 0 0-1-1h-3`,key:`e30mpu`}],[`path`,{d:`M4 22h16`,key:`57wxv0`}],[`path`,{d:`M6 9a6 6 0 0 0 12 0V3a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1z`,key:`1mhfuq`}],[`path`,{d:`M6.084 10H4.5A2.5 2.5 0 0 1 2 7.5V5a1 1 0 0 1 1-1h3`,key:`i0yafy`}]]),a={};(function e(t,n,r,i){var a=!!(t.Worker&&t.Blob&&t.Promise&&t.OffscreenCanvas&&t.OffscreenCanvasRenderingContext2D&&t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype.transferControlToOffscreen&&t.URL&&t.URL.createObjectURL),o=typeof Path2D==`function`&&typeof DOMMatrix==`function`,s=(function(){if(!t.OffscreenCanvas)return!1;try{var e=new OffscreenCanvas(1,1),n=e.getContext(`2d`);n.fillRect(0,0,1,1);var r=e.transferToImageBitmap();n.createPattern(r,`no-repeat`)}catch{return!1}return!0})();function c(){}function l(e){var r=n.exports.Promise,i=r===void 0?t.Promise:r;return typeof i==`function`?new i(e):(e(c,c),null)}var u=(function(e,t){return{transform:function(n){if(e)return n;if(t.has(n))return t.get(n);var r=new OffscreenCanvas(n.width,n.height);return r.getContext(`2d`).drawImage(n,0,0),t.set(n,r),r},clear:function(){t.clear()}}})(s,new Map),d=function(){var e,t,n={},r=0;return typeof requestAnimationFrame==`function`&&typeof cancelAnimationFrame==`function`?(e=function(e){var t=Math.random();return n[t]=requestAnimationFrame(function i(a){r===a||r+16-1<a?(r=a,delete n[t],e()):n[t]=requestAnimationFrame(i)}),t},t=function(e){n[e]&&cancelAnimationFrame(n[e])}):(e=function(e){return setTimeout(e,16)},t=function(e){return clearTimeout(e)}),{frame:e,cancel:t}}(),f=(function(){var t,n,i={};function o(e){function t(t,n){e.postMessage({options:t||{},callback:n})}e.init=function(t){var n=t.transferControlToOffscreen();e.postMessage({canvas:n},[n])},e.fire=function(r,a,o){if(n)return t(r,null),n;var s=Math.random().toString(36).slice(2);return n=l(function(a){function c(t){t.data.callback===s&&(delete i[s],e.removeEventListener(`message`,c),n=null,u.clear(),o(),a())}e.addEventListener(`message`,c),t(r,s),i[s]=c.bind(null,{data:{callback:s}})}),n},e.reset=function(){for(var t in e.postMessage({reset:!0}),i)i[t](),delete i[t]}}return function(){if(t)return t;if(!r&&a){var n=[`var CONFETTI, SIZE = {}, module = {};`,`(`+e.toString()+`)(this, module, true, SIZE);`,`onmessage = function(msg) {`,` if (msg.data.options) {`,` CONFETTI(msg.data.options).then(function () {`,` if (msg.data.callback) {`,` postMessage({ callback: msg.data.callback });`,` }`,` });`,` } else if (msg.data.reset) {`,` CONFETTI && CONFETTI.reset();`,` } else if (msg.data.resize) {`,` SIZE.width = msg.data.resize.width;`,` SIZE.height = msg.data.resize.height;`,` } else if (msg.data.canvas) {`,` SIZE.width = msg.data.canvas.width;`,` SIZE.height = msg.data.canvas.height;`,` CONFETTI = module.exports.create(msg.data.canvas);`,` }`,`}`].join(`
2
  `);try{t=new Worker(URL.createObjectURL(new Blob([n])))}catch(e){return typeof console<`u`&&typeof console.warn==`function`&&console.warn(`🎊 Could not load worker`,e),null}o(t)}return t}})(),p={particleCount:50,angle:90,spread:45,startVelocity:45,decay:.9,gravity:1,drift:0,ticks:200,x:.5,y:.5,shapes:[`square`,`circle`],zIndex:100,colors:[`#26ccff`,`#a25afd`,`#ff5e7e`,`#88ff5a`,`#fcff42`,`#ffa62d`,`#ff36ff`],disableForReducedMotion:!1,scalar:1};function m(e,t){return t?t(e):e}function h(e){return e!=null}function g(e,t,n){return m(e&&h(e[t])?e[t]:p[t],n)}function _(e){return e<0?0:Math.floor(e)}function v(e,t){return Math.floor(Math.random()*(t-e))+e}function y(e){return parseInt(e,16)}function b(e){return e.map(x)}function x(e){var t=String(e).replace(/[^0-9a-f]/gi,``);return t.length<6&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),{r:y(t.substring(0,2)),g:y(t.substring(2,4)),b:y(t.substring(4,6))}}function S(e){var t=g(e,`origin`,Object);return t.x=g(t,`x`,Number),t.y=g(t,`y`,Number),t}function C(e){e.width=document.documentElement.clientWidth,e.height=document.documentElement.clientHeight}function w(e){var t=e.getBoundingClientRect();e.width=t.width,e.height=t.height}function T(e){var t=document.createElement(`canvas`);return t.style.position=`fixed`,t.style.top=`0px`,t.style.left=`0px`,t.style.pointerEvents=`none`,t.style.zIndex=e,t}function E(e,t,n,r,i,a,o,s,c){e.save(),e.translate(t,n),e.rotate(a),e.scale(r,i),e.arc(0,0,1,o,s,c),e.restore()}function D(e){var t=e.angle*(Math.PI/180),n=e.spread*(Math.PI/180);return{x:e.x,y:e.y,wobble:Math.random()*10,wobbleSpeed:Math.min(.11,Math.random()*.1+.05),velocity:e.startVelocity*.5+Math.random()*e.startVelocity,angle2D:-t+(.5*n-Math.random()*n),tiltAngle:(Math.random()*.5+.25)*Math.PI,color:e.color,shape:e.shape,tick:0,totalTicks:e.ticks,decay:e.decay,drift:e.drift,random:Math.random()+2,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:e.gravity*3,ovalScalar:.6,scalar:e.scalar,flat:e.flat}}function O(e,t){t.x+=Math.cos(t.angle2D)*t.velocity+t.drift,t.y+=Math.sin(t.angle2D)*t.velocity+t.gravity,t.velocity*=t.decay,t.flat?(t.wobble=0,t.wobbleX=t.x+10*t.scalar,t.wobbleY=t.y+10*t.scalar,t.tiltSin=0,t.tiltCos=0,t.random=1):(t.wobble+=t.wobbleSpeed,t.wobbleX=t.x+10*t.scalar*Math.cos(t.wobble),t.wobbleY=t.y+10*t.scalar*Math.sin(t.wobble),t.tiltAngle+=.1,t.tiltSin=Math.sin(t.tiltAngle),t.tiltCos=Math.cos(t.tiltAngle),t.random=Math.random()+2);var n=t.tick++/t.totalTicks,r=t.x+t.random*t.tiltCos,i=t.y+t.random*t.tiltSin,a=t.wobbleX+t.random*t.tiltCos,s=t.wobbleY+t.random*t.tiltSin;if(e.fillStyle=`rgba(`+t.color.r+`, `+t.color.g+`, `+t.color.b+`, `+(1-n)+`)`,e.beginPath(),o&&t.shape.type===`path`&&typeof t.shape.path==`string`&&Array.isArray(t.shape.matrix))e.fill(N(t.shape.path,t.shape.matrix,t.x,t.y,Math.abs(a-r)*.1,Math.abs(s-i)*.1,Math.PI/10*t.wobble));else if(t.shape.type===`bitmap`){var c=Math.PI/10*t.wobble,l=Math.abs(a-r)*.1,d=Math.abs(s-i)*.1,f=t.shape.bitmap.width*t.scalar,p=t.shape.bitmap.height*t.scalar,m=new DOMMatrix([Math.cos(c)*l,Math.sin(c)*l,-Math.sin(c)*d,Math.cos(c)*d,t.x,t.y]);m.multiplySelf(new DOMMatrix(t.shape.matrix));var h=e.createPattern(u.transform(t.shape.bitmap),`no-repeat`);h.setTransform(m),e.globalAlpha=1-n,e.fillStyle=h,e.fillRect(t.x-f/2,t.y-p/2,f,p),e.globalAlpha=1}else if(t.shape===`circle`)e.ellipse?e.ellipse(t.x,t.y,Math.abs(a-r)*t.ovalScalar,Math.abs(s-i)*t.ovalScalar,Math.PI/10*t.wobble,0,2*Math.PI):E(e,t.x,t.y,Math.abs(a-r)*t.ovalScalar,Math.abs(s-i)*t.ovalScalar,Math.PI/10*t.wobble,0,2*Math.PI);else if(t.shape===`star`)for(var g=Math.PI/2*3,_=4*t.scalar,v=8*t.scalar,y=t.x,b=t.y,x=5,S=Math.PI/x;x--;)y=t.x+Math.cos(g)*v,b=t.y+Math.sin(g)*v,e.lineTo(y,b),g+=S,y=t.x+Math.cos(g)*_,b=t.y+Math.sin(g)*_,e.lineTo(y,b),g+=S;else e.moveTo(Math.floor(t.x),Math.floor(t.y)),e.lineTo(Math.floor(t.wobbleX),Math.floor(i)),e.lineTo(Math.floor(a),Math.floor(s)),e.lineTo(Math.floor(r),Math.floor(t.wobbleY));return e.closePath(),e.fill(),t.tick<t.totalTicks}function k(e,t,n,a,o){var s=t.slice(),c=e.getContext(`2d`),f,p,m=l(function(t){function l(){f=p=null,c.clearRect(0,0,a.width,a.height),u.clear(),o(),t()}function m(){r&&(a.width!==i.width||a.height!==i.height)&&(a.width=e.width=i.width,a.height=e.height=i.height),!a.width&&!a.height&&(n(e),a.width=e.width,a.height=e.height),c.clearRect(0,0,a.width,a.height),s=s.filter(function(e){return O(c,e)}),s.length?f=d.frame(m):l()}f=d.frame(m),p=l});return{addFettis:function(e){return s=s.concat(e),m},canvas:e,promise:m,reset:function(){f&&d.cancel(f),p&&p()}}}function A(e,n){var r=!e,i=!!g(n||{},`resize`),o=!1,s=g(n,`disableForReducedMotion`,Boolean),c=a&&g(n||{},`useWorker`)?f():null,u=r?C:w,d=e&&c?!!e.__confetti_initialized:!1,p=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion)`).matches,m;function h(t,n,r){for(var i=g(t,`particleCount`,_),a=g(t,`angle`,Number),o=g(t,`spread`,Number),s=g(t,`startVelocity`,Number),c=g(t,`decay`,Number),l=g(t,`gravity`,Number),d=g(t,`drift`,Number),f=g(t,`colors`,b),p=g(t,`ticks`,Number),h=g(t,`shapes`),y=g(t,`scalar`),x=!!g(t,`flat`),C=S(t),w=i,T=[],E=e.width*C.x,O=e.height*C.y;w--;)T.push(D({x:E,y:O,angle:a,spread:o,startVelocity:s,color:f[w%f.length],shape:h[v(0,h.length)],ticks:p,decay:c,gravity:l,drift:d,scalar:y,flat:x}));return m?m.addFettis(T):(m=k(e,T,u,n,r),m.promise)}function y(n){var a=s||g(n,`disableForReducedMotion`,Boolean),f=g(n,`zIndex`,Number);if(a&&p)return l(function(e){e()});r&&m?e=m.canvas:r&&!e&&(e=T(f),document.body.appendChild(e)),i&&!d&&u(e);var _={width:e.width,height:e.height};c&&!d&&c.init(e),d=!0,c&&(e.__confetti_initialized=!0);function v(){if(c){var t={getBoundingClientRect:function(){if(!r)return e.getBoundingClientRect()}};u(t),c.postMessage({resize:{width:t.width,height:t.height}});return}_.width=_.height=null}function y(){m=null,i&&(o=!1,t.removeEventListener(`resize`,v)),r&&e&&(document.body.contains(e)&&document.body.removeChild(e),e=null,d=!1)}return i&&!o&&(o=!0,t.addEventListener(`resize`,v,!1)),c?c.fire(n,_,y):h(n,_,y)}return y.reset=function(){c&&c.reset(),m&&m.reset()},y}var j;function M(){return j||=A(null,{useWorker:!0,resize:!0}),j}function N(e,t,n,r,i,a,o){var s=new Path2D(e),c=new Path2D;c.addPath(s,new DOMMatrix(t));var l=new Path2D;return l.addPath(c,new DOMMatrix([Math.cos(o)*i,Math.sin(o)*i,-Math.sin(o)*a,Math.cos(o)*a,n,r])),l}function P(e){if(!o)throw Error(`path confetti are not supported in this browser`);var t,n;typeof e==`string`?t=e:(t=e.path,n=e.matrix);var r=new Path2D(t),i=document.createElement(`canvas`).getContext(`2d`);if(!n){for(var a=1e3,s=a,c=a,l=0,u=0,d,f,p=0;p<a;p+=2)for(var m=0;m<a;m+=2)i.isPointInPath(r,p,m,`nonzero`)&&(s=Math.min(s,p),c=Math.min(c,m),l=Math.max(l,p),u=Math.max(u,m));d=l-s,f=u-c;var h=10,g=Math.min(h/d,h/f);n=[g,0,0,g,-Math.round(d/2+s)*g,-Math.round(f/2+c)*g]}return{type:`path`,path:t,matrix:n}}function F(e){var t,n=1,r=`#000000`,i=`"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif`;typeof e==`string`?t=e:(t=e.text,n=`scalar`in e?e.scalar:n,i=`fontFamily`in e?e.fontFamily:i,r=`color`in e?e.color:r);var a=10*n,o=``+a+`px `+i,s=new OffscreenCanvas(a,a),c=s.getContext(`2d`);c.font=o;var l=c.measureText(t),u=Math.ceil(l.actualBoundingBoxRight+l.actualBoundingBoxLeft),d=Math.ceil(l.actualBoundingBoxAscent+l.actualBoundingBoxDescent),f=2,p=l.actualBoundingBoxLeft+f,m=l.actualBoundingBoxAscent+f;u+=f+f,d+=f+f,s=new OffscreenCanvas(u,d),c=s.getContext(`2d`),c.font=o,c.fillStyle=r,c.fillText(t,p,m);var h=1/n;return{type:`bitmap`,bitmap:s.transferToImageBitmap(),matrix:[h,0,0,h,-u*h/2,-d*h/2]}}n.exports=function(){return M().apply(this,arguments)},n.exports.reset=function(){M().reset()},n.exports.create=A,n.exports.shapeFromPath=P,n.exports.shapeFromText=F})((function(){return typeof window<`u`?window:typeof self<`u`?self:this||{}})(),a,!1);var o=a.exports;a.exports.create;export{t as a,n as i,i as n,r,o as t};
 
1
+ import{G as e}from"./index-V2pPJO9M.js";var t=e(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),n=e(`file-text`,[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]),r=e(`layers`,[[`path`,{d:`M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z`,key:`zw3jo`}],[`path`,{d:`M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12`,key:`1wduqc`}],[`path`,{d:`M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17`,key:`kqbvx6`}]]),i=e(`trophy`,[[`path`,{d:`M10 14.66V17a1 1 0 0 1-1 1 2 2 0 0 0-2 2v2`,key:`pwuv1l`}],[`path`,{d:`M14 14.66V17a1 1 0 0 0 1 1 2 2 0 0 1 2 2v2`,key:`1y54w1`}],[`path`,{d:`M17.916 10H19.5A2.5 2.5 0 0 0 22 7.5V5a1 1 0 0 0-1-1h-3`,key:`e30mpu`}],[`path`,{d:`M4 22h16`,key:`57wxv0`}],[`path`,{d:`M6 9a6 6 0 0 0 12 0V3a1 1 0 0 0-1-1H7a1 1 0 0 0-1 1z`,key:`1mhfuq`}],[`path`,{d:`M6.084 10H4.5A2.5 2.5 0 0 1 2 7.5V5a1 1 0 0 1 1-1h3`,key:`i0yafy`}]]),a={};(function e(t,n,r,i){var a=!!(t.Worker&&t.Blob&&t.Promise&&t.OffscreenCanvas&&t.OffscreenCanvasRenderingContext2D&&t.HTMLCanvasElement&&t.HTMLCanvasElement.prototype.transferControlToOffscreen&&t.URL&&t.URL.createObjectURL),o=typeof Path2D==`function`&&typeof DOMMatrix==`function`,s=(function(){if(!t.OffscreenCanvas)return!1;try{var e=new OffscreenCanvas(1,1),n=e.getContext(`2d`);n.fillRect(0,0,1,1);var r=e.transferToImageBitmap();n.createPattern(r,`no-repeat`)}catch{return!1}return!0})();function c(){}function l(e){var r=n.exports.Promise,i=r===void 0?t.Promise:r;return typeof i==`function`?new i(e):(e(c,c),null)}var u=(function(e,t){return{transform:function(n){if(e)return n;if(t.has(n))return t.get(n);var r=new OffscreenCanvas(n.width,n.height);return r.getContext(`2d`).drawImage(n,0,0),t.set(n,r),r},clear:function(){t.clear()}}})(s,new Map),d=function(){var e,t,n={},r=0;return typeof requestAnimationFrame==`function`&&typeof cancelAnimationFrame==`function`?(e=function(e){var t=Math.random();return n[t]=requestAnimationFrame(function i(a){r===a||r+16-1<a?(r=a,delete n[t],e()):n[t]=requestAnimationFrame(i)}),t},t=function(e){n[e]&&cancelAnimationFrame(n[e])}):(e=function(e){return setTimeout(e,16)},t=function(e){return clearTimeout(e)}),{frame:e,cancel:t}}(),f=(function(){var t,n,i={};function o(e){function t(t,n){e.postMessage({options:t||{},callback:n})}e.init=function(t){var n=t.transferControlToOffscreen();e.postMessage({canvas:n},[n])},e.fire=function(r,a,o){if(n)return t(r,null),n;var s=Math.random().toString(36).slice(2);return n=l(function(a){function c(t){t.data.callback===s&&(delete i[s],e.removeEventListener(`message`,c),n=null,u.clear(),o(),a())}e.addEventListener(`message`,c),t(r,s),i[s]=c.bind(null,{data:{callback:s}})}),n},e.reset=function(){for(var t in e.postMessage({reset:!0}),i)i[t](),delete i[t]}}return function(){if(t)return t;if(!r&&a){var n=[`var CONFETTI, SIZE = {}, module = {};`,`(`+e.toString()+`)(this, module, true, SIZE);`,`onmessage = function(msg) {`,` if (msg.data.options) {`,` CONFETTI(msg.data.options).then(function () {`,` if (msg.data.callback) {`,` postMessage({ callback: msg.data.callback });`,` }`,` });`,` } else if (msg.data.reset) {`,` CONFETTI && CONFETTI.reset();`,` } else if (msg.data.resize) {`,` SIZE.width = msg.data.resize.width;`,` SIZE.height = msg.data.resize.height;`,` } else if (msg.data.canvas) {`,` SIZE.width = msg.data.canvas.width;`,` SIZE.height = msg.data.canvas.height;`,` CONFETTI = module.exports.create(msg.data.canvas);`,` }`,`}`].join(`
2
  `);try{t=new Worker(URL.createObjectURL(new Blob([n])))}catch(e){return typeof console<`u`&&typeof console.warn==`function`&&console.warn(`🎊 Could not load worker`,e),null}o(t)}return t}})(),p={particleCount:50,angle:90,spread:45,startVelocity:45,decay:.9,gravity:1,drift:0,ticks:200,x:.5,y:.5,shapes:[`square`,`circle`],zIndex:100,colors:[`#26ccff`,`#a25afd`,`#ff5e7e`,`#88ff5a`,`#fcff42`,`#ffa62d`,`#ff36ff`],disableForReducedMotion:!1,scalar:1};function m(e,t){return t?t(e):e}function h(e){return e!=null}function g(e,t,n){return m(e&&h(e[t])?e[t]:p[t],n)}function _(e){return e<0?0:Math.floor(e)}function v(e,t){return Math.floor(Math.random()*(t-e))+e}function y(e){return parseInt(e,16)}function b(e){return e.map(x)}function x(e){var t=String(e).replace(/[^0-9a-f]/gi,``);return t.length<6&&(t=t[0]+t[0]+t[1]+t[1]+t[2]+t[2]),{r:y(t.substring(0,2)),g:y(t.substring(2,4)),b:y(t.substring(4,6))}}function S(e){var t=g(e,`origin`,Object);return t.x=g(t,`x`,Number),t.y=g(t,`y`,Number),t}function C(e){e.width=document.documentElement.clientWidth,e.height=document.documentElement.clientHeight}function w(e){var t=e.getBoundingClientRect();e.width=t.width,e.height=t.height}function T(e){var t=document.createElement(`canvas`);return t.style.position=`fixed`,t.style.top=`0px`,t.style.left=`0px`,t.style.pointerEvents=`none`,t.style.zIndex=e,t}function E(e,t,n,r,i,a,o,s,c){e.save(),e.translate(t,n),e.rotate(a),e.scale(r,i),e.arc(0,0,1,o,s,c),e.restore()}function D(e){var t=e.angle*(Math.PI/180),n=e.spread*(Math.PI/180);return{x:e.x,y:e.y,wobble:Math.random()*10,wobbleSpeed:Math.min(.11,Math.random()*.1+.05),velocity:e.startVelocity*.5+Math.random()*e.startVelocity,angle2D:-t+(.5*n-Math.random()*n),tiltAngle:(Math.random()*.5+.25)*Math.PI,color:e.color,shape:e.shape,tick:0,totalTicks:e.ticks,decay:e.decay,drift:e.drift,random:Math.random()+2,tiltSin:0,tiltCos:0,wobbleX:0,wobbleY:0,gravity:e.gravity*3,ovalScalar:.6,scalar:e.scalar,flat:e.flat}}function O(e,t){t.x+=Math.cos(t.angle2D)*t.velocity+t.drift,t.y+=Math.sin(t.angle2D)*t.velocity+t.gravity,t.velocity*=t.decay,t.flat?(t.wobble=0,t.wobbleX=t.x+10*t.scalar,t.wobbleY=t.y+10*t.scalar,t.tiltSin=0,t.tiltCos=0,t.random=1):(t.wobble+=t.wobbleSpeed,t.wobbleX=t.x+10*t.scalar*Math.cos(t.wobble),t.wobbleY=t.y+10*t.scalar*Math.sin(t.wobble),t.tiltAngle+=.1,t.tiltSin=Math.sin(t.tiltAngle),t.tiltCos=Math.cos(t.tiltAngle),t.random=Math.random()+2);var n=t.tick++/t.totalTicks,r=t.x+t.random*t.tiltCos,i=t.y+t.random*t.tiltSin,a=t.wobbleX+t.random*t.tiltCos,s=t.wobbleY+t.random*t.tiltSin;if(e.fillStyle=`rgba(`+t.color.r+`, `+t.color.g+`, `+t.color.b+`, `+(1-n)+`)`,e.beginPath(),o&&t.shape.type===`path`&&typeof t.shape.path==`string`&&Array.isArray(t.shape.matrix))e.fill(N(t.shape.path,t.shape.matrix,t.x,t.y,Math.abs(a-r)*.1,Math.abs(s-i)*.1,Math.PI/10*t.wobble));else if(t.shape.type===`bitmap`){var c=Math.PI/10*t.wobble,l=Math.abs(a-r)*.1,d=Math.abs(s-i)*.1,f=t.shape.bitmap.width*t.scalar,p=t.shape.bitmap.height*t.scalar,m=new DOMMatrix([Math.cos(c)*l,Math.sin(c)*l,-Math.sin(c)*d,Math.cos(c)*d,t.x,t.y]);m.multiplySelf(new DOMMatrix(t.shape.matrix));var h=e.createPattern(u.transform(t.shape.bitmap),`no-repeat`);h.setTransform(m),e.globalAlpha=1-n,e.fillStyle=h,e.fillRect(t.x-f/2,t.y-p/2,f,p),e.globalAlpha=1}else if(t.shape===`circle`)e.ellipse?e.ellipse(t.x,t.y,Math.abs(a-r)*t.ovalScalar,Math.abs(s-i)*t.ovalScalar,Math.PI/10*t.wobble,0,2*Math.PI):E(e,t.x,t.y,Math.abs(a-r)*t.ovalScalar,Math.abs(s-i)*t.ovalScalar,Math.PI/10*t.wobble,0,2*Math.PI);else if(t.shape===`star`)for(var g=Math.PI/2*3,_=4*t.scalar,v=8*t.scalar,y=t.x,b=t.y,x=5,S=Math.PI/x;x--;)y=t.x+Math.cos(g)*v,b=t.y+Math.sin(g)*v,e.lineTo(y,b),g+=S,y=t.x+Math.cos(g)*_,b=t.y+Math.sin(g)*_,e.lineTo(y,b),g+=S;else e.moveTo(Math.floor(t.x),Math.floor(t.y)),e.lineTo(Math.floor(t.wobbleX),Math.floor(i)),e.lineTo(Math.floor(a),Math.floor(s)),e.lineTo(Math.floor(r),Math.floor(t.wobbleY));return e.closePath(),e.fill(),t.tick<t.totalTicks}function k(e,t,n,a,o){var s=t.slice(),c=e.getContext(`2d`),f,p,m=l(function(t){function l(){f=p=null,c.clearRect(0,0,a.width,a.height),u.clear(),o(),t()}function m(){r&&(a.width!==i.width||a.height!==i.height)&&(a.width=e.width=i.width,a.height=e.height=i.height),!a.width&&!a.height&&(n(e),a.width=e.width,a.height=e.height),c.clearRect(0,0,a.width,a.height),s=s.filter(function(e){return O(c,e)}),s.length?f=d.frame(m):l()}f=d.frame(m),p=l});return{addFettis:function(e){return s=s.concat(e),m},canvas:e,promise:m,reset:function(){f&&d.cancel(f),p&&p()}}}function A(e,n){var r=!e,i=!!g(n||{},`resize`),o=!1,s=g(n,`disableForReducedMotion`,Boolean),c=a&&g(n||{},`useWorker`)?f():null,u=r?C:w,d=e&&c?!!e.__confetti_initialized:!1,p=typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion)`).matches,m;function h(t,n,r){for(var i=g(t,`particleCount`,_),a=g(t,`angle`,Number),o=g(t,`spread`,Number),s=g(t,`startVelocity`,Number),c=g(t,`decay`,Number),l=g(t,`gravity`,Number),d=g(t,`drift`,Number),f=g(t,`colors`,b),p=g(t,`ticks`,Number),h=g(t,`shapes`),y=g(t,`scalar`),x=!!g(t,`flat`),C=S(t),w=i,T=[],E=e.width*C.x,O=e.height*C.y;w--;)T.push(D({x:E,y:O,angle:a,spread:o,startVelocity:s,color:f[w%f.length],shape:h[v(0,h.length)],ticks:p,decay:c,gravity:l,drift:d,scalar:y,flat:x}));return m?m.addFettis(T):(m=k(e,T,u,n,r),m.promise)}function y(n){var a=s||g(n,`disableForReducedMotion`,Boolean),f=g(n,`zIndex`,Number);if(a&&p)return l(function(e){e()});r&&m?e=m.canvas:r&&!e&&(e=T(f),document.body.appendChild(e)),i&&!d&&u(e);var _={width:e.width,height:e.height};c&&!d&&c.init(e),d=!0,c&&(e.__confetti_initialized=!0);function v(){if(c){var t={getBoundingClientRect:function(){if(!r)return e.getBoundingClientRect()}};u(t),c.postMessage({resize:{width:t.width,height:t.height}});return}_.width=_.height=null}function y(){m=null,i&&(o=!1,t.removeEventListener(`resize`,v)),r&&e&&(document.body.contains(e)&&document.body.removeChild(e),e=null,d=!1)}return i&&!o&&(o=!0,t.addEventListener(`resize`,v,!1)),c?c.fire(n,_,y):h(n,_,y)}return y.reset=function(){c&&c.reset(),m&&m.reset()},y}var j;function M(){return j||=A(null,{useWorker:!0,resize:!0}),j}function N(e,t,n,r,i,a,o){var s=new Path2D(e),c=new Path2D;c.addPath(s,new DOMMatrix(t));var l=new Path2D;return l.addPath(c,new DOMMatrix([Math.cos(o)*i,Math.sin(o)*i,-Math.sin(o)*a,Math.cos(o)*a,n,r])),l}function P(e){if(!o)throw Error(`path confetti are not supported in this browser`);var t,n;typeof e==`string`?t=e:(t=e.path,n=e.matrix);var r=new Path2D(t),i=document.createElement(`canvas`).getContext(`2d`);if(!n){for(var a=1e3,s=a,c=a,l=0,u=0,d,f,p=0;p<a;p+=2)for(var m=0;m<a;m+=2)i.isPointInPath(r,p,m,`nonzero`)&&(s=Math.min(s,p),c=Math.min(c,m),l=Math.max(l,p),u=Math.max(u,m));d=l-s,f=u-c;var h=10,g=Math.min(h/d,h/f);n=[g,0,0,g,-Math.round(d/2+s)*g,-Math.round(f/2+c)*g]}return{type:`path`,path:t,matrix:n}}function F(e){var t,n=1,r=`#000000`,i=`"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji", "EmojiOne Color", "Android Emoji", "Twemoji Mozilla", "system emoji", sans-serif`;typeof e==`string`?t=e:(t=e.text,n=`scalar`in e?e.scalar:n,i=`fontFamily`in e?e.fontFamily:i,r=`color`in e?e.color:r);var a=10*n,o=``+a+`px `+i,s=new OffscreenCanvas(a,a),c=s.getContext(`2d`);c.font=o;var l=c.measureText(t),u=Math.ceil(l.actualBoundingBoxRight+l.actualBoundingBoxLeft),d=Math.ceil(l.actualBoundingBoxAscent+l.actualBoundingBoxDescent),f=2,p=l.actualBoundingBoxLeft+f,m=l.actualBoundingBoxAscent+f;u+=f+f,d+=f+f,s=new OffscreenCanvas(u,d),c=s.getContext(`2d`),c.font=o,c.fillStyle=r,c.fillText(t,p,m);var h=1/n;return{type:`bitmap`,bitmap:s.transferToImageBitmap(),matrix:[h,0,0,h,-u*h/2,-d*h/2]}}n.exports=function(){return M().apply(this,arguments)},n.exports.reset=function(){M().reset()},n.exports.create=A,n.exports.shapeFromPath=P,n.exports.shapeFromText=F})((function(){return typeof window<`u`?window:typeof self<`u`?self:this||{}})(),a,!1);var o=a.exports;a.exports.create;export{t as a,n as i,i as n,r,o as t};
algospaced-ui/dist/assets/{external-link-yb1gedrc.js → external-link-BGZfX5Bi.js} RENAMED
@@ -1 +1 @@
1
- import{U as e}from"./index-g5jVBiGr.js";var t=e(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]);export{t};
 
1
+ import{G as e}from"./index-V2pPJO9M.js";var t=e(`external-link`,[[`path`,{d:`M15 3h6v6`,key:`1q9fwt`}],[`path`,{d:`M10 14 21 3`,key:`gplh6r`}],[`path`,{d:`M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6`,key:`a6xqqp`}]]);export{t};
algospaced-ui/dist/assets/eye-DeJ_5v51.js DELETED
@@ -1 +0,0 @@
1
- import{U as e}from"./index-g5jVBiGr.js";var t=e(`circle-alert`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`line`,{x1:`12`,x2:`12`,y1:`8`,y2:`12`,key:`1pkeuh`}],[`line`,{x1:`12`,x2:`12.01`,y1:`16`,y2:`16`,key:`4dfq90`}]]),n=e(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),r=e(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]);export{n,t as r,r as t};
 
 
algospaced-ui/dist/assets/githubSyncService--4Z5jmjP.js DELETED
@@ -1 +0,0 @@
1
- import{i as e}from"./jsx-runtime-j9uSgrFF.js";import{U as t}from"./index-g5jVBiGr.js";var n=t(`folder-git-2`,[[`path`,{d:`M18 19a5 5 0 0 1-5-5v8`,key:`sz5oeg`}],[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5`,key:`1w6njk`}],[`circle`,{cx:`13`,cy:`12`,r:`2`,key:`1j92g6`}],[`circle`,{cx:`20`,cy:`19`,r:`2`,key:`1obnsp`}]]),r={TOKEN:`algospaced_github_token`,USERNAME:`algospaced_github_username`,REPO:`algospaced_github_repo`,BRANCH:`algospaced_github_branch`,AUTOCOMMIT:`algospaced_github_autocommit`,PRIVATE:`algospaced_github_private`,AVATAR:`algospaced_github_avatar`,NAME:`algospaced_github_name`};function i(){return{token:localStorage.getItem(r.TOKEN)||``,username:localStorage.getItem(r.USERNAME)||``,repoName:localStorage.getItem(r.REPO)||`algospaced-solutions`,branch:localStorage.getItem(r.BRANCH)||`main`,autoCommit:localStorage.getItem(r.AUTOCOMMIT)!==`false`,isPrivate:localStorage.getItem(r.PRIVATE)!==`false`}}function a(){let e=localStorage.getItem(r.USERNAME);return e?{login:e,name:localStorage.getItem(r.NAME)||e,avatar_url:localStorage.getItem(r.AVATAR)||``,html_url:`https://github.com/${e}`}:null}function o(e,t){e.token!==void 0&&localStorage.setItem(r.TOKEN,e.token.trim()),e.username!==void 0&&localStorage.setItem(r.USERNAME,e.username.trim()),e.repoName!==void 0&&localStorage.setItem(r.REPO,e.repoName.trim()),e.branch!==void 0&&localStorage.setItem(r.BRANCH,e.branch.trim()),e.autoCommit!==void 0&&localStorage.setItem(r.AUTOCOMMIT,String(e.autoCommit)),e.isPrivate!==void 0&&localStorage.setItem(r.PRIVATE,String(e.isPrivate)),t&&(t.login&&localStorage.setItem(r.USERNAME,t.login),t.name&&localStorage.setItem(r.NAME,t.name),t.avatar_url&&localStorage.setItem(r.AVATAR,t.avatar_url))}function s(){Object.values(r).forEach(e=>localStorage.removeItem(e))}async function c(){let e=window.open(`/api/github/oauth/login`,`algospaced_github_oauth`,`width=600,height=750,menubar=no,toolbar=no,status=no,location=no`);if(!e)throw Error(`Popup window was blocked by your browser. Please allow popups for AlgoSpaced and try again.`);let t=await new Promise((t,n)=>{let r=null,i=()=>{window.removeEventListener(`message`,a),r!==null&&(clearInterval(r),r=null)},a=e=>{if(!e.data||typeof e.data!=`object`)return;let r=e.data;r.type===`GITHUB_OAUTH_SUCCESS`?(i(),r.token&&typeof r.token==`string`?t(r.token.trim()):n(Error(`GitHub authorization succeeded but no access token was returned.`))):r.type===`GITHUB_OAUTH_ERROR`&&(i(),n(Error(r.error||`GitHub authorization was denied or encountered an error.`)))};window.addEventListener(`message`,a),r=setInterval(()=>{e.closed&&(i(),n(Error(`GitHub authorization window was closed before completing.`)))},1e3)}),n=await l(t);if(!n.valid||!n.user)throw Error(n.error||`Failed to retrieve profile with GitHub token.`);let r=n.user;return o({token:t,username:r.login,repoName:i().repoName||`algospaced-solutions`},r),{token:t,user:r}}async function l(e){let t=await fetch(`/api/github/verify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e.trim()})});return t.ok?await t.json():{valid:!1,error:(await t.json().catch(()=>({}))).detail||`Server returned error (${t.status})`}}async function u(e,t,n=!0){let r=await fetch(`/api/github/init-repo`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e.trim(),repo_name:t.trim(),private:n})});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.detail||`Failed to initialize repository (${r.status})`)}return await r.json()}async function d(e){let t=await fetch(`/api/github/push-solution`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.detail||`Failed to commit solution (${t.status})`)}return await t.json()}async function f(t,n,r=`main`){let{data:{session:i}}=await e.auth.getSession(),a=i?`Bearer ${i.access_token}`:`Bearer sandbox`,o=await fetch(`/api/github/sync-all`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:a},body:JSON.stringify({token:t.trim(),repo:n.trim(),branch:r.trim()})});if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.detail||`Sync failed (${o.status})`)}return await o.json()}export{u as a,f as c,a as i,l,c as n,d as o,i as r,o as s,s as t,n as u};
 
 
algospaced-ui/dist/assets/githubSyncService-CsqBgIfT.js ADDED
@@ -0,0 +1 @@
 
 
1
+ import{i as e}from"./jsx-runtime-j9uSgrFF.js";import{G as t}from"./index-V2pPJO9M.js";var n=t(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),r=t(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),i=t(`folder-git-2`,[[`path`,{d:`M18 19a5 5 0 0 1-5-5v8`,key:`sz5oeg`}],[`path`,{d:`M9 20H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H20a2 2 0 0 1 2 2v5`,key:`1w6njk`}],[`circle`,{cx:`13`,cy:`12`,r:`2`,key:`1j92g6`}],[`circle`,{cx:`20`,cy:`19`,r:`2`,key:`1obnsp`}]]),a={TOKEN:`algospaced_github_token`,USERNAME:`algospaced_github_username`,REPO:`algospaced_github_repo`,BRANCH:`algospaced_github_branch`,AUTOCOMMIT:`algospaced_github_autocommit`,PRIVATE:`algospaced_github_private`,AVATAR:`algospaced_github_avatar`,NAME:`algospaced_github_name`};function o(){return{token:localStorage.getItem(a.TOKEN)||``,username:localStorage.getItem(a.USERNAME)||``,repoName:localStorage.getItem(a.REPO)||`algospaced-solutions`,branch:localStorage.getItem(a.BRANCH)||`main`,autoCommit:localStorage.getItem(a.AUTOCOMMIT)!==`false`,isPrivate:localStorage.getItem(a.PRIVATE)!==`false`}}function s(){let e=localStorage.getItem(a.USERNAME);return e?{login:e,name:localStorage.getItem(a.NAME)||e,avatar_url:localStorage.getItem(a.AVATAR)||``,html_url:`https://github.com/${e}`}:null}function c(e,t){e.token!==void 0&&localStorage.setItem(a.TOKEN,e.token.trim()),e.username!==void 0&&localStorage.setItem(a.USERNAME,e.username.trim()),e.repoName!==void 0&&localStorage.setItem(a.REPO,e.repoName.trim()),e.branch!==void 0&&localStorage.setItem(a.BRANCH,e.branch.trim()),e.autoCommit!==void 0&&localStorage.setItem(a.AUTOCOMMIT,String(e.autoCommit)),e.isPrivate!==void 0&&localStorage.setItem(a.PRIVATE,String(e.isPrivate)),t&&(t.login&&localStorage.setItem(a.USERNAME,t.login),t.name&&localStorage.setItem(a.NAME,t.name),t.avatar_url&&localStorage.setItem(a.AVATAR,t.avatar_url))}function l(){Object.values(a).forEach(e=>localStorage.removeItem(e))}async function u(){let e=window.open(`/api/github/oauth/login`,`algospaced_github_oauth`,`width=600,height=750,menubar=no,toolbar=no,status=no,location=no`);if(!e)throw Error(`Popup window was blocked by your browser. Please allow popups for AlgoSpaced and try again.`);let t=await new Promise((t,n)=>{let r=null,i=()=>{window.removeEventListener(`message`,a),r!==null&&(clearInterval(r),r=null)},a=e=>{if(!e.data||typeof e.data!=`object`)return;let r=e.data;r.type===`GITHUB_OAUTH_SUCCESS`?(i(),r.token&&typeof r.token==`string`?t(r.token.trim()):n(Error(`GitHub authorization succeeded but no access token was returned.`))):r.type===`GITHUB_OAUTH_ERROR`&&(i(),n(Error(r.error||`GitHub authorization was denied or encountered an error.`)))};window.addEventListener(`message`,a),r=setInterval(()=>{e.closed&&(i(),n(Error(`GitHub authorization window was closed before completing.`)))},1e3)}),n=await d(t);if(!n.valid||!n.user)throw Error(n.error||`Failed to retrieve profile with GitHub token.`);let r=n.user;return c({token:t,username:r.login,repoName:o().repoName||`algospaced-solutions`},r),{token:t,user:r}}async function d(e){let t=await fetch(`/api/github/verify`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e.trim()})});return t.ok?await t.json():{valid:!1,error:(await t.json().catch(()=>({}))).detail||`Server returned error (${t.status})`}}async function f(e,t,n=!0){let r=await fetch(`/api/github/init-repo`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({token:e.trim(),repo_name:t.trim(),private:n})});if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.detail||`Failed to initialize repository (${r.status})`)}return await r.json()}async function p(e){let t=await fetch(`/api/github/push-solution`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e)});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.detail||`Failed to commit solution (${t.status})`)}return await t.json()}async function m(t,n,r=`main`){let{data:{session:i}}=await e.auth.getSession(),a=i?`Bearer ${i.access_token}`:`Bearer sandbox`,o=await fetch(`/api/github/sync-all`,{method:`POST`,headers:{"Content-Type":`application/json`,Authorization:a},body:JSON.stringify({token:t.trim(),repo:n.trim(),branch:r.trim()})});if(!o.ok){let e=await o.json().catch(()=>({}));throw Error(e.detail||`Sync failed (${o.status})`)}return await o.json()}export{f as a,m as c,r as d,n as f,s as i,d as l,u as n,p as o,o as r,c as s,l as t,i as u};
algospaced-ui/dist/assets/index-B05nv6MT.css ADDED
The diff for this file is too large to render. See raw diff
 
algospaced-ui/dist/assets/{index-g5jVBiGr.js → index-V2pPJO9M.js} RENAMED
The diff for this file is too large to render. See raw diff
 
algospaced-ui/dist/assets/index-Y3EVepB8.css DELETED
The diff for this file is too large to render. See raw diff
 
algospaced-ui/dist/assets/{info-CU16dSEt.js → info-CAmdZoA6.js} RENAMED
@@ -1 +1 @@
1
- import{U as e}from"./index-g5jVBiGr.js";var t=e(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]);export{t};
 
1
+ import{G as e}from"./index-V2pPJO9M.js";var t=e(`info`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]);export{t};
algospaced-ui/dist/assets/{save-CdpRk537.js → save-BgzMM0iu.js} RENAMED
@@ -1 +1 @@
1
- import{U as e}from"./index-g5jVBiGr.js";var t=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]);export{t};
 
1
+ import{G as e}from"./index-V2pPJO9M.js";var t=e(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]);export{t};
algospaced-ui/dist/index.html CHANGED
@@ -13,9 +13,9 @@
13
  <link
14
  href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&amp;family=Be+Vietnam+Pro:wght@500;700&amp;family=Courier+Prime:wght@400;700&amp;family=Press+Start+2P&amp;family=Cinzel:wght@500;700;900&amp;family=Cinzel+Decorative:wght@700;900&amp;family=EB+Garamond:ital,wght@0,400;0,600;1,400;1,600&amp;family=Kalam:wght@400;700&amp;display=swap"
15
  rel="stylesheet" />
16
- <script type="module" crossorigin src="/assets/index-g5jVBiGr.js"></script>
17
  <link rel="modulepreload" crossorigin href="/assets/jsx-runtime-j9uSgrFF.js">
18
- <link rel="stylesheet" crossorigin href="/assets/index-Y3EVepB8.css">
19
  <link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
20
 
21
  <body>
 
13
  <link
14
  href="https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,700;12..96,800&amp;family=Be+Vietnam+Pro:wght@500;700&amp;family=Courier+Prime:wght@400;700&amp;family=Press+Start+2P&amp;family=Cinzel:wght@500;700;900&amp;family=Cinzel+Decorative:wght@700;900&amp;family=EB+Garamond:ital,wght@0,400;0,600;1,400;1,600&amp;family=Kalam:wght@400;700&amp;display=swap"
15
  rel="stylesheet" />
16
+ <script type="module" crossorigin src="/assets/index-V2pPJO9M.js"></script>
17
  <link rel="modulepreload" crossorigin href="/assets/jsx-runtime-j9uSgrFF.js">
18
+ <link rel="stylesheet" crossorigin href="/assets/index-B05nv6MT.css">
19
  <link rel="manifest" href="/manifest.webmanifest"><script id="vite-plugin-pwa:register-sw" src="/registerSW.js"></script></head>
20
 
21
  <body>
algospaced-ui/dist/sw.js CHANGED
@@ -1 +1 @@
1
- if(!self.define){let s,e={};const l=(l,i)=>(l=new URL(l+".js",i).href,e[l]||new Promise(e=>{if("document"in self){const s=document.createElement("script");s.src=l,s.onload=e,document.head.appendChild(s)}else s=l,importScripts(l),e()}).then(()=>{let s=e[l];if(!s)throw new Error(`Module ${l} didn’t register its module`);return s}));self.define=(i,n)=>{const r=s||("document"in self?document.currentScript.src:"")||location.href;if(e[r])return;let u={};const t=s=>l(s,r),o={module:{uri:r},exports:u,require:t};e[r]=Promise.all(i.map(s=>o[s]||t(s))).then(s=>(n(...s),u))}}define(["./workbox-9c191d2f"],function(s){"use strict";self.skipWaiting(),s.clientsClaim(),s.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"ee6abb5e1d45cec355052325429ccafa"},{url:"assets/TerminalEmulator-CI1oWIOR.js",revision:null},{url:"assets/Settings-Cz_GHQn5.js",revision:null},{url:"assets/save-CdpRk537.js",revision:null},{url:"assets/ReviewQueue-BCTxdw81.js",revision:null},{url:"assets/PythonChallenge-Bfcp7_2V.js",revision:null},{url:"assets/PrincessChamber-Cu4RP8Ry.js",revision:null},{url:"assets/MySQLPlayground-BdJWX3_8.js",revision:null},{url:"assets/jsx-runtime-j9uSgrFF.js",revision:null},{url:"assets/JourneyPath-Dg9Be99S.js",revision:null},{url:"assets/info-CU16dSEt.js",revision:null},{url:"assets/index-Y3EVepB8.css",revision:null},{url:"assets/index-g5jVBiGr.js",revision:null},{url:"assets/GitHubSyncWindow-DGw-FVNu.js",revision:null},{url:"assets/githubSyncService--4Z5jmjP.js",revision:null},{url:"assets/FileExplorer-CRW7B6yJ.js",revision:null},{url:"assets/eye-DeJ_5v51.js",revision:null},{url:"assets/external-link-yb1gedrc.js",revision:null},{url:"assets/CreateProblemForm-1KsGQ8w8.js",revision:null},{url:"assets/confetti.module-BEqdENp8.js",revision:null},{url:"manifest.webmanifest",revision:"7c8ff056d2e188c868d851bcb349e28e"}],{}),s.cleanupOutdatedCaches(),s.registerRoute(new s.NavigationRoute(s.createHandlerBoundToURL("index.html")))});
 
1
+ if(!self.define){let s,e={};const l=(l,n)=>(l=new URL(l+".js",n).href,e[l]||new Promise(e=>{if("document"in self){const s=document.createElement("script");s.src=l,s.onload=e,document.head.appendChild(s)}else s=l,importScripts(l),e()}).then(()=>{let s=e[l];if(!s)throw new Error(`Module ${l} didn’t register its module`);return s}));self.define=(n,i)=>{const r=s||("document"in self?document.currentScript.src:"")||location.href;if(e[r])return;let u={};const t=s=>l(s,r),o={module:{uri:r},exports:u,require:t};e[r]=Promise.all(n.map(s=>o[s]||t(s))).then(s=>(i(...s),u))}}define(["./workbox-9c191d2f"],function(s){"use strict";self.skipWaiting(),s.clientsClaim(),s.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"834860cdeecf27887bf032636cab8c90"},{url:"assets/TerminalEmulator-CI1oWIOR.js",revision:null},{url:"assets/Settings-C3gzd0DF.js",revision:null},{url:"assets/save-BgzMM0iu.js",revision:null},{url:"assets/ReviewQueue-CYwGYMOV.js",revision:null},{url:"assets/PythonChallenge-3lpSHvfF.js",revision:null},{url:"assets/PrincessChamber-CXQLBBNW.js",revision:null},{url:"assets/MySQLPlayground-BdJWX3_8.js",revision:null},{url:"assets/jsx-runtime-j9uSgrFF.js",revision:null},{url:"assets/JourneyPath-BXnxFEFy.js",revision:null},{url:"assets/info-CAmdZoA6.js",revision:null},{url:"assets/index-V2pPJO9M.js",revision:null},{url:"assets/index-B05nv6MT.css",revision:null},{url:"assets/GitHubSyncWindow-Ca288SgB.js",revision:null},{url:"assets/githubSyncService-CsqBgIfT.js",revision:null},{url:"assets/FileExplorer-CRW7B6yJ.js",revision:null},{url:"assets/external-link-BGZfX5Bi.js",revision:null},{url:"assets/CreateProblemForm-Cu_hnDPM.js",revision:null},{url:"assets/confetti.module-nUzO7Zin.js",revision:null},{url:"assets/circle-alert-BL6bvZTM.js",revision:null},{url:"manifest.webmanifest",revision:"7c8ff056d2e188c868d851bcb349e28e"}],{}),s.cleanupOutdatedCaches(),s.registerRoute(new s.NavigationRoute(s.createHandlerBoundToURL("index.html")))});
algospaced-ui/src/components/CreateProblemForm.tsx CHANGED
@@ -1,6 +1,6 @@
1
  import React, { useState } from 'react';
2
  import { supabase } from '../firebaseClient';
3
- import type { ProblemItem } from '../types/reviewTypes';
4
 
5
  interface CreateProblemFormProps {
6
  onClose: () => void;
@@ -36,6 +36,13 @@ const COMMON_PATTERNS = [
36
  'Bit Manipulation'
37
  ];
38
 
 
 
 
 
 
 
 
39
  export default function CreateProblemForm({
40
  onClose,
41
  onSuccess,
@@ -89,7 +96,7 @@ export default function CreateProblemForm({
89
  });
90
 
91
  const [newFileOptimalTime, setNewFileOptimalTime] = useState(() => initialProblem?.optimal_time || 'O(N)');
92
- const [newFileOptimalSpace, setNewFileOptimalSpace] = useState(() => initialProblem?.optimal_space || 'O(N)');
93
  const [newFileDescription, setNewFileDescription] = useState(() => initialProblem?.description || '');
94
 
95
  const [newFileExamples, setNewFileExamples] = useState<ExampleItem[]>(() => {
@@ -126,6 +133,107 @@ export default function CreateProblemForm({
126
  return '';
127
  });
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  // Dual-write & Status
130
  const [syncToGDoc, setSyncToGDoc] = useState(true);
131
  const [createError, setCreateError] = useState('');
@@ -187,6 +295,18 @@ export default function CreateProblemForm({
187
  if (data.how_to_solve) setNewFileHowToSolve(data.how_to_solve);
188
  if (data.starter_code && !newFileCode.trim()) setNewFileCode(data.starter_code);
189
 
 
 
 
 
 
 
 
 
 
 
 
 
190
  if (Array.isArray(data.examples) && data.examples.length > 0) {
191
  setNewFileExamples(data.examples);
192
  }
@@ -208,7 +328,8 @@ export default function CreateProblemForm({
208
 
209
  // 1b. AI Prefill based on Problem Title / Code
210
  const handlePrefill = async () => {
211
- if (!newFileName.trim() && !newFileCode.trim()) return;
 
212
  setPrefilling(true);
213
  setCreateError('');
214
  try {
@@ -216,7 +337,7 @@ export default function CreateProblemForm({
216
  const res = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/explorer/problems/prefill`, {
217
  method: 'POST',
218
  headers,
219
- body: JSON.stringify({ name: newFileName, code: newFileCode })
220
  });
221
  if (res.ok) {
222
  const data = await res.json();
@@ -229,7 +350,18 @@ export default function CreateProblemForm({
229
  if (data.optimal_time) setNewFileOptimalTime(data.optimal_time);
230
  if (data.optimal_space) setNewFileOptimalSpace(data.optimal_space);
231
  if (data.description) setNewFileDescription(data.description);
232
- if (data.reference_code && !newFileCode.trim()) setNewFileCode(data.reference_code);
 
 
 
 
 
 
 
 
 
 
 
233
  } else {
234
  const errData = await res.json();
235
  setCreateError(errData.detail || 'Prefill failed.');
@@ -243,7 +375,8 @@ export default function CreateProblemForm({
243
 
244
  // 2. AI Assist: Generate "How to solve?" Intuition
245
  const handleGenerateIntuition = async () => {
246
- if (!newFileName.trim() && !newFileCode.trim()) {
 
247
  setCreateError('Please enter a problem name or code first.');
248
  return;
249
  }
@@ -257,7 +390,7 @@ export default function CreateProblemForm({
257
  body: JSON.stringify({
258
  field: 'intuition',
259
  title: newFileName,
260
- code: newFileCode,
261
  description: newFileDescription
262
  })
263
  });
@@ -266,6 +399,7 @@ export default function CreateProblemForm({
266
  const data = await res.json();
267
  if (data.how_to_solve) {
268
  setNewFileHowToSolve(data.how_to_solve);
 
269
  }
270
  } else {
271
  const errData = await res.json();
@@ -280,7 +414,8 @@ export default function CreateProblemForm({
280
 
281
  // 3. AI Assist: Format Code with Step-by-Step Comments
282
  const handleFormatCode = async () => {
283
- if (!newFileCode.trim()) {
 
284
  setCreateError('Please enter some Python code to format.');
285
  return;
286
  }
@@ -294,7 +429,7 @@ export default function CreateProblemForm({
294
  body: JSON.stringify({
295
  field: 'comments',
296
  title: newFileName,
297
- code: newFileCode
298
  })
299
  });
300
 
@@ -302,6 +437,7 @@ export default function CreateProblemForm({
302
  const data = await res.json();
303
  if (data.formatted_code) {
304
  setNewFileCode(data.formatted_code);
 
305
  }
306
  } else {
307
  const errData = await res.json();
@@ -332,6 +468,13 @@ export default function CreateProblemForm({
332
  .map(c => c.trim())
333
  .filter(Boolean);
334
 
 
 
 
 
 
 
 
335
  let res: Response;
336
  if (isEditMode && initialProblem) {
337
  const targetId = initialProblem.id || (initialProblem.problem_number ? String(initialProblem.problem_number) : '') || newFileName.trim();
@@ -340,16 +483,17 @@ export default function CreateProblemForm({
340
  headers,
341
  body: JSON.stringify({
342
  name: newFileName.trim(),
343
- pattern: newFilePattern.trim() || 'General',
344
  difficulty: newFileDifficulty,
345
- reference_code: newFileCode,
346
  description: newFileDescription,
347
  problem_number: newFileProblemNumber === '' ? null : Number(newFileProblemNumber),
348
- optimal_time: newFileOptimalTime,
349
- optimal_space: newFileOptimalSpace,
350
  examples: newFileExamples.filter(ex => ex.input.trim() || ex.output.trim()),
351
  constraints: constraintsList,
352
- how_to_solve: newFileHowToSolve
 
353
  })
354
  });
355
  } else {
@@ -358,17 +502,18 @@ export default function CreateProblemForm({
358
  headers,
359
  body: JSON.stringify({
360
  name: newFileName.trim(),
361
- pattern: newFilePattern.trim() || 'General',
362
  difficulty: newFileDifficulty,
363
- reference_code: newFileCode,
364
  description: newFileDescription,
365
  problem_number: newFileProblemNumber === '' ? null : Number(newFileProblemNumber),
366
- optimal_time: newFileOptimalTime,
367
- optimal_space: newFileOptimalSpace,
368
  examples: newFileExamples.filter(ex => ex.input.trim() || ex.output.trim()),
369
  constraints: constraintsList,
370
- how_to_solve: newFileHowToSolve,
371
- sync_to_gdoc: syncToGDoc
 
372
  })
373
  });
374
  }
@@ -499,7 +644,7 @@ export default function CreateProblemForm({
499
  <button
500
  type="button"
501
  onClick={handlePrefill}
502
- disabled={prefilling || (!newFileName.trim() && !newFileCode.trim())}
503
  className="text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer"
504
  >
505
  <span>✦</span> {prefilling ? '...' : 'AUTO-FILL'}
@@ -534,42 +679,36 @@ export default function CreateProblemForm({
534
  </div>
535
  </div>
536
 
537
- {/* Row 2: Pattern & Complexities */}
538
- <div className="grid grid-cols-3 gap-2">
539
  <div className="flex flex-col gap-1">
540
- <label className="text-[10px] font-bold text-slate-600 uppercase">Pattern / Topic:</label>
541
- <input
542
- type="text"
543
- list="pattern-suggestions"
544
- value={newFilePattern}
545
- onChange={(e) => setNewFilePattern(e.target.value)}
546
- placeholder="e.g. Arrays & Hashing"
547
- className="bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium"
548
- />
549
- <datalist id="pattern-suggestions">
550
- {COMMON_PATTERNS.map(p => (
551
- <option key={p} value={p} />
552
- ))}
553
- </datalist>
554
- </div>
555
- <div className="flex flex-col gap-1">
556
- <label className="text-[10px] font-bold text-slate-600 uppercase">Time Complexity:</label>
557
  <input
558
  type="text"
559
  value={newFileOptimalTime}
560
  onChange={(e) => setNewFileOptimalTime(e.target.value)}
561
  placeholder="e.g. O(N)"
562
- className="bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-semibold"
563
  />
564
  </div>
565
  <div className="flex flex-col gap-1">
566
- <label className="text-[10px] font-bold text-slate-600 uppercase">Space Complexity:</label>
 
 
 
 
 
567
  <input
568
  type="text"
569
  value={newFileOptimalSpace}
570
  onChange={(e) => setNewFileOptimalSpace(e.target.value)}
571
  placeholder="e.g. O(1)"
572
- className="bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-semibold"
573
  />
574
  </div>
575
  </div>
@@ -608,7 +747,7 @@ export default function CreateProblemForm({
608
  <button
609
  type="button"
610
  onClick={() => removeExample(idx)}
611
- className="text-[10px] text-red-600 hover:text-red-800 font-bold"
612
  >
613
  ✕
614
  </button>
@@ -652,50 +791,175 @@ export default function CreateProblemForm({
652
  />
653
  </div>
654
 
655
- {/* Row 6: "How to solve?" Intuition with AI Generator */}
656
- <div className="flex flex-col gap-1">
657
- <div className="flex justify-between items-center">
658
- <label className="text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1">
659
- <span>💡</span> "How to solve?" Intuition:
660
- </label>
 
 
 
 
 
 
661
  <button
662
  type="button"
663
- onClick={handleGenerateIntuition}
664
- disabled={loadingIntuition}
665
- className="text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 shadow-[1px_1px_0px_#1E293B] cursor-pointer"
666
  >
667
- <span>✦</span> {loadingIntuition ? 'GENERATING...' : 'AI INTUITION'}
668
  </button>
669
  </div>
670
- <textarea
671
- value={newFileHowToSolve}
672
- onChange={(e) => setNewFileHowToSolve(e.target.value)}
673
- placeholder="Explain the mental model, dummy nodes, invariants, or two-pointer logic..."
674
- className="bg-white border-2 border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-24 resize-y leading-relaxed"
675
- />
676
- </div>
677
 
678
- {/* Row 7: Reference Python Code with Emoji Comments Assist */}
679
- <div className="flex flex-col gap-1">
680
- <div className="flex justify-between items-center">
681
- <label className="text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1">
682
- <span>🐍</span> Solution Code (Python):
683
- </label>
684
- <button
685
- type="button"
686
- onClick={handleFormatCode}
687
- disabled={loadingComments || !newFileCode.trim()}
688
- className="text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black bg-[#a7f3d0] hover:bg-emerald-300 disabled:opacity-50 flex items-center gap-1 shadow-[1px_1px_0px_#1E293B] cursor-pointer text-emerald-950"
689
- >
690
- <span>✨</span> {loadingComments ? 'FORMATTING...' : 'ADD EMOJI COMMENTS'}
691
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  </div>
693
- <textarea
694
- value={newFileCode}
695
- onChange={(e) => setNewFileCode(e.target.value)}
696
- placeholder="def twoSum(nums: list[int], target: int) -> list[int]:&#10; # 1. 🗺️ Initialize lookup map&#10; seen = {}&#10; ...&#10; return []"
697
- className="bg-slate-900 text-[#4ADE80] font-mono p-2.5 border-2 border-ink-black rounded outline-none h-44 text-xs leading-relaxed resize-y w-full"
698
- />
699
  </div>
700
  </>
701
  ) : (
@@ -775,45 +1039,57 @@ export default function CreateProblemForm({
775
  </div>
776
  )}
777
 
778
- {/* Method / Pattern */}
779
- <div className="pt-2">
780
- <div className="font-bold text-xs text-slate-800">Method:</div>
781
- <div className="text-xs text-slate-600">Pattern:</div>
782
- <h3 className="text-base font-bold text-primary-purple mt-0.5">
783
- {newFilePattern || 'Standard'}
784
- </h3>
785
- </div>
786
-
787
- {/* Complexities */}
788
- <div className="space-y-1 text-xs">
789
- <div>
790
- <span className="font-bold text-slate-800">Time Complexity: </span>
791
- <span className="font-mono text-slate-900">{newFileOptimalTime}</span>
792
- </div>
793
- <div>
794
- <span className="font-bold text-slate-800">Space Complexity: </span>
795
- <span className="font-mono text-slate-900">{newFileOptimalSpace}</span>
796
  </div>
797
  </div>
798
 
799
- {/* How to solve? */}
800
- {newFileHowToSolve && (
801
- <div className="space-y-1.5 pt-2">
802
- <h3 className="text-sm font-bold text-slate-900">How to solve?</h3>
803
- <div className="text-xs text-slate-700 leading-relaxed whitespace-pre-wrap">
804
- {newFileHowToSolve}
805
- </div>
806
  </div>
807
- )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
808
 
809
- {/* Code */}
810
- {newFileCode && (
811
- <div className="pt-2">
812
- <div className="bg-[#f8fafc] border border-slate-300 p-3 rounded font-mono text-[11.5px] leading-relaxed text-slate-900 overflow-x-auto whitespace-pre">
813
- {newFileCode}
 
 
 
 
 
 
 
 
 
 
 
814
  </div>
815
- </div>
816
- )}
817
  </div>
818
  )}
819
  </div>
 
1
  import React, { useState } from 'react';
2
  import { supabase } from '../firebaseClient';
3
+ import type { ProblemItem, ProblemSolution } from '../types/reviewTypes';
4
 
5
  interface CreateProblemFormProps {
6
  onClose: () => void;
 
36
  'Bit Manipulation'
37
  ];
38
 
39
+ function generateSolutionId(): string {
40
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
41
+ return `sol-${crypto.randomUUID()}`;
42
+ }
43
+ return `sol-${Date.now()}`;
44
+ }
45
+
46
  export default function CreateProblemForm({
47
  onClose,
48
  onSuccess,
 
96
  });
97
 
98
  const [newFileOptimalTime, setNewFileOptimalTime] = useState(() => initialProblem?.optimal_time || 'O(N)');
99
+ const [newFileOptimalSpace, setNewFileOptimalSpace] = useState(() => initialProblem?.optimal_space || 'O(1)');
100
  const [newFileDescription, setNewFileDescription] = useState(() => initialProblem?.description || '');
101
 
102
  const [newFileExamples, setNewFileExamples] = useState<ExampleItem[]>(() => {
 
133
  return '';
134
  });
135
 
136
+ // Multi-solution state
137
+ const [solutions, setSolutions] = useState<ProblemSolution[]>(() => {
138
+ if (initialProblem?.solutions && Array.isArray(initialProblem.solutions) && initialProblem.solutions.length > 0) {
139
+ return initialProblem.solutions.map((s, idx) => ({
140
+ id: s.id || `sol-${idx + 1}`,
141
+ name: s.name || `Method ${idx + 1}`,
142
+ pattern: s.pattern || initialProblem.pattern || 'Arrays & Hashing',
143
+ time_complexity: s.time_complexity || initialProblem.optimal_time || 'O(N)',
144
+ space_complexity: s.space_complexity || initialProblem.optimal_space || 'O(1)',
145
+ code: s.code || '',
146
+ explanation: s.explanation || '',
147
+ is_optimal: s.is_optimal ?? (idx === 0)
148
+ }));
149
+ }
150
+
151
+ let initCode = initialProblem?.reference_code || '';
152
+ let initPattern = initialProblem?.pattern || 'Arrays & Hashing';
153
+ try {
154
+ const draft = localStorage.getItem('algospaced_prefill_draft');
155
+ if (draft) {
156
+ const parsed = JSON.parse(draft);
157
+ if (parsed.code && !initCode) initCode = parsed.code;
158
+ if (parsed.pattern && !initPattern) initPattern = parsed.pattern;
159
+ }
160
+ } catch {
161
+ /* ignore invalid json */
162
+ }
163
+
164
+ return [
165
+ {
166
+ id: 'sol-1',
167
+ name: 'Optimal Method',
168
+ pattern: initPattern,
169
+ time_complexity: initialProblem?.optimal_time || 'O(N)',
170
+ space_complexity: initialProblem?.optimal_space || 'O(1)',
171
+ code: initCode,
172
+ explanation: (initialProblem as { how_to_solve?: string } | undefined)?.how_to_solve || '',
173
+ is_optimal: true
174
+ }
175
+ ];
176
+ });
177
+ const [activeSolutionIdx, setActiveSolutionIdx] = useState(0);
178
+
179
+ const activeSolution = solutions[activeSolutionIdx] || solutions[0] || {
180
+ id: 'sol-1',
181
+ name: 'Method 1',
182
+ pattern: 'Arrays & Hashing',
183
+ time_complexity: 'O(N)',
184
+ space_complexity: 'O(1)',
185
+ code: '',
186
+ explanation: '',
187
+ is_optimal: true
188
+ };
189
+
190
+ const updateActiveSolution = (updates: Partial<ProblemSolution>) => {
191
+ setSolutions(prev => {
192
+ const next = [...prev];
193
+ const targetIdx = activeSolutionIdx < next.length ? activeSolutionIdx : 0;
194
+ next[targetIdx] = { ...next[targetIdx], ...updates };
195
+ if (updates.is_optimal) {
196
+ next.forEach((s, idx) => {
197
+ if (idx !== targetIdx) s.is_optimal = false;
198
+ });
199
+ if (next[targetIdx].time_complexity) setNewFileOptimalTime(next[targetIdx].time_complexity);
200
+ if (next[targetIdx].space_complexity) setNewFileOptimalSpace(next[targetIdx].space_complexity);
201
+ if (next[targetIdx].pattern) setNewFilePattern(next[targetIdx].pattern);
202
+ }
203
+ return next;
204
+ });
205
+ };
206
+
207
+ const addSolution = () => {
208
+ const nextNum = solutions.length + 1;
209
+ const newSol: ProblemSolution = {
210
+ id: generateSolutionId(),
211
+ name: `Method ${nextNum}`,
212
+ pattern: newFilePattern || 'Arrays & Hashing',
213
+ time_complexity: 'O(N)',
214
+ space_complexity: 'O(1)',
215
+ code: '',
216
+ explanation: '',
217
+ is_optimal: solutions.length === 0
218
+ };
219
+ setSolutions(prev => [...prev, newSol]);
220
+ setActiveSolutionIdx(solutions.length);
221
+ };
222
+
223
+ const removeSolution = (idxToRemove: number) => {
224
+ if (solutions.length <= 1) return;
225
+ setSolutions(prev => {
226
+ const next = prev.filter((_, i) => i !== idxToRemove);
227
+ if (!next.some(s => s.is_optimal)) {
228
+ next[0].is_optimal = true;
229
+ }
230
+ return next;
231
+ });
232
+ if (activeSolutionIdx >= solutions.length - 1) {
233
+ setActiveSolutionIdx(Math.max(0, solutions.length - 2));
234
+ }
235
+ };
236
+
237
  // Dual-write & Status
238
  const [syncToGDoc, setSyncToGDoc] = useState(true);
239
  const [createError, setCreateError] = useState('');
 
295
  if (data.how_to_solve) setNewFileHowToSolve(data.how_to_solve);
296
  if (data.starter_code && !newFileCode.trim()) setNewFileCode(data.starter_code);
297
 
298
+ setSolutions(prev => {
299
+ const next = [...prev];
300
+ const active = { ...next[activeSolutionIdx] };
301
+ if (data.pattern) active.pattern = data.pattern;
302
+ if (data.optimal_time) active.time_complexity = data.optimal_time;
303
+ if (data.optimal_space) active.space_complexity = data.optimal_space;
304
+ if (data.how_to_solve) active.explanation = data.how_to_solve;
305
+ if (data.starter_code && !active.code?.trim()) active.code = data.starter_code;
306
+ next[activeSolutionIdx] = active;
307
+ return next;
308
+ });
309
+
310
  if (Array.isArray(data.examples) && data.examples.length > 0) {
311
  setNewFileExamples(data.examples);
312
  }
 
328
 
329
  // 1b. AI Prefill based on Problem Title / Code
330
  const handlePrefill = async () => {
331
+ const codeToUse = activeSolution.code || newFileCode;
332
+ if (!newFileName.trim() && !codeToUse.trim()) return;
333
  setPrefilling(true);
334
  setCreateError('');
335
  try {
 
337
  const res = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/explorer/problems/prefill`, {
338
  method: 'POST',
339
  headers,
340
+ body: JSON.stringify({ name: newFileName, code: codeToUse })
341
  });
342
  if (res.ok) {
343
  const data = await res.json();
 
350
  if (data.optimal_time) setNewFileOptimalTime(data.optimal_time);
351
  if (data.optimal_space) setNewFileOptimalSpace(data.optimal_space);
352
  if (data.description) setNewFileDescription(data.description);
353
+ if (data.reference_code && !codeToUse.trim()) setNewFileCode(data.reference_code);
354
+
355
+ setSolutions(prev => {
356
+ const next = [...prev];
357
+ const active = { ...next[activeSolutionIdx] };
358
+ if (data.pattern) active.pattern = data.pattern;
359
+ if (data.optimal_time) active.time_complexity = data.optimal_time;
360
+ if (data.optimal_space) active.space_complexity = data.optimal_space;
361
+ if (data.reference_code && !active.code?.trim()) active.code = data.reference_code;
362
+ next[activeSolutionIdx] = active;
363
+ return next;
364
+ });
365
  } else {
366
  const errData = await res.json();
367
  setCreateError(errData.detail || 'Prefill failed.');
 
375
 
376
  // 2. AI Assist: Generate "How to solve?" Intuition
377
  const handleGenerateIntuition = async () => {
378
+ const codeToUse = activeSolution.code || newFileCode;
379
+ if (!newFileName.trim() && !codeToUse.trim()) {
380
  setCreateError('Please enter a problem name or code first.');
381
  return;
382
  }
 
390
  body: JSON.stringify({
391
  field: 'intuition',
392
  title: newFileName,
393
+ code: codeToUse,
394
  description: newFileDescription
395
  })
396
  });
 
399
  const data = await res.json();
400
  if (data.how_to_solve) {
401
  setNewFileHowToSolve(data.how_to_solve);
402
+ updateActiveSolution({ explanation: data.how_to_solve });
403
  }
404
  } else {
405
  const errData = await res.json();
 
414
 
415
  // 3. AI Assist: Format Code with Step-by-Step Comments
416
  const handleFormatCode = async () => {
417
+ const codeToUse = activeSolution.code || newFileCode;
418
+ if (!codeToUse.trim()) {
419
  setCreateError('Please enter some Python code to format.');
420
  return;
421
  }
 
429
  body: JSON.stringify({
430
  field: 'comments',
431
  title: newFileName,
432
+ code: codeToUse
433
  })
434
  });
435
 
 
437
  const data = await res.json();
438
  if (data.formatted_code) {
439
  setNewFileCode(data.formatted_code);
440
+ updateActiveSolution({ code: data.formatted_code });
441
  }
442
  } else {
443
  const errData = await res.json();
 
468
  .map(c => c.trim())
469
  .filter(Boolean);
470
 
471
+ const optimalSol = solutions.find(s => s.is_optimal) || solutions[0];
472
+ const finalPattern = optimalSol?.pattern || newFilePattern.trim() || 'General';
473
+ const finalCode = optimalSol?.code || newFileCode;
474
+ const finalHowToSolve = optimalSol?.explanation || newFileHowToSolve;
475
+ const finalOptimalTime = newFileOptimalTime || optimalSol?.time_complexity || 'O(N)';
476
+ const finalOptimalSpace = newFileOptimalSpace || optimalSol?.space_complexity || 'O(1)';
477
+
478
  let res: Response;
479
  if (isEditMode && initialProblem) {
480
  const targetId = initialProblem.id || (initialProblem.problem_number ? String(initialProblem.problem_number) : '') || newFileName.trim();
 
483
  headers,
484
  body: JSON.stringify({
485
  name: newFileName.trim(),
486
+ pattern: finalPattern,
487
  difficulty: newFileDifficulty,
488
+ reference_code: finalCode,
489
  description: newFileDescription,
490
  problem_number: newFileProblemNumber === '' ? null : Number(newFileProblemNumber),
491
+ optimal_time: finalOptimalTime,
492
+ optimal_space: finalOptimalSpace,
493
  examples: newFileExamples.filter(ex => ex.input.trim() || ex.output.trim()),
494
  constraints: constraintsList,
495
+ how_to_solve: finalHowToSolve,
496
+ solutions: solutions
497
  })
498
  });
499
  } else {
 
502
  headers,
503
  body: JSON.stringify({
504
  name: newFileName.trim(),
505
+ pattern: finalPattern,
506
  difficulty: newFileDifficulty,
507
+ reference_code: finalCode,
508
  description: newFileDescription,
509
  problem_number: newFileProblemNumber === '' ? null : Number(newFileProblemNumber),
510
+ optimal_time: finalOptimalTime,
511
+ optimal_space: finalOptimalSpace,
512
  examples: newFileExamples.filter(ex => ex.input.trim() || ex.output.trim()),
513
  constraints: constraintsList,
514
+ how_to_solve: finalHowToSolve,
515
+ sync_to_gdoc: syncToGDoc,
516
+ solutions: solutions
517
  })
518
  });
519
  }
 
644
  <button
645
  type="button"
646
  onClick={handlePrefill}
647
+ disabled={prefilling || (!newFileName.trim() && !activeSolution.code?.trim())}
648
  className="text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer"
649
  >
650
  <span>✦</span> {prefilling ? '...' : 'AUTO-FILL'}
 
679
  </div>
680
  </div>
681
 
682
+ {/* Row 2: Target Optimal Complexities (Active Recall Shielded on Review) */}
683
+ <div className="grid grid-cols-2 gap-2 bg-[#f6edd2] p-2 border-2 border-ink-black rounded">
684
  <div className="flex flex-col gap-1">
685
+ <div className="flex items-center justify-between">
686
+ <label className="text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1">
687
+ <span>⏱️</span> Target Optimal Time:
688
+ </label>
689
+ <span className="text-[8px] font-mono text-slate-500">(hidden behind spoiler on review)</span>
690
+ </div>
 
 
 
 
 
 
 
 
 
 
 
691
  <input
692
  type="text"
693
  value={newFileOptimalTime}
694
  onChange={(e) => setNewFileOptimalTime(e.target.value)}
695
  placeholder="e.g. O(N)"
696
+ className="bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-bold"
697
  />
698
  </div>
699
  <div className="flex flex-col gap-1">
700
+ <div className="flex items-center justify-between">
701
+ <label className="text-[10px] font-bold text-slate-700 uppercase flex items-center gap-1">
702
+ <span>📦</span> Target Optimal Space:
703
+ </label>
704
+ <span className="text-[8px] font-mono text-slate-500">(hidden behind spoiler on review)</span>
705
+ </div>
706
  <input
707
  type="text"
708
  value={newFileOptimalSpace}
709
  onChange={(e) => setNewFileOptimalSpace(e.target.value)}
710
  placeholder="e.g. O(1)"
711
+ className="bg-white border-2 border-ink-black p-1.5 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-bold"
712
  />
713
  </div>
714
  </div>
 
747
  <button
748
  type="button"
749
  onClick={() => removeExample(idx)}
750
+ className="text-[10px] text-red-600 hover:text-red-800 font-bold cursor-pointer"
751
  >
752
  ✕
753
  </button>
 
791
  />
792
  </div>
793
 
794
+ {/* Row 6: Solutions & Methods Studio (Active Recall Isolated) */}
795
+ <div className="border-2 border-ink-black bg-[#faf6eb] p-3 rounded space-y-3">
796
+ <div className="flex flex-wrap items-center justify-between gap-2 border-b-2 border-ink-black pb-2">
797
+ <div className="flex items-center gap-2">
798
+ <span className="text-xs">💡</span>
799
+ <label className="text-[11px] font-bold font-arcade uppercase tracking-wide">
800
+ Solutions & Methods ({solutions.length})
801
+ </label>
802
+ <span className="text-[9px] bg-slate-200 text-slate-700 font-mono px-1.5 py-0.5 rounded border border-slate-300">
803
+ Active Recall: Shown on Solutions Tab
804
+ </span>
805
+ </div>
806
  <button
807
  type="button"
808
+ onClick={addSolution}
809
+ className="px-2.5 py-1 text-[9px] font-bold font-arcade bg-[#ffe24c] hover:bg-yellow-300 border-2 border-ink-black shadow-[1px_1px_0px_#1E293B] cursor-pointer flex items-center gap-1"
 
810
  >
811
+ <span>+</span> ADD METHOD
812
  </button>
813
  </div>
 
 
 
 
 
 
 
814
 
815
+ {/* Solution Tabs */}
816
+ <div className="flex flex-wrap gap-1.5">
817
+ {solutions.map((sol, idx) => (
818
+ <button
819
+ key={sol.id || idx}
820
+ type="button"
821
+ onClick={() => setActiveSolutionIdx(idx)}
822
+ className={`px-2.5 py-1 text-[10px] font-bold border-2 border-ink-black flex items-center gap-1.5 cursor-pointer rounded transition-colors ${
823
+ activeSolutionIdx === idx
824
+ ? 'bg-primary-purple text-white shadow-[1px_1px_0px_#1E293B]'
825
+ : 'bg-white text-slate-700 hover:bg-slate-100'
826
+ }`}
827
+ >
828
+ <span>{sol.name || `Method ${idx + 1}`}</span>
829
+ {sol.is_optimal && (
830
+ <span className={`text-[8px] px-1 py-0.2 rounded font-mono uppercase font-black ${
831
+ activeSolutionIdx === idx ? 'bg-amber-400 text-ink-black' : 'bg-amber-200 text-amber-900'
832
+ }`}>
833
+ ★ Optimal
834
+ </span>
835
+ )}
836
+ </button>
837
+ ))}
838
+ </div>
839
+
840
+ {/* Active Solution Fields */}
841
+ <div className="bg-white border-2 border-ink-black p-3 rounded space-y-2.5">
842
+ <div className="flex flex-wrap items-center justify-between gap-2 border-b border-slate-200 pb-2">
843
+ <div className="flex items-center gap-2">
844
+ <span className="text-xs font-bold text-slate-500">Method #{activeSolutionIdx + 1}:</span>
845
+ <input
846
+ type="text"
847
+ value={activeSolution.name}
848
+ onChange={(e) => updateActiveSolution({ name: e.target.value })}
849
+ placeholder="e.g. Hash Map Lookup or Two Pointers"
850
+ className="border border-ink-black px-2 py-0.5 text-xs font-bold bg-[#fffdf5] outline-none focus:ring-1 focus:ring-primary-purple w-56"
851
+ />
852
+ </div>
853
+
854
+ <div className="flex items-center gap-3">
855
+ <label className="flex items-center gap-1.5 text-[10px] font-bold text-amber-800 cursor-pointer select-none">
856
+ <input
857
+ type="checkbox"
858
+ checked={Boolean(activeSolution.is_optimal)}
859
+ onChange={(e) => updateActiveSolution({ is_optimal: e.target.checked })}
860
+ className="w-3.5 h-3.5 accent-amber-500 cursor-pointer"
861
+ />
862
+ <span>Mark as Optimal Solution</span>
863
+ </label>
864
+
865
+ {solutions.length > 1 && (
866
+ <button
867
+ type="button"
868
+ onClick={() => removeSolution(activeSolutionIdx)}
869
+ className="text-[10px] font-bold text-red-600 hover:text-red-800 border border-red-300 hover:border-red-500 px-2 py-0.5 rounded cursor-pointer"
870
+ >
871
+ Remove Method
872
+ </button>
873
+ )}
874
+ </div>
875
+ </div>
876
+
877
+ {/* Method Pattern and Big-O */}
878
+ <div className="grid grid-cols-1 md:grid-cols-3 gap-2">
879
+ <div className="flex flex-col gap-1">
880
+ <label className="text-[10px] font-bold text-slate-600 uppercase">Pattern / Technique:</label>
881
+ <input
882
+ type="text"
883
+ list="pattern-suggestions"
884
+ value={activeSolution.pattern || ''}
885
+ onChange={(e) => updateActiveSolution({ pattern: e.target.value })}
886
+ placeholder="e.g. Arrays & Hashing"
887
+ className="bg-[#fafafa] border border-ink-black p-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-medium"
888
+ />
889
+ <datalist id="pattern-suggestions">
890
+ {COMMON_PATTERNS.map(p => (
891
+ <option key={p} value={p} />
892
+ ))}
893
+ </datalist>
894
+ </div>
895
+ <div className="flex flex-col gap-1">
896
+ <label className="text-[10px] font-bold text-slate-600 uppercase">Method Time Complexity:</label>
897
+ <input
898
+ type="text"
899
+ value={activeSolution.time_complexity || ''}
900
+ onChange={(e) => updateActiveSolution({ time_complexity: e.target.value })}
901
+ placeholder="e.g. O(N)"
902
+ className="bg-[#fafafa] border border-ink-black p-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-semibold"
903
+ />
904
+ </div>
905
+ <div className="flex flex-col gap-1">
906
+ <label className="text-[10px] font-bold text-slate-600 uppercase">Method Space Complexity:</label>
907
+ <input
908
+ type="text"
909
+ value={activeSolution.space_complexity || ''}
910
+ onChange={(e) => updateActiveSolution({ space_complexity: e.target.value })}
911
+ placeholder="e.g. O(1)"
912
+ className="bg-[#fafafa] border border-ink-black p-1 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-mono font-semibold"
913
+ />
914
+ </div>
915
+ </div>
916
+
917
+ {/* Method Intuition */}
918
+ <div className="flex flex-col gap-1">
919
+ <div className="flex justify-between items-center">
920
+ <label className="text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1">
921
+ <span>💡</span> Intuition / Mental Model:
922
+ </label>
923
+ <button
924
+ type="button"
925
+ onClick={handleGenerateIntuition}
926
+ disabled={loadingIntuition}
927
+ className="text-[8px] font-arcade font-bold px-2 py-0.5 border border-ink-black bg-[#ffe24c] hover:bg-yellow-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer"
928
+ >
929
+ <span>✦</span> {loadingIntuition ? 'GENERATING...' : 'AI INTUITION'}
930
+ </button>
931
+ </div>
932
+ <textarea
933
+ value={activeSolution.explanation || ''}
934
+ onChange={(e) => updateActiveSolution({ explanation: e.target.value })}
935
+ placeholder="Explain how this specific method works, key data structures, invariants, or edge cases..."
936
+ className="bg-[#fafafa] border border-ink-black p-2 text-xs outline-none focus:ring-1 focus:ring-primary-purple font-sans h-20 resize-y leading-relaxed"
937
+ />
938
+ </div>
939
+
940
+ {/* Method Python Code */}
941
+ <div className="flex flex-col gap-1">
942
+ <div className="flex justify-between items-center">
943
+ <label className="text-[10px] font-bold text-slate-600 uppercase flex items-center gap-1">
944
+ <span>🐍</span> Method Python Code:
945
+ </label>
946
+ <button
947
+ type="button"
948
+ onClick={handleFormatCode}
949
+ disabled={loadingComments || !activeSolution.code?.trim()}
950
+ className="text-[8px] font-arcade font-bold px-2 py-0.5 border border-ink-black bg-[#a7f3d0] hover:bg-emerald-300 disabled:opacity-50 flex items-center gap-1 cursor-pointer text-emerald-950"
951
+ >
952
+ <span>✨</span> {loadingComments ? 'FORMATTING...' : 'ADD EMOJI COMMENTS'}
953
+ </button>
954
+ </div>
955
+ <textarea
956
+ value={activeSolution.code || ''}
957
+ onChange={(e) => updateActiveSolution({ code: e.target.value })}
958
+ placeholder="def twoSum(nums: list[int], target: int) -> list[int]:&#10; # 1. 🗺️ Initialize lookup map&#10; seen = {}&#10; ...&#10; return []"
959
+ className="bg-slate-900 text-[#4ADE80] font-mono p-2.5 border-2 border-ink-black rounded outline-none h-44 text-xs leading-relaxed resize-y w-full"
960
+ />
961
+ </div>
962
  </div>
 
 
 
 
 
 
963
  </div>
964
  </>
965
  ) : (
 
1039
  </div>
1040
  )}
1041
 
1042
+ {/* Target Optimal Complexities */}
1043
+ <div className="p-2.5 bg-slate-50 border border-slate-200 rounded space-y-1 text-xs">
1044
+ <div className="font-bold text-slate-700">Target Optimal Complexities (Active Recall Shielded on Review):</div>
1045
+ <div className="flex gap-4 font-mono text-slate-900">
1046
+ <span>Time: {newFileOptimalTime}</span>
1047
+ <span>Space: {newFileOptimalSpace}</span>
 
 
 
 
 
 
 
 
 
 
 
 
1048
  </div>
1049
  </div>
1050
 
1051
+ {/* Methods & Solutions List */}
1052
+ <div className="pt-3 space-y-4">
1053
+ <div className="font-bold text-sm text-slate-900 border-b pb-1">
1054
+ Solutions & Methods ({solutions.length})
 
 
 
1055
  </div>
1056
+ {solutions.map((sol, i) => (
1057
+ <div key={sol.id || i} className="border border-slate-300 p-3 rounded space-y-2 bg-[#fdfdfd]">
1058
+ <div className="flex items-center justify-between">
1059
+ <span className="font-bold text-xs text-slate-900">
1060
+ {sol.name || `Method ${i + 1}`}
1061
+ </span>
1062
+ <div className="flex items-center gap-1.5">
1063
+ {sol.is_optimal && (
1064
+ <span className="text-[9px] bg-amber-100 text-amber-800 font-bold px-1.5 py-0.5 rounded border border-amber-300">
1065
+ ★ Optimal
1066
+ </span>
1067
+ )}
1068
+ <span className="text-[9px] bg-purple-100 text-primary-purple font-bold px-1.5 py-0.5 rounded border border-purple-200">
1069
+ {sol.pattern || 'Standard'}
1070
+ </span>
1071
+ </div>
1072
+ </div>
1073
 
1074
+ <div className="flex gap-4 text-xs font-mono text-slate-600">
1075
+ <span>T: {sol.time_complexity || 'O(?)'}</span>
1076
+ <span>S: {sol.space_complexity || 'O(?)'}</span>
1077
+ </div>
1078
+
1079
+ {sol.explanation && (
1080
+ <div className="text-xs text-slate-700 leading-relaxed whitespace-pre-wrap bg-slate-50 p-2 rounded">
1081
+ {sol.explanation}
1082
+ </div>
1083
+ )}
1084
+
1085
+ {sol.code && (
1086
+ <div className="bg-[#f8fafc] border border-slate-200 p-2.5 rounded font-mono text-[11px] leading-relaxed text-slate-900 overflow-x-auto whitespace-pre">
1087
+ {sol.code}
1088
+ </div>
1089
+ )}
1090
  </div>
1091
+ ))}
1092
+ </div>
1093
  </div>
1094
  )}
1095
  </div>
algospaced-ui/src/components/ReviewQueue.tsx CHANGED
@@ -1,8 +1,8 @@
1
  import { useState, useEffect, useCallback } from 'react';
2
  import { RefreshCw, FileText, Code, BookOpen } from 'lucide-react';
3
  import OnboardingModal from './OnboardingModal';
4
- import { getCatalogProblemByNumber, getCatalogProblemById } from '../services/catalogService';
5
- import { parseProblemContent } from '../utils/problemContentParser';
6
  import { getGitHubConfig, pushSolutionToGitHub } from '../services/githubSyncService';
7
  import { useReviewQueue } from '../hooks/useReviewQueue';
8
  import { useSandboxRunner } from '../hooks/useSandboxRunner';
@@ -12,7 +12,7 @@ import { ProblemSpecPanel } from './review/ProblemSpecPanel';
12
  import { CodeStudioPanel } from './review/CodeStudioPanel';
13
  import { RatingBar } from './review/RatingBar';
14
  import { EmptyQueueCelebration } from './review/EmptyQueueCelebration';
15
- import type { ProblemItem } from '../types/reviewTypes';
16
 
17
  export interface ReviewQueueProps {
18
  overrideProblemId: string | null;
@@ -223,6 +223,21 @@ export default function ReviewQueue({
223
  }
224
  }, [onOpenOnboarding]);
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  // Loading State
227
  if (loading) {
228
  return (
@@ -267,26 +282,37 @@ export default function ReviewQueue({
267
  const problemNumber = rawProblem?.problem_number ??
268
  (/^\d+$/.test(activeReview?.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined);
269
 
270
- const catalogProb = problemNumber !== undefined
271
- ? getCatalogProblemByNumber(problemNumber)
272
- : (getCatalogProblemById(rawProblem?.id) || getCatalogProblemById(activeReview?.problem_id));
 
 
 
 
 
 
 
 
 
273
 
274
  const effectiveProblem: ProblemItem = {
275
  ...catalogProb,
276
  ...rawProblem,
277
  id: rawProblem?.id || catalogProb?.id || activeReview?.problem_id,
278
- name: rawProblem?.name || catalogProb?.name || 'Algorithm Problem',
279
  problem_number: rawProblem?.problem_number ?? catalogProb?.problem_number,
280
- pattern: rawProblem?.pattern || catalogProb?.pattern || 'General Algorithm',
 
281
  difficulty: rawProblem?.difficulty || catalogProb?.difficulty || 'Medium',
282
  reference_code: rawProblem?.reference_code || catalogProb?.reference_solution || '',
283
- starter_code: rawProblem?.starter_code || catalogProb?.starter_code || '',
284
  description: rawProblem?.description || catalogProb?.description || '',
285
  optimal_time: rawProblem?.optimal_time || catalogProb?.time_complexity || 'O(N)',
286
  optimal_space: rawProblem?.optimal_space || catalogProb?.space_complexity || 'O(1)',
287
  examples: (rawProblem?.examples && rawProblem.examples.length > 0) ? rawProblem.examples : catalogProb?.examples,
288
  constraints: rawProblem?.constraints || catalogProb?.constraints,
289
  how_to_solve: (rawProblem as { how_to_solve?: string } | undefined)?.how_to_solve || '',
 
290
  };
291
 
292
  const parsed = parseProblemContent({
@@ -398,8 +424,11 @@ export default function ReviewQueue({
398
  explainLoading={explainLoading}
399
  explainError={explainError}
400
  explanationText={explanationText}
401
- onExplainCode={() => handleExplainCode(activeReview)}
 
 
402
  activeReview={activeReview}
 
403
  onEditProblem={() => {
404
  if (onOpenEditProblem) onOpenEditProblem(effectiveProblem);
405
  else onOpenWindow?.('editProblem');
 
1
  import { useState, useEffect, useCallback } from 'react';
2
  import { RefreshCw, FileText, Code, BookOpen } from 'lucide-react';
3
  import OnboardingModal from './OnboardingModal';
4
+ import { findCatalogProblem } from '../services/catalogService';
5
+ import { parseProblemContent, parseProblemTitle } from '../utils/problemContentParser';
6
  import { getGitHubConfig, pushSolutionToGitHub } from '../services/githubSyncService';
7
  import { useReviewQueue } from '../hooks/useReviewQueue';
8
  import { useSandboxRunner } from '../hooks/useSandboxRunner';
 
12
  import { CodeStudioPanel } from './review/CodeStudioPanel';
13
  import { RatingBar } from './review/RatingBar';
14
  import { EmptyQueueCelebration } from './review/EmptyQueueCelebration';
15
+ import type { ProblemItem, ProblemSolution } from '../types/reviewTypes';
16
 
17
  export interface ReviewQueueProps {
18
  overrideProblemId: string | null;
 
223
  }
224
  }, [onOpenOnboarding]);
225
 
226
+ const handleUpdateSolutions = useCallback((updatedSolutions: ProblemSolution[]) => {
227
+ setReviews((prev) => {
228
+ if (prev.length === 0) return prev;
229
+ const next = [...prev];
230
+ const curr = next[0];
231
+ if (curr && curr.problems) {
232
+ curr.problems = {
233
+ ...curr.problems,
234
+ solutions: updatedSolutions
235
+ };
236
+ }
237
+ return next;
238
+ });
239
+ }, [setReviews]);
240
+
241
  // Loading State
242
  if (loading) {
243
  return (
 
282
  const problemNumber = rawProblem?.problem_number ??
283
  (/^\d+$/.test(activeReview?.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined);
284
 
285
+ const catalogProb = findCatalogProblem(
286
+ problemNumber,
287
+ rawProblem?.id || activeReview?.problem_id,
288
+ rawProblem?.name
289
+ );
290
+
291
+ const { cleanTitle, approachVariant, pattern: resolvedPattern } = parseProblemTitle(
292
+ rawProblem?.name,
293
+ catalogProb?.name,
294
+ rawProblem?.pattern,
295
+ catalogProb?.pattern
296
+ );
297
 
298
  const effectiveProblem: ProblemItem = {
299
  ...catalogProb,
300
  ...rawProblem,
301
  id: rawProblem?.id || catalogProb?.id || activeReview?.problem_id,
302
+ name: cleanTitle,
303
  problem_number: rawProblem?.problem_number ?? catalogProb?.problem_number,
304
+ pattern: resolvedPattern,
305
+ approach_variant: approachVariant,
306
  difficulty: rawProblem?.difficulty || catalogProb?.difficulty || 'Medium',
307
  reference_code: rawProblem?.reference_code || catalogProb?.reference_solution || '',
308
+ starter_code: catalogProb?.starter_code || rawProblem?.starter_code || '',
309
  description: rawProblem?.description || catalogProb?.description || '',
310
  optimal_time: rawProblem?.optimal_time || catalogProb?.time_complexity || 'O(N)',
311
  optimal_space: rawProblem?.optimal_space || catalogProb?.space_complexity || 'O(1)',
312
  examples: (rawProblem?.examples && rawProblem.examples.length > 0) ? rawProblem.examples : catalogProb?.examples,
313
  constraints: rawProblem?.constraints || catalogProb?.constraints,
314
  how_to_solve: (rawProblem as { how_to_solve?: string } | undefined)?.how_to_solve || '',
315
+ solutions: (rawProblem?.solutions && rawProblem.solutions.length > 0) ? rawProblem.solutions : (catalogProb as unknown as { solutions?: ProblemSolution[] })?.solutions,
316
  };
317
 
318
  const parsed = parseProblemContent({
 
424
  explainLoading={explainLoading}
425
  explainError={explainError}
426
  explanationText={explanationText}
427
+ onExplainCode={(overrideCode, overridePattern, overrideTime, overrideSpace) =>
428
+ handleExplainCode(activeReview, overrideCode, overridePattern, overrideTime, overrideSpace)
429
+ }
430
  activeReview={activeReview}
431
+ onUpdateSolutions={handleUpdateSolutions}
432
  onEditProblem={() => {
433
  if (onOpenEditProblem) onOpenEditProblem(effectiveProblem);
434
  else onOpenWindow?.('editProblem');
algospaced-ui/src/components/review/ProblemSpecPanel.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
2
  import {
3
  FileText,
4
  Code,
@@ -11,12 +11,39 @@ import {
11
  Sparkles,
12
  BrainCircuit,
13
  Layers,
14
- UserCheck,
15
- Edit3
 
 
 
 
 
 
16
  } from 'lucide-react';
17
- import type { ProblemItem, ReviewItem, ParsedExample } from '../../types/reviewTypes';
 
 
18
 
19
- import { renderInlineMarkdown, parseMarkdown } from '../../utils/problemContentParser';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  interface ProblemSpecPanelProps {
22
  leftTab: 'spec' | 'ref' | 'leitner';
@@ -40,9 +67,17 @@ interface ProblemSpecPanelProps {
40
  explainLoading: boolean;
41
  explainError: string | null;
42
  explanationText: string | null;
43
- onExplainCode: () => void;
44
  activeReview: ReviewItem;
45
  onEditProblem?: () => void;
 
 
 
 
 
 
 
 
46
  }
47
 
48
  export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
@@ -65,17 +100,195 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
65
  explanationText,
66
  onExplainCode,
67
  activeReview,
68
- onEditProblem
69
  }) => {
70
- const [userSelectedTab, setUserSelectedTab] = useState<'saved' | 'default' | null>(null);
71
- const [prevProblemId, setPrevProblemId] = useState(problem.id);
 
 
 
 
 
 
72
 
73
- if (prevProblemId !== problem.id) {
74
- setPrevProblemId(problem.id);
75
- setUserSelectedTab(null);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
 
78
- const solutionTab = userSelectedTab ?? 'default';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  return (
81
  <div
@@ -105,7 +318,7 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
105
  }`}
106
  >
107
  <Code className="w-3.5 h-3.5 text-blue-700 shrink-0" />
108
- <span className="text-center leading-tight">SOLUTION</span>
109
  </button>
110
  <button
111
  onClick={() => onSelectLeftTab('leitner')}
@@ -122,20 +335,23 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
122
 
123
  {/* Dossier Scroll Area */}
124
  <div className="flex-1 overflow-y-auto custom-scrollbar p-4 sm:p-5 space-y-4">
125
- {/* SUBTAB 1: PROBLEM SPEC */}
126
  {leftTab === 'spec' && (
127
  <div className="space-y-4">
128
- {/* 1. Problem Title & Number Header Banner */}
129
- <div className="p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-2">
130
- <div className="flex items-center justify-between gap-2 flex-wrap">
131
- <div className="flex items-center gap-2">
 
 
 
132
  {problem.problem_number !== undefined && problem.problem_number !== null && (
133
- <span className="font-arcade text-[10px] font-bold px-2 py-0.5 bg-amber-300 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] text-ink-black shrink-0">
134
- {problem.problem_number > 0 ? `LC #${problem.problem_number}` : 'CUSTOM'}
135
  </span>
136
  )}
137
  <span
138
- className={`text-[9px] font-arcade font-bold px-2 py-0.5 border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] shrink-0 text-white ${
139
  problem.difficulty === 'Easy'
140
  ? 'bg-emerald-500'
141
  : problem.difficulty === 'Medium'
@@ -143,47 +359,8 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
143
  : 'bg-rose-500'
144
  }`}
145
  >
146
- {problem.difficulty ? problem.difficulty.toUpperCase() : 'EASY'}
147
- </span>
148
- </div>
149
- <div className="flex items-center gap-1.5">
150
- <span className="px-2 py-0.5 bg-purple-50 border border-purple-300 font-arcade text-[9px] text-purple-800 font-bold">
151
- {problem.pattern || 'General Algorithm'}
152
  </span>
153
- {onEditProblem && (
154
- <button
155
- onClick={onEditProblem}
156
- className="px-2 py-0.5 bg-white hover:bg-emerald-50 border border-ink-black text-[9px] font-arcade text-ink-black flex items-center gap-1 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none cursor-pointer"
157
- title="Edit Problem Specification"
158
- >
159
- <Edit3 className="w-2.5 h-2.5 text-emerald-600" />
160
- <span>EDIT</span>
161
- </button>
162
- )}
163
- </div>
164
- </div>
165
- <h2 className="text-base sm:text-lg font-extrabold text-ink-black font-headline-md leading-tight m-0 select-text">
166
- {problem.name || 'Algorithm Problem'}
167
- </h2>
168
- </div>
169
-
170
- {/* Pattern & Target Complexity Box */}
171
- <div className="p-3 bg-amber-50 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]">
172
- <div className="flex flex-wrap items-center justify-between gap-2 text-xs font-bold text-ink-black">
173
- <div className="flex items-center gap-1.5">
174
- <span className="font-arcade text-[8px] text-trash-gray uppercase">Pattern:</span>
175
- <span className="px-2 py-0.5 bg-white border border-ink-black font-arcade text-[9px] text-purple-700">
176
- {problem.pattern || 'General Algorithm'}
177
- </span>
178
- </div>
179
- <div className="flex items-center gap-2">
180
- <span className="font-arcade text-[8px] text-trash-gray uppercase">Optimal:</span>
181
- <code className="bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black">
182
- T: {problem.optimal_time || 'O(N)'}
183
- </code>
184
- <code className="bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black">
185
- S: {problem.optimal_space || 'O(1)'}
186
- </code>
187
  </div>
188
  </div>
189
  </div>
@@ -261,8 +438,8 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
261
  )}
262
 
263
  {ex.explanation && (
264
- <div className="text-[11px] font-sans text-slate-700 bg-amber-50/70 p-2 border border-dashed border-amber-300 select-text">
265
- <span className="font-bold text-ink-black">Explanation: </span>
266
  {ex.explanation}
267
  </div>
268
  )}
@@ -274,9 +451,8 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
274
 
275
  {/* Constraints */}
276
  {parsed.constraints.length > 0 && (
277
- <div className="p-3 bg-[#fdfbf7] border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-2">
278
- <div className="text-[9px] font-arcade text-trash-gray uppercase font-bold flex items-center gap-1">
279
- <AlertTriangle className="w-3 h-3 text-amber-600" />
280
  CONSTRAINTS
281
  </div>
282
  <ul className="space-y-1.5 list-none m-0 p-0">
@@ -291,97 +467,390 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
291
  </ul>
292
  </div>
293
  )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  </div>
295
  )}
296
 
297
- {/* SUBTAB 2: REFERENCE CODE & EXPLANATION */}
298
  {leftTab === 'ref' && (
299
  <div className="space-y-4">
300
- {/* INNER SOLUTION TABS: SOLUTION 1 (DEFAULT) VS SOLUTION 2 (PERSONAL) */}
301
- <div className="flex items-center gap-1.5 p-1 bg-slate-200/90 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]">
302
- <button
303
- type="button"
304
- onClick={() => setUserSelectedTab('default')}
305
- className={`flex-1 py-1.5 px-2 font-arcade text-[9px] font-bold flex items-center justify-center gap-1.5 border-2 border-ink-black transition-all cursor-pointer ${
306
- solutionTab === 'default'
307
- ? 'bg-sky-600 text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] -translate-y-0.5'
308
- : 'bg-white text-ink-black hover:bg-sky-50 shadow-none'
309
  }`}
310
  >
311
- <BookOpen className="w-3.5 h-3.5" />
312
- <span>SOLUTION 1 (DEFAULT)</span>
313
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
 
315
  <button
316
  type="button"
317
- onClick={() => setUserSelectedTab('saved')}
318
- className={`flex-1 py-1.5 px-2 font-arcade text-[9px] font-bold flex items-center justify-center gap-1.5 border-2 border-ink-black transition-all cursor-pointer ${
319
- solutionTab === 'saved'
320
- ? 'bg-emerald-500 text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] -translate-y-0.5'
321
- : 'bg-white text-ink-black hover:bg-emerald-50 shadow-none'
 
 
 
 
 
 
 
 
 
 
 
 
322
  }`}
 
323
  >
324
- <UserCheck className="w-3.5 h-3.5" />
325
- <span>SOLUTION 2 (PERSONAL)</span>
326
- {userSolution ? (
327
- <span
328
- className={`text-[7.5px] px-1.5 py-0.2 border ${
329
- solutionTab === 'saved'
330
- ? 'border-white bg-emerald-700 text-white'
331
- : 'border-emerald-600 bg-emerald-100 text-emerald-800'
332
- }`}
333
- >
334
- SAVED
335
- </span>
336
- ) : (
337
- <span className="text-[7.5px] px-1 py-0.2 border border-slate-300 bg-slate-100 text-slate-500">
338
- NONE
339
- </span>
340
- )}
341
  </button>
342
  </div>
343
 
344
- {/* TAB PANEL 1: SOLUTION 1 (DEFAULT) */}
345
- {solutionTab === 'default' && (
346
- <>
347
- {officialSolution ? (
348
- <div className="border-2 border-ink-black bg-[#0f172a] shadow-[3px_3px_0px_0px_rgba(30,41,59,1)]">
349
- <div className="bg-[#1e293b] px-3 py-1.5 border-b-2 border-ink-black flex items-center justify-end gap-2">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
  <button
351
- onClick={() => onCopyText(officialSolution, 'official-sol')}
352
- className="px-2 py-0.5 bg-white hover:bg-slate-100 text-ink-black border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0"
353
- title="Copy official solution"
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  >
355
- <Copy className="w-2.5 h-2.5" />
356
- {copiedSnippet === 'official-sol' ? 'COPIED!' : 'COPY'}
357
  </button>
358
- </div>
359
- <div className="p-3 text-xs overflow-x-auto max-h-72 custom-scrollbar">
360
- <pre className="font-code-mono text-sky-200 text-[11px] leading-relaxed select-text m-0">
361
- <code>{officialSolution}</code>
362
- </pre>
 
 
 
 
 
363
  </div>
364
  </div>
365
- ) : effectiveReferenceCode ? (
366
- <div className="border-2 border-ink-black bg-[#1E293B] shadow-[3px_3px_0px_0px_rgba(30,41,59,1)]">
367
- <div className="bg-slate-800 px-3 py-1.5 border-b-2 border-ink-black flex items-center justify-end">
 
 
 
 
 
 
368
  <button
369
- onClick={() => onCopyText(effectiveReferenceCode, 'ref-code')}
370
- className="px-2 py-0.5 bg-white hover:bg-slate-100 text-ink-black border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer"
 
371
  >
372
  <Copy className="w-2.5 h-2.5" />
373
- {copiedSnippet === 'ref-code' ? 'COPIED!' : 'COPY'}
374
  </button>
375
  </div>
376
- <div className="p-3 text-xs overflow-x-auto max-h-72 custom-scrollbar">
377
  <pre className="font-code-mono text-[#4ADE80] text-[11px] leading-relaxed select-text m-0">
378
- <code>{effectiveReferenceCode}</code>
379
  </pre>
380
  </div>
381
  </div>
382
  ) : (
383
  <div className="p-4 bg-amber-50 border-2 border-dashed border-amber-300 text-center space-y-3 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]">
384
- <p className="text-xs font-sans text-stone-700">No official default solution archived for this problem yet.</p>
385
  <button
386
  onClick={onFetchAiSolution}
387
  disabled={aiSolutionLoading}
@@ -404,109 +873,77 @@ export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
404
  )}
405
  </div>
406
  )}
407
- </>
408
- )}
409
 
410
- {/* TAB PANEL 2: SOLUTION 2 (PERSONAL) */}
411
- {solutionTab === 'saved' && (
412
- <>
413
- {userSolution ? (
414
- <div className="border-2 border-ink-black bg-[#1E293B] shadow-[3px_3px_0px_0px_rgba(30,41,59,1)]">
415
- <div className="bg-[#0f172a] px-3 py-1.5 border-b-2 border-ink-black flex items-center justify-end gap-2">
416
- <button
417
- onClick={() => onCopyText(userSolution, 'user-sol')}
418
- className="px-2 py-0.5 bg-white hover:bg-slate-100 text-ink-black border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0"
419
- title="Copy your saved solution"
420
- >
421
- <Copy className="w-2.5 h-2.5" />
422
- {copiedSnippet === 'user-sol' ? 'COPIED!' : 'COPY'}
423
- </button>
424
- </div>
425
- <div className="p-3 text-xs overflow-x-auto max-h-72 custom-scrollbar">
426
- <pre className="font-code-mono text-[#4ADE80] text-[11px] leading-relaxed select-text m-0">
427
- <code>{userSolution}</code>
428
- </pre>
429
  </div>
430
  </div>
431
- ) : (
432
- <div className="p-4 bg-amber-50/80 border-2 border-dashed border-amber-300 text-center space-y-2.5 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]">
433
- <div className="w-8 h-8 mx-auto bg-amber-100 border-2 border-ink-black flex items-center justify-center text-amber-700 shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]">
434
- <UserCheck className="w-4 h-4" />
435
- </div>
436
- <div className="font-arcade text-[9px] font-bold text-ink-black uppercase">
437
- NO PERSONAL SOLUTION SAVED YET
438
- </div>
439
- <p className="text-xs font-sans text-stone-600 max-w-sm mx-auto leading-relaxed">
440
- You haven&apos;t archived a personal solution for this problem yet. Test your code in the Studio on the right and click <strong>SAVE CURRENT STUDIO CODE AS SOLUTION</strong> below to store it in your personal database.
441
- </p>
442
- {officialSolution && (
443
- <button
444
- type="button"
445
- onClick={() => setUserSelectedTab('default')}
446
- className="px-3 py-1 bg-white hover:bg-sky-50 text-sky-700 font-arcade text-[8.5px] font-bold border-2 border-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)] cursor-pointer inline-flex items-center gap-1 active:translate-y-0.5 active:shadow-none transition-all"
447
- >
448
- <BookOpen className="w-3 h-3 text-sky-600" />
449
- <span>VIEW SOLUTION 1 (DEFAULT) INSTEAD</span>
450
- </button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
451
  )}
452
  </div>
453
  )}
454
- </>
455
- )}
456
-
457
 
458
- {/* Save error banner */}
459
  {saveRefError && (
460
  <div className="p-2.5 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-bold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(244,63,94,1)]">
461
  <AlertTriangle className="w-4 h-4 text-rose-600 shrink-0" />
462
  <div className="flex-1">{saveRefError}</div>
463
  </div>
464
  )}
465
-
466
-
467
-
468
- {/* Gemini Explanation Action */}
469
- {effectiveReferenceCode && (
470
- <div className="space-y-3">
471
- <button
472
- onClick={onExplainCode}
473
- disabled={explainLoading}
474
- className="w-full bg-amber-300 hover:bg-amber-400 border-2 border-ink-black text-ink-black font-arcade text-[9px] py-2.5 px-4 font-bold flex items-center justify-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer disabled:opacity-50"
475
- >
476
- {explainLoading ? (
477
- <>
478
- <RefreshCw className="w-3.5 h-3.5 animate-spin" />
479
- <span>EXPLAINING VIA GEMINI...</span>
480
- </>
481
- ) : (
482
- <>
483
- <Sparkles className="w-3.5 h-3.5 text-purple-700" />
484
- <span>EXPLAIN SOLUTION WITH GEMINI</span>
485
- </>
486
- )}
487
- </button>
488
-
489
- {explainError && (
490
- <div className="p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold">
491
- {explainError}
492
- </div>
493
- )}
494
-
495
- {explanationText && (
496
- <div className="p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-2 select-text">
497
- <div className="flex items-center gap-1.5 pb-2 border-b-2 border-dashed border-ink-black">
498
- <BrainCircuit className="w-4 h-4 text-purple-600" />
499
- <span className="font-arcade text-[9px] font-bold text-ink-black uppercase">
500
- Gemini Code Breakdown
501
- </span>
502
- </div>
503
- <div className="font-sans text-xs space-y-2 max-h-80 overflow-y-auto custom-scrollbar pt-1 font-medium text-slate-800">
504
- {parseMarkdown(explanationText)}
505
- </div>
506
- </div>
507
- )}
508
- </div>
509
- )}
510
  </div>
511
  )}
512
 
 
1
+ import React, { useState, useEffect } from 'react';
2
  import {
3
  FileText,
4
  Code,
 
11
  Sparkles,
12
  BrainCircuit,
13
  Layers,
14
+ Eye,
15
+ EyeOff,
16
+ Lock,
17
+ Plus,
18
+ Edit3,
19
+ Trash2,
20
+ CheckCircle2,
21
+ X
22
  } from 'lucide-react';
23
+ import type { ProblemItem, ReviewItem, ParsedExample, ProblemSolution } from '../../types/reviewTypes';
24
+ import { renderInlineMarkdown, parseMarkdown, normalizeProblemSolutions } from '../../utils/problemContentParser';
25
+ import { updateProblemSolutions } from '../../services/reviewService';
26
 
27
+ const COMMON_PATTERNS = [
28
+ 'Arrays & Hashing',
29
+ 'Two Pointers',
30
+ 'Sliding Window',
31
+ 'Stack',
32
+ 'Binary Search',
33
+ 'Linked List',
34
+ 'Trees',
35
+ 'Tries',
36
+ 'Heap / Priority Queue',
37
+ 'Backtracking',
38
+ 'Graphs',
39
+ 'Advanced Graphs',
40
+ '1-D Dynamic Programming',
41
+ '2-D Dynamic Programming',
42
+ 'Greedy',
43
+ 'Intervals',
44
+ 'Math & Geometry',
45
+ 'Bit Manipulation'
46
+ ];
47
 
48
  interface ProblemSpecPanelProps {
49
  leftTab: 'spec' | 'ref' | 'leitner';
 
67
  explainLoading: boolean;
68
  explainError: string | null;
69
  explanationText: string | null;
70
+ onExplainCode: (codeToExplain?: string, pattern?: string, timeC?: string, spaceC?: string) => void;
71
  activeReview: ReviewItem;
72
  onEditProblem?: () => void;
73
+ onUpdateSolutions?: (solutions: ProblemSolution[]) => void;
74
+ }
75
+
76
+ function generateSolutionId(): string {
77
+ if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
78
+ return `sol-${crypto.randomUUID()}`;
79
+ }
80
+ return `sol-${Date.now()}`;
81
  }
82
 
83
  export const ProblemSpecPanel: React.FC<ProblemSpecPanelProps> = ({
 
100
  explanationText,
101
  onExplainCode,
102
  activeReview,
103
+ onUpdateSolutions
104
  }) => {
105
+ // Active Recall Spoiler state
106
+ const [showComplexitySpoiler, setShowComplexitySpoiler] = useState(false);
107
+ const [prevProblemKey, setPrevProblemKey] = useState<string>(() => problem.id || problem.name);
108
+
109
+ // Multi-solution state
110
+ const [selectedSolutionIndex, setSelectedSolutionIndex] = useState(0);
111
+ const [isAddingSolution, setIsAddingSolution] = useState(false);
112
+ const [editingSolutionId, setEditingSolutionId] = useState<string | null>(null);
113
 
114
+ // Form state for adding/editing a solution
115
+ const [solutionForm, setSolutionForm] = useState<{
116
+ name: string;
117
+ pattern: string;
118
+ time_complexity: string;
119
+ space_complexity: string;
120
+ code: string;
121
+ explanation: string;
122
+ is_optimal: boolean;
123
+ }>({
124
+ name: '',
125
+ pattern: 'Arrays & Hashing',
126
+ time_complexity: 'O(N)',
127
+ space_complexity: 'O(1)',
128
+ code: '',
129
+ explanation: '',
130
+ is_optimal: false
131
+ });
132
+
133
+ const [savingSolution, setSavingSolution] = useState(false);
134
+ const [solutionFeedback, setSolutionFeedback] = useState<{ type: 'success' | 'error'; message: string } | null>(null);
135
+
136
+ // Reset local state when active problem switches
137
+ const currentProblemKey = problem.id || problem.name;
138
+ if (prevProblemKey !== currentProblemKey) {
139
+ setPrevProblemKey(currentProblemKey);
140
+ setShowComplexitySpoiler(false);
141
+ setSelectedSolutionIndex(0);
142
+ setIsAddingSolution(false);
143
+ setEditingSolutionId(null);
144
+ setSolutionFeedback(null);
145
  }
146
 
147
+ // Derive solutions list
148
+ const solutions: ProblemSolution[] = normalizeProblemSolutions(problem, officialSolution, userSolution);
149
+ const safeIndex = selectedSolutionIndex < solutions.length ? selectedSolutionIndex : 0;
150
+ const activeSolution = solutions[safeIndex];
151
+
152
+ // Auto-dismiss feedback message after 3.5 seconds
153
+ useEffect(() => {
154
+ if (solutionFeedback) {
155
+ const timer = setTimeout(() => setSolutionFeedback(null), 3500);
156
+ return () => clearTimeout(timer);
157
+ }
158
+ }, [solutionFeedback]);
159
+
160
+ // Handle saving (add or update) solution
161
+ const handleSaveSolution = async () => {
162
+ if (!solutionForm.name.trim()) {
163
+ setSolutionFeedback({ type: 'error', message: 'Solution name cannot be empty.' });
164
+ return;
165
+ }
166
+ if (!solutionForm.code.trim()) {
167
+ setSolutionFeedback({ type: 'error', message: 'Solution code cannot be empty.' });
168
+ return;
169
+ }
170
+
171
+ setSavingSolution(true);
172
+ setSolutionFeedback(null);
173
+
174
+ try {
175
+ let updatedSolutions: ProblemSolution[];
176
+
177
+ if (editingSolutionId) {
178
+ // Edit existing
179
+ updatedSolutions = solutions.map((s) => {
180
+ if (s.id === editingSolutionId) {
181
+ return {
182
+ ...s,
183
+ name: solutionForm.name.trim(),
184
+ pattern: solutionForm.pattern.trim() || 'General Algorithm',
185
+ time_complexity: solutionForm.time_complexity.trim() || 'O(N)',
186
+ space_complexity: solutionForm.space_complexity.trim() || 'O(1)',
187
+ code: solutionForm.code,
188
+ explanation: solutionForm.explanation.trim(),
189
+ is_optimal: solutionForm.is_optimal
190
+ };
191
+ }
192
+ // If this one is marked optimal, unset others
193
+ if (solutionForm.is_optimal && s.id !== editingSolutionId) {
194
+ return { ...s, is_optimal: false };
195
+ }
196
+ return s;
197
+ });
198
+ } else {
199
+ // Add new
200
+ const newSolution: ProblemSolution = {
201
+ id: generateSolutionId(),
202
+ name: solutionForm.name.trim(),
203
+ pattern: solutionForm.pattern.trim() || 'General Algorithm',
204
+ time_complexity: solutionForm.time_complexity.trim() || 'O(N)',
205
+ space_complexity: solutionForm.space_complexity.trim() || 'O(1)',
206
+ code: solutionForm.code,
207
+ explanation: solutionForm.explanation.trim(),
208
+ is_optimal: solutionForm.is_optimal || solutions.length === 0
209
+ };
210
+
211
+ if (newSolution.is_optimal) {
212
+ updatedSolutions = [
213
+ ...solutions.map((s): ProblemSolution => ({ ...s, is_optimal: false })),
214
+ newSolution
215
+ ];
216
+ } else {
217
+ updatedSolutions = [...solutions, newSolution];
218
+ }
219
+ }
220
+
221
+ const optimalSol = updatedSolutions.find((s) => s.is_optimal) || updatedSolutions[0];
222
+
223
+ if (problem.id) {
224
+ await updateProblemSolutions(
225
+ problem.id,
226
+ updatedSolutions,
227
+ optimalSol?.time_complexity,
228
+ optimalSol?.space_complexity,
229
+ problem
230
+ );
231
+ }
232
+
233
+ onUpdateSolutions?.(updatedSolutions);
234
+ setSolutionFeedback({
235
+ type: 'success',
236
+ message: editingSolutionId ? 'Solution updated successfully!' : 'New solution added to problem dossier!'
237
+ });
238
+ setIsAddingSolution(false);
239
+ setEditingSolutionId(null);
240
+ setSelectedSolutionIndex(
241
+ editingSolutionId
242
+ ? safeIndex
243
+ : updatedSolutions.length - 1
244
+ );
245
+ } catch (err) {
246
+ const msg = err instanceof Error ? err.message : 'Failed to save solution.';
247
+ setSolutionFeedback({ type: 'error', message: msg });
248
+ } finally {
249
+ setSavingSolution(false);
250
+ }
251
+ };
252
+
253
+ // Handle deleting a solution
254
+ const handleDeleteSolution = async (solutionIdToDelete: string) => {
255
+ if (solutions.length <= 1) {
256
+ setSolutionFeedback({ type: 'error', message: 'Problem must have at least one solution.' });
257
+ return;
258
+ }
259
+
260
+ if (!window.confirm('Are you sure you want to remove this solution?')) return;
261
+
262
+ setSavingSolution(true);
263
+ try {
264
+ const updatedSolutions = solutions.filter((s) => s.id !== solutionIdToDelete);
265
+ // Ensure at least one is optimal
266
+ if (!updatedSolutions.some((s) => s.is_optimal) && updatedSolutions.length > 0) {
267
+ updatedSolutions[0].is_optimal = true;
268
+ }
269
+
270
+ const optimalSol = updatedSolutions.find((s) => s.is_optimal) || updatedSolutions[0];
271
+
272
+ if (problem.id) {
273
+ await updateProblemSolutions(
274
+ problem.id,
275
+ updatedSolutions,
276
+ optimalSol?.time_complexity,
277
+ optimalSol?.space_complexity,
278
+ problem
279
+ );
280
+ }
281
+
282
+ onUpdateSolutions?.(updatedSolutions);
283
+ setSelectedSolutionIndex(0);
284
+ setSolutionFeedback({ type: 'success', message: 'Solution removed successfully.' });
285
+ } catch (err) {
286
+ const msg = err instanceof Error ? err.message : 'Failed to delete solution.';
287
+ setSolutionFeedback({ type: 'error', message: msg });
288
+ } finally {
289
+ setSavingSolution(false);
290
+ }
291
+ };
292
 
293
  return (
294
  <div
 
318
  }`}
319
  >
320
  <Code className="w-3.5 h-3.5 text-blue-700 shrink-0" />
321
+ <span className="text-center leading-tight">SOLUTIONS ({solutions.length})</span>
322
  </button>
323
  <button
324
  onClick={() => onSelectLeftTab('leitner')}
 
335
 
336
  {/* Dossier Scroll Area */}
337
  <div className="flex-1 overflow-y-auto custom-scrollbar p-4 sm:p-5 space-y-4">
338
+ {/* SUBTAB 1: PROBLEM SPEC (Active Recall Mode - No Spoilers!) */}
339
  {leftTab === 'spec' && (
340
  <div className="space-y-4">
341
+ {/* 1. Problem Title Header Banner */}
342
+ <div className="p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-1.5">
343
+ <div className="flex items-center justify-between gap-3">
344
+ <h2 className="text-base sm:text-lg font-extrabold text-ink-black font-headline-md leading-tight m-0 select-text">
345
+ {problem.name || 'Algorithm Problem'}
346
+ </h2>
347
+ <div className="flex items-center gap-1.5 shrink-0">
348
  {problem.problem_number !== undefined && problem.problem_number !== null && (
349
+ <span className="font-arcade text-[9px] font-bold px-2 py-0.5 bg-amber-200 border border-ink-black text-ink-black">
350
+ LC #{problem.problem_number}
351
  </span>
352
  )}
353
  <span
354
+ className={`font-arcade text-[9px] font-bold px-2 py-0.5 border border-ink-black text-white ${
355
  problem.difficulty === 'Easy'
356
  ? 'bg-emerald-500'
357
  : problem.difficulty === 'Medium'
 
359
  : 'bg-rose-500'
360
  }`}
361
  >
362
+ {problem.difficulty ? problem.difficulty.toUpperCase() : 'MEDIUM'}
 
 
 
 
 
363
  </span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  </div>
365
  </div>
366
  </div>
 
438
  )}
439
 
440
  {ex.explanation && (
441
+ <div className="text-[11px] font-sans text-slate-600 bg-slate-50 p-2 border border-slate-200">
442
+ <span className="font-bold text-slate-700">Explanation: </span>
443
  {ex.explanation}
444
  </div>
445
  )}
 
451
 
452
  {/* Constraints */}
453
  {parsed.constraints.length > 0 && (
454
+ <div className="p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]">
455
+ <div className="text-[9px] font-arcade text-trash-gray uppercase font-bold mb-2">
 
456
  CONSTRAINTS
457
  </div>
458
  <ul className="space-y-1.5 list-none m-0 p-0">
 
467
  </ul>
468
  </div>
469
  )}
470
+
471
+ {/* Optimal Complexity Target Spoiler Shield (Positioned below constraints for active recall) */}
472
+ {!showComplexitySpoiler ? (
473
+ <div className="p-3 bg-amber-50/70 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex items-center justify-between gap-2">
474
+ <div className="flex items-center gap-2">
475
+ <Lock className="w-4 h-4 text-amber-700 shrink-0" />
476
+ <div>
477
+ <span className="font-arcade text-[9px] font-bold text-ink-black tracking-wide uppercase block">
478
+ OPTIMAL COMPLEXITY TARGET
479
+ </span>
480
+ <span className="text-[10px] font-sans text-slate-600 font-semibold">
481
+ Hidden to test active recall before coding
482
+ </span>
483
+ </div>
484
+ </div>
485
+ <button
486
+ type="button"
487
+ onClick={() => setShowComplexitySpoiler(true)}
488
+ className="px-2.5 py-1 bg-white hover:bg-amber-100 border-2 border-ink-black font-arcade text-[8.5px] font-bold text-ink-black shadow-[1.5px_1.5px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer flex items-center gap-1.5 shrink-0"
489
+ title="Click to reveal target time and space complexity"
490
+ >
491
+ <Eye className="w-3 h-3 text-amber-700" />
492
+ <span>REVEAL TARGET</span>
493
+ </button>
494
+ </div>
495
+ ) : (
496
+ <div className="p-3 bg-amber-50 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex flex-wrap items-center justify-between gap-2">
497
+ <div className="flex items-center gap-2 flex-wrap">
498
+ <Zap className="w-4 h-4 text-amber-600 shrink-0" />
499
+ <span className="font-arcade text-[9px] font-bold text-ink-black tracking-wide uppercase">
500
+ OPTIMAL TARGET:
501
+ </span>
502
+ <code className="bg-[#1E293B] text-[#4ADE80] font-code-mono px-2 py-0.5 text-[11px] border border-ink-black font-bold">
503
+ T: {problem.optimal_time || 'O(N)'}
504
+ </code>
505
+ <code className="bg-[#1E293B] text-[#4ADE80] font-code-mono px-2 py-0.5 text-[11px] border border-ink-black font-bold">
506
+ S: {problem.optimal_space || 'O(1)'}
507
+ </code>
508
+ </div>
509
+ <button
510
+ type="button"
511
+ onClick={() => setShowComplexitySpoiler(false)}
512
+ className="px-2 py-0.5 bg-white hover:bg-slate-100 border border-ink-black font-arcade text-[8px] text-trash-gray hover:text-ink-black cursor-pointer flex items-center gap-1"
513
+ title="Conceal target complexity"
514
+ >
515
+ <EyeOff className="w-2.5 h-2.5" />
516
+ <span>HIDE</span>
517
+ </button>
518
+ </div>
519
+ )}
520
  </div>
521
  )}
522
 
523
+ {/* SUBTAB 2: SOLUTIONS (Methods Archive with Pattern, Complexity, & Code) */}
524
  {leftTab === 'ref' && (
525
  <div className="space-y-4">
526
+ {/* Feedback alert */}
527
+ {solutionFeedback && (
528
+ <div
529
+ className={`p-2.5 border-2 border-ink-black text-xs font-bold flex items-center justify-between shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] ${
530
+ solutionFeedback.type === 'success' ? 'bg-emerald-100 text-emerald-900 border-emerald-700' : 'bg-rose-100 text-rose-900 border-rose-700'
 
 
 
 
531
  }`}
532
  >
533
+ <div className="flex items-center gap-2">
534
+ {solutionFeedback.type === 'success' ? (
535
+ <CheckCircle2 className="w-4 h-4 text-emerald-700 shrink-0" />
536
+ ) : (
537
+ <AlertTriangle className="w-4 h-4 text-rose-700 shrink-0" />
538
+ )}
539
+ <span>{solutionFeedback.message}</span>
540
+ </div>
541
+ <button
542
+ type="button"
543
+ onClick={() => setSolutionFeedback(null)}
544
+ className="text-slate-600 hover:text-ink-black cursor-pointer"
545
+ >
546
+ <X className="w-3.5 h-3.5" />
547
+ </button>
548
+ </div>
549
+ )}
550
+
551
+ {/* SOLUTION SELECTOR TAB BAR */}
552
+ <div className="flex items-center gap-1.5 p-1 bg-slate-200/90 border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] overflow-x-auto custom-scrollbar">
553
+ {solutions.map((sol, idx) => (
554
+ <button
555
+ key={sol.id || idx}
556
+ type="button"
557
+ onClick={() => {
558
+ setSelectedSolutionIndex(idx);
559
+ setIsAddingSolution(false);
560
+ setEditingSolutionId(null);
561
+ }}
562
+ className={`py-1.5 px-3 font-arcade text-[9px] font-bold flex items-center justify-center gap-1.5 border-2 border-ink-black transition-all cursor-pointer whitespace-nowrap shrink-0 ${
563
+ safeIndex === idx && !isAddingSolution && !editingSolutionId
564
+ ? 'bg-sky-600 text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] -translate-y-0.5'
565
+ : 'bg-white text-ink-black hover:bg-sky-50 shadow-none'
566
+ }`}
567
+ >
568
+ {sol.is_optimal ? <Sparkles className="w-3 h-3 text-amber-300" /> : <BookOpen className="w-3 h-3" />}
569
+ <span>{`SOL ${idx + 1}: ${sol.name.toUpperCase()}`}</span>
570
+ {sol.is_optimal && (
571
+ <span className="text-[7.5px] px-1 py-0.2 bg-amber-300 text-ink-black border border-ink-black font-extrabold">
572
+ OPTIMAL
573
+ </span>
574
+ )}
575
+ </button>
576
+ ))}
577
 
578
  <button
579
  type="button"
580
+ onClick={() => {
581
+ setIsAddingSolution(true);
582
+ setEditingSolutionId(null);
583
+ setSolutionForm({
584
+ name: `Method ${solutions.length + 1}`,
585
+ pattern: 'Arrays & Hashing',
586
+ time_complexity: 'O(N)',
587
+ space_complexity: 'O(1)',
588
+ code: '',
589
+ explanation: '',
590
+ is_optimal: false
591
+ });
592
+ }}
593
+ className={`py-1.5 px-2.5 font-arcade text-[9px] font-bold flex items-center gap-1 border-2 border-ink-black cursor-pointer whitespace-nowrap shrink-0 active:translate-y-0.5 transition-all ${
594
+ isAddingSolution
595
+ ? 'bg-emerald-600 text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]'
596
+ : 'bg-amber-300 text-ink-black hover:bg-amber-200'
597
  }`}
598
+ title="Add another solution / method for this problem"
599
  >
600
+ <Plus className="w-3 h-3" />
601
+ <span>+ ADD SOLUTION</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
  </button>
603
  </div>
604
 
605
+ {/* ADD OR EDIT SOLUTION FORM */}
606
+ {(isAddingSolution || editingSolutionId) ? (
607
+ <div className="p-4 bg-white border-2 border-ink-black shadow-[3px_3px_0px_0px_rgba(30,41,59,1)] space-y-3.5">
608
+ <div className="flex items-center justify-between pb-2 border-b-2 border-dashed border-ink-black">
609
+ <div className="flex items-center gap-2">
610
+ <Edit3 className="w-4 h-4 text-purple-700" />
611
+ <span className="font-arcade text-[10px] font-bold text-ink-black uppercase">
612
+ {editingSolutionId ? 'EDIT SOLUTION' : 'ADD NEW SOLUTION / METHOD'}
613
+ </span>
614
+ </div>
615
+ <button
616
+ type="button"
617
+ onClick={() => {
618
+ setIsAddingSolution(false);
619
+ setEditingSolutionId(null);
620
+ }}
621
+ className="text-xs font-arcade text-trash-gray hover:text-rose-600 cursor-pointer font-bold"
622
+ >
623
+ CANCEL
624
+ </button>
625
+ </div>
626
+
627
+ <div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
628
+ {/* Solution Name */}
629
+ <div className="space-y-1">
630
+ <label className="font-arcade text-[8.5px] font-bold text-trash-gray uppercase block">
631
+ Solution / Method Name
632
+ </label>
633
+ <input
634
+ type="text"
635
+ value={solutionForm.name}
636
+ onChange={(e) => setSolutionForm({ ...solutionForm, name: e.target.value })}
637
+ placeholder="e.g. One-Pass Hash Map, Two Pointers"
638
+ className="w-full p-2 border-2 border-ink-black text-xs font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white"
639
+ />
640
+ </div>
641
+
642
+ {/* Pattern */}
643
+ <div className="space-y-1">
644
+ <label className="font-arcade text-[8.5px] font-bold text-trash-gray uppercase block">
645
+ Pattern / Strategy
646
+ </label>
647
+ <select
648
+ value={solutionForm.pattern}
649
+ onChange={(e) => setSolutionForm({ ...solutionForm, pattern: e.target.value })}
650
+ className="w-full p-2 border-2 border-ink-black text-xs font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white"
651
+ >
652
+ {COMMON_PATTERNS.map((p) => (
653
+ <option key={p} value={p}>{p}</option>
654
+ ))}
655
+ </select>
656
+ </div>
657
+
658
+ {/* Time Complexity */}
659
+ <div className="space-y-1">
660
+ <label className="font-arcade text-[8.5px] font-bold text-trash-gray uppercase block">
661
+ Time Complexity
662
+ </label>
663
+ <input
664
+ type="text"
665
+ value={solutionForm.time_complexity}
666
+ onChange={(e) => setSolutionForm({ ...solutionForm, time_complexity: e.target.value })}
667
+ placeholder="e.g. O(N), O(N log N), O(N^2)"
668
+ className="w-full p-2 border-2 border-ink-black text-xs font-code-mono font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white"
669
+ />
670
+ </div>
671
+
672
+ {/* Space Complexity */}
673
+ <div className="space-y-1">
674
+ <label className="font-arcade text-[8.5px] font-bold text-trash-gray uppercase block">
675
+ Space Complexity
676
+ </label>
677
+ <input
678
+ type="text"
679
+ value={solutionForm.space_complexity}
680
+ onChange={(e) => setSolutionForm({ ...solutionForm, space_complexity: e.target.value })}
681
+ placeholder="e.g. O(1), O(N)"
682
+ className="w-full p-2 border-2 border-ink-black text-xs font-code-mono font-bold bg-[#fdf8e1] focus:outline-none focus:bg-white"
683
+ />
684
+ </div>
685
+ </div>
686
+
687
+ {/* Reference Code */}
688
+ <div className="space-y-1">
689
+ <div className="flex items-center justify-between">
690
+ <label className="font-arcade text-[8.5px] font-bold text-trash-gray uppercase">
691
+ Python Reference Code
692
+ </label>
693
+ <button
694
+ type="button"
695
+ onClick={() => setSolutionForm({ ...solutionForm, code: effectiveReferenceCode })}
696
+ className="text-[8.5px] font-arcade text-sky-700 hover:underline cursor-pointer"
697
+ >
698
+ Paste Current Code
699
+ </button>
700
+ </div>
701
+ <textarea
702
+ rows={8}
703
+ value={solutionForm.code}
704
+ onChange={(e) => setSolutionForm({ ...solutionForm, code: e.target.value })}
705
+ placeholder="class Solution:&#10; def solve(self, nums):&#10; ..."
706
+ className="w-full p-2.5 border-2 border-ink-black bg-[#1E293B] text-[#4ADE80] font-code-mono text-xs focus:outline-none custom-scrollbar"
707
+ />
708
+ </div>
709
+
710
+ {/* Explanation */}
711
+ <div className="space-y-1">
712
+ <label className="font-arcade text-[8.5px] font-bold text-trash-gray uppercase block">
713
+ Intuition / How to Solve (Optional)
714
+ </label>
715
+ <textarea
716
+ rows={3}
717
+ value={solutionForm.explanation}
718
+ onChange={(e) => setSolutionForm({ ...solutionForm, explanation: e.target.value })}
719
+ placeholder="Key insight, trade-offs, and state tracking notes..."
720
+ className="w-full p-2 border-2 border-ink-black text-xs bg-[#fdf8e1] focus:outline-none focus:bg-white custom-scrollbar"
721
+ />
722
+ </div>
723
+
724
+ {/* Is Optimal Checkbox */}
725
+ <div className="flex items-center gap-2">
726
+ <input
727
+ type="checkbox"
728
+ id="is_optimal_solution"
729
+ checked={solutionForm.is_optimal}
730
+ onChange={(e) => setSolutionForm({ ...solutionForm, is_optimal: e.target.checked })}
731
+ className="w-4 h-4 border-2 border-ink-black rounded cursor-pointer accent-emerald-600"
732
+ />
733
+ <label htmlFor="is_optimal_solution" className="font-arcade text-[9px] font-bold text-ink-black cursor-pointer">
734
+ SET AS OPTIMAL / PRIMARY APPROACH FOR THIS PROBLEM
735
+ </label>
736
+ </div>
737
+
738
+ {/* Action Buttons */}
739
+ <div className="flex items-center justify-end gap-2 pt-2 border-t-2 border-dashed border-ink-black">
740
+ <button
741
+ type="button"
742
+ onClick={() => {
743
+ setIsAddingSolution(false);
744
+ setEditingSolutionId(null);
745
+ }}
746
+ className="px-3 py-1.5 bg-slate-100 hover:bg-slate-200 border-2 border-ink-black font-arcade text-[9px] font-bold text-ink-black cursor-pointer"
747
+ >
748
+ CANCEL
749
+ </button>
750
+ <button
751
+ type="button"
752
+ disabled={savingSolution}
753
+ onClick={handleSaveSolution}
754
+ className="px-4 py-1.5 bg-emerald-500 hover:bg-emerald-400 border-2 border-ink-black font-arcade text-[9px] font-bold text-white shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer disabled:opacity-50 flex items-center gap-1.5"
755
+ >
756
+ {savingSolution && <RefreshCw className="w-3 h-3 animate-spin" />}
757
+ <span>{editingSolutionId ? 'UPDATE SOLUTION' : 'SAVE SOLUTION'}</span>
758
+ </button>
759
+ </div>
760
+ </div>
761
+ ) : activeSolution ? (
762
+ /* VIEWING ACTIVE SOLUTION */
763
+ <div className="space-y-3.5">
764
+ {/* Solution Metadata Banner (Pattern, Time, Space shown right here!) */}
765
+ <div className="p-3 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] flex flex-col sm:flex-row sm:items-center justify-between gap-2.5">
766
+ <div className="flex items-center gap-2 flex-wrap">
767
+ <h3 className="font-headline-md font-extrabold text-sm sm:text-base text-ink-black m-0 select-text">
768
+ {activeSolution.name || `Solution ${safeIndex + 1}`}
769
+ </h3>
770
+ {activeSolution.is_optimal && (
771
+ <span className="px-2 py-0.5 bg-amber-300 border border-ink-black font-arcade text-[8px] font-bold text-ink-black shadow-[1px_1px_0px_0px_rgba(30,41,59,1)]">
772
+ ★ OPTIMAL
773
+ </span>
774
+ )}
775
+ </div>
776
+
777
+ {/* Pattern & Complexities for this specific solution! */}
778
+ <div className="flex items-center gap-2 flex-wrap sm:ml-auto">
779
+ <div className="flex items-center gap-1">
780
+ <span className="font-arcade text-[8px] text-trash-gray uppercase">Pattern:</span>
781
+ <span className="px-2 py-0.5 bg-purple-50 border border-purple-300 font-arcade text-[8.5px] text-purple-800 font-bold">
782
+ {activeSolution.pattern || 'General Algorithm'}
783
+ </span>
784
+ </div>
785
+ <div className="flex items-center gap-1.5">
786
+ <code className="bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black font-bold">
787
+ T: {activeSolution.time_complexity || 'O(N)'}
788
+ </code>
789
+ <code className="bg-[#1E293B] text-[#4ADE80] font-code-mono px-1.5 py-0.5 text-[11px] border border-ink-black font-bold">
790
+ S: {activeSolution.space_complexity || 'O(1)'}
791
+ </code>
792
+ </div>
793
+ <div className="flex items-center gap-1 ml-auto">
794
  <button
795
+ type="button"
796
+ onClick={() => {
797
+ setEditingSolutionId(activeSolution.id);
798
+ setIsAddingSolution(false);
799
+ setSolutionForm({
800
+ name: activeSolution.name,
801
+ pattern: activeSolution.pattern,
802
+ time_complexity: activeSolution.time_complexity,
803
+ space_complexity: activeSolution.space_complexity,
804
+ code: activeSolution.code,
805
+ explanation: activeSolution.explanation || '',
806
+ is_optimal: Boolean(activeSolution.is_optimal)
807
+ });
808
+ }}
809
+ className="px-2 py-1 bg-white hover:bg-slate-100 border border-ink-black text-ink-black font-arcade text-[8px] font-bold flex items-center gap-1 cursor-pointer"
810
+ title="Edit this solution"
811
  >
812
+ <Edit3 className="w-3 h-3 text-slate-700" />
813
+ <span className="hidden sm:inline">EDIT</span>
814
  </button>
815
+ {solutions.length > 1 && (
816
+ <button
817
+ type="button"
818
+ onClick={() => handleDeleteSolution(activeSolution.id)}
819
+ className="px-1.5 py-1 bg-white hover:bg-rose-50 border border-ink-black text-rose-700 font-arcade text-[8px] font-bold flex items-center gap-1 cursor-pointer"
820
+ title="Delete this solution"
821
+ >
822
+ <Trash2 className="w-3 h-3" />
823
+ </button>
824
+ )}
825
  </div>
826
  </div>
827
+ </div>
828
+
829
+ {/* Reference Code Container */}
830
+ {activeSolution.code ? (
831
+ <div className="border-2 border-ink-black bg-[#0f172a] shadow-[3px_3px_0px_0px_rgba(30,41,59,1)]">
832
+ <div className="bg-[#1e293b] px-3 py-1.5 border-b-2 border-ink-black flex items-center justify-between">
833
+ <span className="font-arcade text-[8px] text-slate-300 font-bold uppercase">
834
+ PYTHON 3 IMPLEMENTATION
835
+ </span>
836
  <button
837
+ onClick={() => onCopyText(activeSolution.code, `sol-${activeSolution.id}`)}
838
+ className="px-2 py-0.5 bg-white hover:bg-slate-100 text-ink-black border border-ink-black text-[9px] font-arcade font-bold flex items-center gap-1 cursor-pointer shrink-0"
839
+ title="Copy solution code"
840
  >
841
  <Copy className="w-2.5 h-2.5" />
842
+ {copiedSnippet === `sol-${activeSolution.id}` ? 'COPIED!' : 'COPY'}
843
  </button>
844
  </div>
845
+ <div className="p-3 text-xs overflow-x-auto max-h-80 custom-scrollbar">
846
  <pre className="font-code-mono text-[#4ADE80] text-[11px] leading-relaxed select-text m-0">
847
+ <code>{activeSolution.code}</code>
848
  </pre>
849
  </div>
850
  </div>
851
  ) : (
852
  <div className="p-4 bg-amber-50 border-2 border-dashed border-amber-300 text-center space-y-3 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)]">
853
+ <p className="text-xs font-sans text-stone-700">No code implementation archived for this solution yet.</p>
854
  <button
855
  onClick={onFetchAiSolution}
856
  disabled={aiSolutionLoading}
 
873
  )}
874
  </div>
875
  )}
 
 
876
 
877
+ {/* Solution Explanation / Intuition */}
878
+ {activeSolution.explanation && (
879
+ <div className="p-3.5 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-1.5 select-text">
880
+ <span className="font-arcade text-[8.5px] text-trash-gray uppercase font-bold block">
881
+ SOLUTION INTUITION & STRATEGY:
882
+ </span>
883
+ <div className="font-sans text-xs text-slate-800 leading-relaxed font-medium space-y-1.5">
884
+ {parseMarkdown(activeSolution.explanation)}
 
 
 
 
 
 
 
 
 
 
 
885
  </div>
886
  </div>
887
+ )}
888
+
889
+ {/* Gemini Code Explanation Action */}
890
+ {activeSolution.code && (
891
+ <div className="space-y-3 pt-1">
892
+ <button
893
+ onClick={() =>
894
+ onExplainCode(
895
+ activeSolution.code,
896
+ activeSolution.pattern,
897
+ activeSolution.time_complexity,
898
+ activeSolution.space_complexity
899
+ )
900
+ }
901
+ disabled={explainLoading}
902
+ className="w-full bg-amber-300 hover:bg-amber-400 border-2 border-ink-black text-ink-black font-arcade text-[9px] py-2.5 px-4 font-bold flex items-center justify-center gap-2 shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] active:translate-y-0.5 active:shadow-none transition-all cursor-pointer disabled:opacity-50"
903
+ >
904
+ {explainLoading ? (
905
+ <>
906
+ <RefreshCw className="w-3.5 h-3.5 animate-spin" />
907
+ <span>EXPLAINING THIS SOLUTION VIA GEMINI...</span>
908
+ </>
909
+ ) : (
910
+ <>
911
+ <Sparkles className="w-3.5 h-3.5 text-purple-700" />
912
+ <span>EXPLAIN THIS SOLUTION WITH GEMINI</span>
913
+ </>
914
+ )}
915
+ </button>
916
+
917
+ {explainError && (
918
+ <div className="p-3 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-semibold">
919
+ {explainError}
920
+ </div>
921
+ )}
922
+
923
+ {explanationText && (
924
+ <div className="p-4 bg-white border-2 border-ink-black shadow-[2px_2px_0px_0px_rgba(30,41,59,1)] space-y-2 select-text">
925
+ <div className="flex items-center gap-1.5 pb-2 border-b-2 border-dashed border-ink-black">
926
+ <BrainCircuit className="w-4 h-4 text-purple-600" />
927
+ <span className="font-arcade text-[9px] font-bold text-ink-black uppercase">
928
+ Gemini Code Breakdown ({activeSolution.name})
929
+ </span>
930
+ </div>
931
+ <div className="font-sans text-xs space-y-2 max-h-80 overflow-y-auto custom-scrollbar pt-1 font-medium text-slate-800">
932
+ {parseMarkdown(explanationText)}
933
+ </div>
934
+ </div>
935
  )}
936
  </div>
937
  )}
938
+ </div>
939
+ ) : null}
 
940
 
 
941
  {saveRefError && (
942
  <div className="p-2.5 border-2 border-rose-500 bg-rose-50 text-rose-800 text-xs font-bold flex items-center gap-2 shadow-[2px_2px_0px_0px_rgba(244,63,94,1)]">
943
  <AlertTriangle className="w-4 h-4 text-rose-600 shrink-0" />
944
  <div className="flex-1">{saveRefError}</div>
945
  </div>
946
  )}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
947
  </div>
948
  )}
949
 
algospaced-ui/src/components/review/ReviewHeader.tsx CHANGED
@@ -6,6 +6,8 @@ import {
6
  ChevronDown
7
  } from 'lucide-react';
8
  import type { ProblemItem, ReviewItem } from '../../types/reviewTypes';
 
 
9
 
10
  interface ReviewHeaderProps {
11
  problem: ProblemItem;
@@ -67,7 +69,9 @@ export const ReviewHeader: React.FC<ReviewHeaderProps> = ({
67
  {reviews.map((rev, idx) => {
68
  const revProb = rev.problems || {};
69
  const num = revProb.problem_number;
70
- const title = revProb.name || 'Algorithm Problem';
 
 
71
  const isCurrent = idx === 0;
72
  return (
73
  <div
@@ -85,7 +89,7 @@ export const ReviewHeader: React.FC<ReviewHeaderProps> = ({
85
  LC #{num}
86
  </span>
87
  )}
88
- <span className="truncate">{title}</span>
89
  </div>
90
  <span
91
  className={`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black text-white shrink-0 ${
 
6
  ChevronDown
7
  } from 'lucide-react';
8
  import type { ProblemItem, ReviewItem } from '../../types/reviewTypes';
9
+ import { parseProblemTitle } from '../../utils/problemContentParser';
10
+ import { getCatalogProblemByNumber } from '../../services/catalogService';
11
 
12
  interface ReviewHeaderProps {
13
  problem: ProblemItem;
 
69
  {reviews.map((rev, idx) => {
70
  const revProb = rev.problems || {};
71
  const num = revProb.problem_number;
72
+ const catProb = num !== undefined && num !== null ? getCatalogProblemByNumber(num) : undefined;
73
+ const { cleanTitle, approachVariant } = parseProblemTitle(revProb.name, catProb?.name);
74
+ const displayTitle = approachVariant ? `${cleanTitle} (${approachVariant})` : cleanTitle;
75
  const isCurrent = idx === 0;
76
  return (
77
  <div
 
89
  LC #{num}
90
  </span>
91
  )}
92
+ <span className="truncate">{displayTitle}</span>
93
  </div>
94
  <span
95
  className={`text-[8px] font-arcade font-bold px-1.5 py-0.5 border border-ink-black text-white shrink-0 ${
algospaced-ui/src/hooks/useAiReviewer.ts CHANGED
@@ -61,7 +61,13 @@ export function useAiReviewer() {
61
  );
62
 
63
  const handleExplainCode = useCallback(
64
- async (activeReview: ReviewItem | undefined) => {
 
 
 
 
 
 
65
  if (!activeReview || explainLoading) return;
66
  const problem = activeReview.problems;
67
  if (!problem) return;
@@ -70,7 +76,7 @@ export function useAiReviewer() {
70
  ? getCatalogProblemByNumber(problem.problem_number)
71
  : getCatalogProblemById(problem.id || '');
72
 
73
- const refCode = problem.reference_code || catalogProb?.reference_solution;
74
  if (!refCode) return;
75
 
76
  setExplainLoading(true);
@@ -89,11 +95,11 @@ export function useAiReviewer() {
89
  },
90
  body: JSON.stringify({
91
  problem_number: problem.problem_number || catalogProb?.problem_number,
92
- method: problem.pattern || catalogProb?.pattern,
93
  code: refCode,
94
  problem_name: problem.name,
95
- optimal_time: problem.optimal_time || catalogProb?.time_complexity,
96
- optimal_space: problem.optimal_space || catalogProb?.space_complexity
97
  })
98
  });
99
 
 
61
  );
62
 
63
  const handleExplainCode = useCallback(
64
+ async (
65
+ activeReview: ReviewItem | undefined,
66
+ overrideCode?: string,
67
+ overridePattern?: string,
68
+ overrideTime?: string,
69
+ overrideSpace?: string
70
+ ) => {
71
  if (!activeReview || explainLoading) return;
72
  const problem = activeReview.problems;
73
  if (!problem) return;
 
76
  ? getCatalogProblemByNumber(problem.problem_number)
77
  : getCatalogProblemById(problem.id || '');
78
 
79
+ const refCode = overrideCode || problem.reference_code || catalogProb?.reference_solution;
80
  if (!refCode) return;
81
 
82
  setExplainLoading(true);
 
95
  },
96
  body: JSON.stringify({
97
  problem_number: problem.problem_number || catalogProb?.problem_number,
98
+ method: overridePattern || problem.pattern || catalogProb?.pattern,
99
  code: refCode,
100
  problem_name: problem.name,
101
+ optimal_time: overrideTime || problem.optimal_time || catalogProb?.time_complexity,
102
+ optimal_space: overrideSpace || problem.optimal_space || catalogProb?.space_complexity
103
  })
104
  });
105
 
algospaced-ui/src/hooks/useReviewQueue.ts CHANGED
@@ -3,8 +3,7 @@ import { supabase } from '../firebaseClient';
3
  import confetti from 'canvas-confetti';
4
  import { companionStore } from '../features/companion';
5
  import {
6
- getCatalogProblemByNumber,
7
- getCatalogProblemById,
8
  getNextUnsolvedProblem,
9
  type CatalogProblem
10
  } from '../services/catalogService';
@@ -88,9 +87,10 @@ export function useReviewQueue({
88
  // attempt auto-activation from the canonical catalog
89
  if (overrideProblemId && (!data || data.length === 0)) {
90
  const isNumeric = /^\d+$/.test(overrideProblemId);
91
- const catalogProb = isNumeric
92
- ? getCatalogProblemByNumber(parseInt(overrideProblemId, 10))
93
- : getCatalogProblemById(overrideProblemId);
 
94
 
95
  if (catalogProb) {
96
  try {
@@ -128,11 +128,13 @@ export function useReviewQueue({
128
  const rawProblem = activeReview.problems;
129
  const probNum = rawProblem?.problem_number ??
130
  (/^\d+$/.test(activeReview?.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined);
131
- const catalogProb = probNum !== undefined
132
- ? getCatalogProblemByNumber(probNum)
133
- : (getCatalogProblemById(rawProblem?.id) || getCatalogProblemById(activeReview?.problem_id));
 
 
134
 
135
- const starter = rawProblem?.starter_code || catalogProb?.starter_code || '';
136
  setCode(starter);
137
  } else {
138
  // Empty queue: discover next milestone from journey progress
@@ -265,10 +267,12 @@ export function useReviewQueue({
265
  const rawProb = nextActive.problems;
266
  const probNum = rawProb?.problem_number ??
267
  (/^\d+$/.test(nextActive?.problem_id || '') ? parseInt(nextActive.problem_id, 10) : undefined);
268
- const catalogProb = probNum !== undefined
269
- ? getCatalogProblemByNumber(probNum)
270
- : (getCatalogProblemById(rawProb?.id) || getCatalogProblemById(nextActive?.problem_id));
271
- const nextStarter = rawProb?.starter_code || catalogProb?.starter_code || '';
 
 
272
  setCode(nextStarter);
273
  } else {
274
  setCode('');
@@ -313,11 +317,13 @@ export function useReviewQueue({
313
  const rawProblem = activeReview?.problems;
314
  const probNum = rawProblem?.problem_number ??
315
  (/^\d+$/.test(activeReview?.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined);
316
- const catalogProb = probNum !== undefined
317
- ? getCatalogProblemByNumber(probNum)
318
- : (getCatalogProblemById(rawProblem?.id) || getCatalogProblemById(activeReview?.problem_id));
 
 
319
 
320
- const starter = rawProblem?.starter_code || catalogProb?.starter_code || '';
321
  setCode(starter);
322
  }, [reviews]);
323
 
 
3
  import confetti from 'canvas-confetti';
4
  import { companionStore } from '../features/companion';
5
  import {
6
+ findCatalogProblem,
 
7
  getNextUnsolvedProblem,
8
  type CatalogProblem
9
  } from '../services/catalogService';
 
87
  // attempt auto-activation from the canonical catalog
88
  if (overrideProblemId && (!data || data.length === 0)) {
89
  const isNumeric = /^\d+$/.test(overrideProblemId);
90
+ const catalogProb = findCatalogProblem(
91
+ isNumeric ? parseInt(overrideProblemId, 10) : undefined,
92
+ overrideProblemId
93
+ );
94
 
95
  if (catalogProb) {
96
  try {
 
128
  const rawProblem = activeReview.problems;
129
  const probNum = rawProblem?.problem_number ??
130
  (/^\d+$/.test(activeReview?.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined);
131
+ const catalogProb = findCatalogProblem(
132
+ probNum,
133
+ rawProblem?.id || activeReview?.problem_id,
134
+ rawProblem?.name
135
+ );
136
 
137
+ const starter = catalogProb?.starter_code || rawProblem?.starter_code || '';
138
  setCode(starter);
139
  } else {
140
  // Empty queue: discover next milestone from journey progress
 
267
  const rawProb = nextActive.problems;
268
  const probNum = rawProb?.problem_number ??
269
  (/^\d+$/.test(nextActive?.problem_id || '') ? parseInt(nextActive.problem_id, 10) : undefined);
270
+ const catalogProb = findCatalogProblem(
271
+ probNum,
272
+ rawProb?.id || nextActive?.problem_id,
273
+ rawProb?.name
274
+ );
275
+ const nextStarter = catalogProb?.starter_code || rawProb?.starter_code || '';
276
  setCode(nextStarter);
277
  } else {
278
  setCode('');
 
317
  const rawProblem = activeReview?.problems;
318
  const probNum = rawProblem?.problem_number ??
319
  (/^\d+$/.test(activeReview?.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined);
320
+ const catalogProb = findCatalogProblem(
321
+ probNum,
322
+ rawProblem?.id || activeReview?.problem_id,
323
+ rawProblem?.name
324
+ );
325
 
326
+ const starter = catalogProb?.starter_code || rawProblem?.starter_code || '';
327
  setCode(starter);
328
  }, [reviews]);
329
 
algospaced-ui/src/hooks/useSandboxRunner.ts CHANGED
@@ -5,7 +5,7 @@ import {
5
  type SandboxRunResult,
6
  type SaveReferenceMetadata
7
  } from '../services/reviewService';
8
- import { getCatalogProblemByNumber, getCatalogProblemById } from '../services/catalogService';
9
  import type { ReviewItem } from '../types/reviewTypes';
10
 
11
  export function useSandboxRunner() {
@@ -21,9 +21,11 @@ export function useSandboxRunner() {
21
  async (activeReview: ReviewItem | undefined, code: string) => {
22
  if (!activeReview || !code.trim() || sandboxRunning) return;
23
  const problem = activeReview.problems;
24
- const catalogProb = problem?.problem_number
25
- ? getCatalogProblemByNumber(problem.problem_number)
26
- : getCatalogProblemById(problem?.id || '');
 
 
27
 
28
  const rawExamples = problem?.examples && problem.examples.length > 0
29
  ? problem.examples
@@ -34,7 +36,7 @@ export function useSandboxRunner() {
34
  return { input: ex?.input ?? '', expected: ex?.output ?? '' };
35
  });
36
 
37
- const starterCode = problem?.starter_code || catalogProb?.starter_code;
38
  const problemName = problem?.name || catalogProb?.name;
39
 
40
  setSandboxRunning(true);
@@ -72,9 +74,11 @@ export function useSandboxRunner() {
72
  : (/^\d+$/.test(activeReview.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined)
73
  );
74
 
75
- const catalogProb = probNum !== undefined
76
- ? getCatalogProblemByNumber(probNum)
77
- : (getCatalogProblemById(rawProbId) || getCatalogProblemById(activeReview.problem_id));
 
 
78
 
79
  const rawConstraints = problem?.constraints ?? catalogProb?.constraints;
80
  const formattedConstraints: string[] = Array.isArray(rawConstraints)
@@ -100,7 +104,7 @@ export function useSandboxRunner() {
100
  optimal_time: problem?.optimal_time || catalogProb?.time_complexity,
101
  optimal_space: problem?.optimal_space || catalogProb?.space_complexity,
102
  description: problem?.description || catalogProb?.description,
103
- starter_code: problem?.starter_code || catalogProb?.starter_code,
104
  examples: formattedExamples,
105
  constraints: formattedConstraints,
106
  };
 
5
  type SandboxRunResult,
6
  type SaveReferenceMetadata
7
  } from '../services/reviewService';
8
+ import { findCatalogProblem } from '../services/catalogService';
9
  import type { ReviewItem } from '../types/reviewTypes';
10
 
11
  export function useSandboxRunner() {
 
21
  async (activeReview: ReviewItem | undefined, code: string) => {
22
  if (!activeReview || !code.trim() || sandboxRunning) return;
23
  const problem = activeReview.problems;
24
+ const catalogProb = findCatalogProblem(
25
+ problem?.problem_number,
26
+ problem?.id || '',
27
+ problem?.name
28
+ );
29
 
30
  const rawExamples = problem?.examples && problem.examples.length > 0
31
  ? problem.examples
 
36
  return { input: ex?.input ?? '', expected: ex?.output ?? '' };
37
  });
38
 
39
+ const starterCode = catalogProb?.starter_code || problem?.starter_code;
40
  const problemName = problem?.name || catalogProb?.name;
41
 
42
  setSandboxRunning(true);
 
74
  : (/^\d+$/.test(activeReview.problem_id || '') ? parseInt(activeReview.problem_id, 10) : undefined)
75
  );
76
 
77
+ const catalogProb = findCatalogProblem(
78
+ probNum,
79
+ rawProbId || activeReview.problem_id,
80
+ problem?.name
81
+ );
82
 
83
  const rawConstraints = problem?.constraints ?? catalogProb?.constraints;
84
  const formattedConstraints: string[] = Array.isArray(rawConstraints)
 
104
  optimal_time: problem?.optimal_time || catalogProb?.time_complexity,
105
  optimal_space: problem?.optimal_space || catalogProb?.space_complexity,
106
  description: problem?.description || catalogProb?.description,
107
+ starter_code: catalogProb?.starter_code || problem?.starter_code,
108
  examples: formattedExamples,
109
  constraints: formattedConstraints,
110
  };
algospaced-ui/src/services/catalogService.ts CHANGED
@@ -50,6 +50,44 @@ export function getCatalogProblemById(id: string | undefined | null): CatalogPro
50
  return undefined;
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  /**
54
  * Returns all 150 curated problems in canonical expedition sequence.
55
  */
 
50
  return undefined;
51
  }
52
 
53
+ /**
54
+ * Returns a catalog problem by its problem name/title.
55
+ */
56
+ export function getCatalogProblemByName(name: string | undefined | null): CatalogProblem | undefined {
57
+ if (!name) return undefined;
58
+ const cleanName = name.toLowerCase().replace(/\s*-\s*method.*$/i, '').replace(/[^a-z0-9]+/g, '');
59
+ for (const prob of NEETCODE_150_DATA) {
60
+ const probNormalized = prob.name.toLowerCase().replace(/[^a-z0-9]+/g, '');
61
+ if (probNormalized === cleanName) {
62
+ return prob;
63
+ }
64
+ }
65
+ return undefined;
66
+ }
67
+
68
+ /**
69
+ * Robust, unified catalog lookup across problem number, ID, and problem title.
70
+ */
71
+ export function findCatalogProblem(
72
+ problemNumber?: number | string | null,
73
+ id?: string | null,
74
+ name?: string | null
75
+ ): CatalogProblem | undefined {
76
+ if (problemNumber !== undefined && problemNumber !== null) {
77
+ const p = getCatalogProblemByNumber(problemNumber);
78
+ if (p) return p;
79
+ }
80
+ if (id) {
81
+ const p = getCatalogProblemById(id);
82
+ if (p) return p;
83
+ }
84
+ if (name) {
85
+ const p = getCatalogProblemByName(name);
86
+ if (p) return p;
87
+ }
88
+ return undefined;
89
+ }
90
+
91
  /**
92
  * Returns all 150 curated problems in canonical expedition sequence.
93
  */
algospaced-ui/src/services/reviewService.ts CHANGED
@@ -1,5 +1,6 @@
1
  import { supabase } from '../firebaseClient';
2
  import type { CatalogProblem } from './catalogService';
 
3
 
4
  export interface ActivateProblemPayload {
5
  problem_number: number;
@@ -158,6 +159,50 @@ export async function saveReferenceSolution(
158
  return res.json();
159
  }
160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  /**
162
  * Retrieves the stored reference solution (0 LLM tokens) or generates via AI grimoire.
163
  */
 
1
  import { supabase } from '../firebaseClient';
2
  import type { CatalogProblem } from './catalogService';
3
+ import type { ProblemSolution, ProblemItem } from '../types/reviewTypes';
4
 
5
  export interface ActivateProblemPayload {
6
  problem_number: number;
 
159
  return res.json();
160
  }
161
 
162
+ /**
163
+ * Updates the solutions array for a problem.
164
+ */
165
+ export async function updateProblemSolutions(
166
+ problemId: string,
167
+ solutions: ProblemSolution[],
168
+ optimalTime?: string,
169
+ optimalSpace?: string,
170
+ additionalData?: Partial<ProblemItem>
171
+ ): Promise<{ success: boolean; problem_id: string }> {
172
+ const token = await getAuthToken();
173
+ const optimalSol = solutions.find((s) => s.is_optimal) || solutions[0];
174
+ const payload = {
175
+ name: additionalData?.name || 'Problem',
176
+ pattern: optimalSol?.pattern || additionalData?.pattern || 'General',
177
+ difficulty: additionalData?.difficulty || 'Medium',
178
+ reference_code: optimalSol?.code || additionalData?.reference_code || '',
179
+ description: additionalData?.description || '',
180
+ problem_number: additionalData?.problem_number ?? null,
181
+ optimal_time: optimalTime || optimalSol?.time_complexity || additionalData?.optimal_time || 'O(N)',
182
+ optimal_space: optimalSpace || optimalSol?.space_complexity || additionalData?.optimal_space || 'O(1)',
183
+ examples: additionalData?.examples,
184
+ constraints: additionalData?.constraints,
185
+ how_to_solve: additionalData?.how_to_solve || '',
186
+ solutions
187
+ };
188
+
189
+ const res = await fetch(`${import.meta.env.VITE_API_BASE_URL}/api/explorer/problems/${problemId}`, {
190
+ method: 'PUT',
191
+ headers: {
192
+ 'Content-Type': 'application/json',
193
+ 'Authorization': `Bearer ${token}`
194
+ },
195
+ body: JSON.stringify(payload)
196
+ });
197
+
198
+ if (!res.ok) {
199
+ const err = await res.json().catch(() => ({ detail: 'Failed to update problem solutions' }));
200
+ throw new Error(err.detail || 'Failed to update problem solutions');
201
+ }
202
+
203
+ return res.json();
204
+ }
205
+
206
  /**
207
  * Retrieves the stored reference solution (0 LLM tokens) or generates via AI grimoire.
208
  */
algospaced-ui/src/types/reviewTypes.ts CHANGED
@@ -1,8 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
1
  export interface ProblemItem {
2
  id?: string;
3
  name: string;
4
  problem_number?: number;
5
  pattern: string;
 
6
  difficulty: 'Easy' | 'Medium' | 'Hard';
7
  description?: string;
8
  examples?: Array<{ input?: string; output?: string; explanation?: string } | string>;
@@ -13,6 +25,7 @@ export interface ProblemItem {
13
  starter_code?: string;
14
  reference_code?: string;
15
  how_to_solve?: string;
 
16
  }
17
 
18
  export interface ReviewItem {
 
1
+ export interface ProblemSolution {
2
+ id: string;
3
+ name: string;
4
+ pattern: string;
5
+ time_complexity: string;
6
+ space_complexity: string;
7
+ code: string;
8
+ explanation?: string;
9
+ is_optimal?: boolean;
10
+ }
11
+
12
  export interface ProblemItem {
13
  id?: string;
14
  name: string;
15
  problem_number?: number;
16
  pattern: string;
17
+ approach_variant?: string | null;
18
  difficulty: 'Easy' | 'Medium' | 'Hard';
19
  description?: string;
20
  examples?: Array<{ input?: string; output?: string; explanation?: string } | string>;
 
25
  starter_code?: string;
26
  reference_code?: string;
27
  how_to_solve?: string;
28
+ solutions?: ProblemSolution[];
29
  }
30
 
31
  export interface ReviewItem {
algospaced-ui/src/utils/problemContentParser.tsx CHANGED
@@ -1,5 +1,5 @@
1
  import React from 'react';
2
- import type { ProblemItem, ParsedExample } from '../types/reviewTypes';
3
 
4
  export function parseProblemContent(problem: ProblemItem | null | undefined): {
5
  description: string;
@@ -191,3 +191,171 @@ export function parseMarkdown(text: string): React.ReactNode[] {
191
  });
192
  });
193
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import React from 'react';
2
+ import type { ProblemItem, ParsedExample, ProblemSolution } from '../types/reviewTypes';
3
 
4
  export function parseProblemContent(problem: ProblemItem | null | undefined): {
5
  description: string;
 
191
  });
192
  });
193
  }
194
+
195
+ export interface ParsedProblemTitle {
196
+ cleanTitle: string;
197
+ approachVariant: string | null;
198
+ pattern: string;
199
+ }
200
+
201
+ /**
202
+ * Normalizes problem title, extracts approach variants (e.g. "Hash Map (One-Pass)"),
203
+ * and resolves the canonical algorithm pattern, preventing repetitive "Method 1" echoes.
204
+ */
205
+ export function parseProblemTitle(
206
+ rawName: string | undefined | null,
207
+ catalogName?: string | null,
208
+ rawPattern?: string | null,
209
+ catalogPattern?: string | null
210
+ ): ParsedProblemTitle {
211
+ const isGeneric = (str?: string | null) =>
212
+ !str || /^Method\s*\d*$/i.test(str.trim()) || str.trim().toLowerCase() === 'standard';
213
+
214
+ let name = (rawName || catalogName || 'Algorithm Problem').trim();
215
+ let approachVariant: string | null = null;
216
+
217
+ // 1. If catalogName is provided and name starts with catalogName, extract the suffix
218
+ if (catalogName && name.toLowerCase().startsWith(catalogName.toLowerCase())) {
219
+ const suffix = name.slice(catalogName.length).trim();
220
+ name = catalogName; // Canonical clean title
221
+
222
+ if (suffix) {
223
+ // Check for:
224
+ // " - Method 1 (Hash Map (One-Pass))"
225
+ // " - Method 1 (Method 1)"
226
+ const methodWithParenMatch = suffix.match(/^[-\s]*Method\s*(\d+)\s*\((.+)\)$/i);
227
+ if (methodWithParenMatch) {
228
+ const methodNum = parseInt(methodWithParenMatch[1], 10);
229
+ const parenContent = methodWithParenMatch[2].trim();
230
+ if (!isGeneric(parenContent)) {
231
+ approachVariant = parenContent;
232
+ } else if (methodNum > 1) {
233
+ approachVariant = `Method ${methodNum}`;
234
+ }
235
+ } else {
236
+ const methodOnlyMatch = suffix.match(/^[-\s]*Method\s*(\d+)/i);
237
+ if (methodOnlyMatch) {
238
+ const methodNum = parseInt(methodOnlyMatch[1], 10);
239
+ if (methodNum > 1) {
240
+ approachVariant = `Method ${methodNum}`;
241
+ }
242
+ } else {
243
+ const parenMatch = suffix.match(/^[-\s]*\((.+)\)$/);
244
+ if (parenMatch) {
245
+ const parenContent = parenMatch[1].trim();
246
+ if (!isGeneric(parenContent)) {
247
+ approachVariant = parenContent;
248
+ }
249
+ } else {
250
+ const hyphenMatch = suffix.match(/^[-\s]+([^-]+)$/);
251
+ if (hyphenMatch && !isGeneric(hyphenMatch[1])) {
252
+ approachVariant = hyphenMatch[1].trim();
253
+ }
254
+ }
255
+ }
256
+ }
257
+ }
258
+ } else {
259
+ // 2. Fallback when catalogName is not available or doesn't match prefix
260
+ const methodParenRegex = /^(.*?)\s*-\s*Method\s*(\d+)\s*\((.+)\)$/i;
261
+ const methodParenMatch = name.match(methodParenRegex);
262
+ if (methodParenMatch) {
263
+ name = methodParenMatch[1].trim();
264
+ const methodNum = parseInt(methodParenMatch[2], 10);
265
+ const parenContent = methodParenMatch[3].trim();
266
+ if (!isGeneric(parenContent)) {
267
+ approachVariant = parenContent;
268
+ } else if (methodNum > 1) {
269
+ approachVariant = `Method ${methodNum}`;
270
+ }
271
+ } else {
272
+ const methodRegex = /^(.*?)\s*-\s*Method\s*(\d+)$/i;
273
+ const methodMatch = name.match(methodRegex);
274
+ if (methodMatch) {
275
+ name = methodMatch[1].trim();
276
+ const methodNum = parseInt(methodMatch[2], 10);
277
+ if (methodNum > 1) {
278
+ approachVariant = `Method ${methodNum}`;
279
+ }
280
+ } else {
281
+ const parenMethodRegex = /^(.*?)\s*\(\s*Method\s*(\d+)\s*\)$/i;
282
+ const parenMethodMatch = name.match(parenMethodRegex);
283
+ if (parenMethodMatch) {
284
+ name = parenMethodMatch[1].trim();
285
+ const methodNum = parseInt(parenMethodMatch[2], 10);
286
+ if (methodNum > 1) {
287
+ approachVariant = `Method ${methodNum}`;
288
+ }
289
+ }
290
+ }
291
+ }
292
+ }
293
+
294
+ // Determine resolved pattern:
295
+ let resolvedPattern = 'General Algorithm';
296
+ if (!isGeneric(rawPattern)) {
297
+ resolvedPattern = rawPattern!.trim();
298
+ } else if (!isGeneric(catalogPattern)) {
299
+ resolvedPattern = catalogPattern!.trim();
300
+ } else if (approachVariant && !isGeneric(approachVariant)) {
301
+ resolvedPattern = approachVariant;
302
+ }
303
+
304
+ return {
305
+ cleanTitle: name,
306
+ approachVariant,
307
+ pattern: resolvedPattern
308
+ };
309
+ }
310
+
311
+ /**
312
+ * Normalizes problem solutions into a clean ProblemSolution[] array.
313
+ * If the problem has a dedicated solutions array, it uses it.
314
+ * Otherwise, it creates fallback solutions from reference_code, pattern, optimal_time, optimal_space, and userSolution.
315
+ */
316
+ export function normalizeProblemSolutions(
317
+ problem: ProblemItem | null | undefined,
318
+ officialSolution?: string,
319
+ userSolution?: string
320
+ ): ProblemSolution[] {
321
+ if (!problem) return [];
322
+
323
+ if (Array.isArray(problem.solutions) && problem.solutions.length > 0) {
324
+ return problem.solutions;
325
+ }
326
+
327
+ const results: ProblemSolution[] = [];
328
+ const primaryCode = officialSolution || problem.reference_code || '';
329
+ const pattern = problem.pattern || 'General Algorithm';
330
+ const timeComplexity = problem.optimal_time || 'O(N)';
331
+ const spaceComplexity = problem.optimal_space || 'O(1)';
332
+
333
+ if (primaryCode || pattern) {
334
+ results.push({
335
+ id: 'sol-1',
336
+ name: problem.approach_variant || 'Optimal Solution',
337
+ pattern,
338
+ time_complexity: timeComplexity,
339
+ space_complexity: spaceComplexity,
340
+ code: primaryCode,
341
+ explanation: problem.how_to_solve || '',
342
+ is_optimal: true
343
+ });
344
+ }
345
+
346
+ // If user has a distinct personal solution not matching official, add as Solution 2
347
+ if (userSolution && userSolution.trim() && userSolution.trim() !== primaryCode.trim()) {
348
+ results.push({
349
+ id: 'sol-2',
350
+ name: 'Personal Solution',
351
+ pattern,
352
+ time_complexity: timeComplexity,
353
+ space_complexity: spaceComplexity,
354
+ code: userSolution,
355
+ is_optimal: false
356
+ });
357
+ }
358
+
359
+ return results;
360
+ }
361
+
core/problem_utils.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import re
2
 
3
  import ai_cache
@@ -5,51 +6,74 @@ import db
5
 
6
 
7
  def extract_starter_code(reference_code: str) -> str:
8
- if not reference_code:
 
 
 
 
 
 
9
  return ""
10
 
 
 
11
  lines = reference_code.splitlines()
12
- starter_lines = []
13
- in_def = False
14
-
15
  for line in lines:
16
  stripped = line.strip()
17
-
18
- # If we see a class, add it
19
- if stripped.startswith("class ") and not in_def:
20
- starter_lines.append(line)
21
- continue
22
-
23
- # If we see def, start adding lines
24
- if stripped.startswith("def ") and not in_def:
25
- in_def = True
26
- starter_lines.append(line)
27
- check_line = stripped.split("#")[0].strip()
28
- if check_line.endswith(":"):
29
- in_def = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  indent = len(line) - len(line.lstrip())
31
  starter_lines.append(" " * (indent + 4) + "pass")
32
- break
33
- continue
34
-
35
- # If we are inside a multi-line def, keep adding lines
36
- if in_def:
37
- starter_lines.append(line)
38
- check_line = stripped.split("#")[0].strip()
39
- if check_line.endswith(":"):
40
- in_def = False
41
- def_indent = 4
42
- for prev_line in reversed(starter_lines):
43
- if prev_line.strip().startswith("def "):
44
- def_indent = len(prev_line) - len(prev_line.lstrip())
45
- break
46
- starter_lines.append(" " * (def_indent + 4) + "pass")
47
- break
48
-
49
- if not starter_lines:
50
- return reference_code
51
-
52
- return "\n".join(starter_lines)
53
 
54
 
55
  def parse_examples_and_constraints_from_text(text: str):
 
1
+ import ast
2
  import re
3
 
4
  import ai_cache
 
6
 
7
 
8
  def extract_starter_code(reference_code: str) -> str:
9
+ """
10
+ Extracts a clean, spoiler-free starter code skeleton from reference_code.
11
+ Preserves all class definitions, helper type definition comments (e.g. ListNode/TreeNode),
12
+ and all function/method signatures with empty 'pass' bodies.
13
+ Never returns implementation logic or dumps the reference solution.
14
+ """
15
+ if not reference_code or not reference_code.strip():
16
  return ""
17
 
18
+ # 1. Collect any leading definition comments (e.g. # Definition for singly-linked list.)
19
+ leading_comments = []
20
  lines = reference_code.splitlines()
21
+ in_def_comment = False
 
 
22
  for line in lines:
23
  stripped = line.strip()
24
+ if stripped.startswith("# Definition for"):
25
+ in_def_comment = True
26
+ leading_comments.append(line)
27
+ elif in_def_comment:
28
+ if stripped.startswith("#"):
29
+ leading_comments.append(line)
30
+ else:
31
+ break
32
+ elif stripped.startswith("class ") or stripped.startswith("def "):
33
+ break
34
+
35
+ try:
36
+ tree = ast.parse(reference_code)
37
+
38
+ # Keep only ClassDef, FunctionDef, and AsyncFunctionDef to prevent leaking top-level state
39
+ defs = [
40
+ n
41
+ for n in tree.body
42
+ if isinstance(n, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef))
43
+ ]
44
+ if not defs:
45
+ return "def solve():\n pass\n"
46
+
47
+ tree.body = defs
48
+
49
+ class BodyStripper(ast.NodeTransformer):
50
+ def visit_FunctionDef(self, node):
51
+ node.body = [ast.Pass()]
52
+ return node
53
+
54
+ def visit_AsyncFunctionDef(self, node):
55
+ node.body = [ast.Pass()]
56
+ return node
57
+
58
+ new_tree = BodyStripper().visit(tree)
59
+ unparsed = ast.unparse(new_tree)
60
+ if leading_comments:
61
+ return "\n".join(leading_comments) + "\n" + unparsed
62
+ return unparsed
63
+ except Exception:
64
+ # Fallback to line scanning without leaking function bodies
65
+ starter_lines = []
66
+ for line in lines:
67
+ stripped = line.strip()
68
+ if stripped.startswith("class "):
69
+ starter_lines.append(line)
70
+ elif stripped.startswith("def "):
71
+ starter_lines.append(line)
72
  indent = len(line) - len(line.lstrip())
73
  starter_lines.append(" " * (indent + 4) + "pass")
74
+ if starter_lines:
75
+ return "\n".join(starter_lines)
76
+ return "def solve():\n pass\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
 
78
 
79
  def parse_examples_and_constraints_from_text(text: str):
db.py CHANGED
@@ -774,7 +774,9 @@ def get_reviews_by_problem_id(problem_id: str, client_or_user_id=None) -> list[d
774
  if res.data:
775
  return res.data
776
  # Fallback: check if problem_id is a problem_number string
777
- if isinstance(problem_id, int) or (isinstance(problem_id, str) and problem_id.strip().isdigit()):
 
 
778
  prob_num = int(problem_id)
779
  probs = get_problems_by_number(prob_num, client_or_user_id)
780
  for p in probs:
@@ -812,7 +814,10 @@ def get_reviews_by_problem_id(problem_id: str, client_or_user_id=None) -> list[d
812
  rev_data["problems"] = None
813
  reviews.append(rev_data)
814
 
815
- if not reviews and (isinstance(problem_id, int) or (isinstance(problem_id, str) and problem_id.strip().isdigit())):
 
 
 
816
  prob_num = int(problem_id)
817
  probs = get_problems_by_number(prob_num, user_id)
818
  for p in probs:
 
774
  if res.data:
775
  return res.data
776
  # Fallback: check if problem_id is a problem_number string
777
+ if isinstance(problem_id, int) or (
778
+ isinstance(problem_id, str) and problem_id.strip().isdigit()
779
+ ):
780
  prob_num = int(problem_id)
781
  probs = get_problems_by_number(prob_num, client_or_user_id)
782
  for p in probs:
 
814
  rev_data["problems"] = None
815
  reviews.append(rev_data)
816
 
817
+ if not reviews and (
818
+ isinstance(problem_id, int)
819
+ or (isinstance(problem_id, str) and problem_id.strip().isdigit())
820
+ ):
821
  prob_num = int(problem_id)
822
  probs = get_problems_by_number(prob_num, user_id)
823
  for p in probs:
gdrive_sync.py CHANGED
@@ -114,8 +114,8 @@ def extract_text_from_elements(elements):
114
 
115
 
116
  def parse_problem_body(problem_name, body):
117
- # Match headers like "Method 1:", "Method 2 (Two Pointers):", or just "Method:"
118
- method_matches = list(re.finditer(r"Method\s*(\d*)\s*(?:\(([^)]+)\))?:", body, re.IGNORECASE))
119
 
120
  difficulty = "Medium"
121
  diff_match = re.search(r"^\s*(Easy|Medium|Hard)\b", body, re.IGNORECASE | re.MULTILINE)
@@ -172,8 +172,10 @@ def parse_problem_body(problem_name, body):
172
 
173
  methods.append(
174
  {
175
- "name": f"{problem_name} - Method 1 ({global_pattern})",
176
- "pattern": global_pattern,
 
 
177
  "difficulty": difficulty,
178
  "optimal_time": optimal_time,
179
  "optimal_space": optimal_space,
@@ -226,10 +228,30 @@ def parse_problem_body(problem_name, body):
226
  raw_code = re.sub(r"\s*```$", "", raw_code)
227
  code = raw_code.strip()
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  methods.append(
230
  {
231
- "name": f"{problem_name} - Method {method_num} ({method_name})",
232
- "pattern": method_name,
233
  "difficulty": difficulty,
234
  "optimal_time": optimal_time,
235
  "optimal_space": optimal_space,
 
114
 
115
 
116
  def parse_problem_body(problem_name, body):
117
+ # Match headers like "Method 1:", "Method 2 (Two Pointers):", or "Method 1 (Hash Map (One-Pass)):"
118
+ method_matches = list(re.finditer(r"Method\s*(\d*)\s*(?:\((.+?)\))?\s*:", body, re.IGNORECASE))
119
 
120
  difficulty = "Medium"
121
  diff_match = re.search(r"^\s*(Easy|Medium|Hard)\b", body, re.IGNORECASE | re.MULTILINE)
 
172
 
173
  methods.append(
174
  {
175
+ "name": problem_name,
176
+ "pattern": global_pattern
177
+ if global_pattern and global_pattern != "Standard"
178
+ else "General Algorithm",
179
  "difficulty": difficulty,
180
  "optimal_time": optimal_time,
181
  "optimal_space": optimal_space,
 
228
  raw_code = re.sub(r"\s*```$", "", raw_code)
229
  code = raw_code.strip()
230
 
231
+ is_generic = (
232
+ not method_name
233
+ or re.match(r"^Method\s*\d*$", method_name, re.IGNORECASE)
234
+ or method_name.strip().lower() == "standard"
235
+ )
236
+
237
+ if is_generic:
238
+ if len(method_matches) == 1 and method_num in ("1", "01"):
239
+ cleaned_name = problem_name
240
+ else:
241
+ cleaned_name = f"{problem_name} - Method {method_num}"
242
+ pattern_val = (
243
+ global_pattern
244
+ if global_pattern and global_pattern != "Standard"
245
+ else "General Algorithm"
246
+ )
247
+ else:
248
+ cleaned_name = f"{problem_name} - Method {method_num} ({method_name})"
249
+ pattern_val = method_name
250
+
251
  methods.append(
252
  {
253
+ "name": cleaned_name,
254
+ "pattern": pattern_val,
255
  "difficulty": difficulty,
256
  "optimal_time": optimal_time,
257
  "optimal_space": optimal_space,
main.py CHANGED
@@ -16,6 +16,7 @@ except ImportError:
16
 
17
  # Core utilities & database initialization
18
  import db
 
19
  from core.auth import Client, UserSession, get_auth_session # noqa: F401 (re-exported)
20
  from core.limiter import check_burst_rate_limit # noqa: F401 (re-exported)
21
  from core.problem_utils import ( # noqa: F401 (re-exported)
@@ -32,8 +33,9 @@ mimetypes.add_type("text/css", ".css")
32
 
33
  logger = logging.getLogger("algospaced")
34
 
35
- # Initialize Firebase backend services
36
  db.init_firebase()
 
37
 
38
  app = FastAPI(title="AlgoSpaced API")
39
 
@@ -74,7 +76,6 @@ if os.path.exists(frontend_dist):
74
  if os.path.exists(sprites_dir):
75
  app.mount("/sprites", StaticFiles(directory=sprites_dir), name="sprites")
76
 
77
-
78
  @app.get("/", include_in_schema=False)
79
  def serve_root():
80
  index_file = os.path.join(frontend_dist, "index.html")
 
16
 
17
  # Core utilities & database initialization
18
  import db
19
+ import sandbox_db
20
  from core.auth import Client, UserSession, get_auth_session # noqa: F401 (re-exported)
21
  from core.limiter import check_burst_rate_limit # noqa: F401 (re-exported)
22
  from core.problem_utils import ( # noqa: F401 (re-exported)
 
33
 
34
  logger = logging.getLogger("algospaced")
35
 
36
+ # Initialize backend database services
37
  db.init_firebase()
38
+ sandbox_db.init_db()
39
 
40
  app = FastAPI(title="AlgoSpaced API")
41
 
 
76
  if os.path.exists(sprites_dir):
77
  app.mount("/sprites", StaticFiles(directory=sprites_dir), name="sprites")
78
 
 
79
  @app.get("/", include_in_schema=False)
80
  def serve_root():
81
  index_file = os.path.join(frontend_dist, "index.html")
routers/explorer.py CHANGED
@@ -36,6 +36,7 @@ class CreateProblemRequest(BaseModel):
36
  how_to_solve: str | None = ""
37
  sync_to_gdoc: bool | None = True
38
  google_doc_id: str | None = None
 
39
 
40
 
41
  class UpdateProblemRequest(BaseModel):
@@ -50,6 +51,7 @@ class UpdateProblemRequest(BaseModel):
50
  examples: Any | None = None
51
  constraints: Any | None = None
52
  how_to_solve: str | None = ""
 
53
 
54
 
55
  class FetchLeetCodeRequest(BaseModel):
@@ -175,6 +177,8 @@ def create_explorer_problem(req: CreateProblemRequest, client: Client = Depends(
175
  "constraints": req.constraints or [],
176
  "how_to_solve": req.how_to_solve or "",
177
  }
 
 
178
  res_prob = db.insert_problem(prob_data, client)
179
  if not res_prob or not res_prob.data:
180
  raise HTTPException(status_code=500, detail="Failed to create problem record")
@@ -251,6 +255,21 @@ def update_explorer_problem(
251
  update_data["constraints"] = req.constraints
252
  if req.how_to_solve is not None:
253
  update_data["how_to_solve"] = req.how_to_solve
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  # 1. First attempt to update directly with problem_id
256
  res = db.update_problem(problem_id, update_data, client)
@@ -293,6 +312,8 @@ def update_explorer_problem(
293
  "constraints": req.constraints or [],
294
  "how_to_solve": req.how_to_solve or "",
295
  }
 
 
296
  res_p = db.insert_problem(prob_data, client)
297
  if res_p and res_p.data:
298
  new_id = res_p.data[0]["id"]
 
36
  how_to_solve: str | None = ""
37
  sync_to_gdoc: bool | None = True
38
  google_doc_id: str | None = None
39
+ solutions: list[dict] | None = None
40
 
41
 
42
  class UpdateProblemRequest(BaseModel):
 
51
  examples: Any | None = None
52
  constraints: Any | None = None
53
  how_to_solve: str | None = ""
54
+ solutions: list[dict] | None = None
55
 
56
 
57
  class FetchLeetCodeRequest(BaseModel):
 
177
  "constraints": req.constraints or [],
178
  "how_to_solve": req.how_to_solve or "",
179
  }
180
+ if req.solutions is not None:
181
+ prob_data["solutions"] = req.solutions
182
  res_prob = db.insert_problem(prob_data, client)
183
  if not res_prob or not res_prob.data:
184
  raise HTTPException(status_code=500, detail="Failed to create problem record")
 
255
  update_data["constraints"] = req.constraints
256
  if req.how_to_solve is not None:
257
  update_data["how_to_solve"] = req.how_to_solve
258
+ if req.solutions is not None:
259
+ update_data["solutions"] = req.solutions
260
+ if req.solutions:
261
+ optimal_sol = next(
262
+ (s for s in req.solutions if s.get("is_optimal")), req.solutions[0]
263
+ )
264
+ if optimal_sol:
265
+ if optimal_sol.get("pattern"):
266
+ update_data["pattern"] = optimal_sol["pattern"]
267
+ if optimal_sol.get("time_complexity"):
268
+ update_data["optimal_time"] = optimal_sol["time_complexity"]
269
+ if optimal_sol.get("space_complexity"):
270
+ update_data["optimal_space"] = optimal_sol["space_complexity"]
271
+ if optimal_sol.get("code"):
272
+ update_data["reference_code"] = optimal_sol["code"]
273
 
274
  # 1. First attempt to update directly with problem_id
275
  res = db.update_problem(problem_id, update_data, client)
 
312
  "constraints": req.constraints or [],
313
  "how_to_solve": req.how_to_solve or "",
314
  }
315
+ if req.solutions is not None:
316
+ prob_data["solutions"] = req.solutions
317
  res_p = db.insert_problem(prob_data, client)
318
  if res_p and res_p.data:
319
  new_id = res_p.data[0]["id"]
routers/github_sync.py CHANGED
@@ -128,7 +128,11 @@ def commit_file_to_github(
128
 
129
  if status in (200, 201):
130
  html_url = res.get("content", {}).get("html_url", "")
131
- return True, "Committed successfully", {"html_url": html_url, "sha": res.get("commit", {}).get("sha", "")}
 
 
 
 
132
 
133
  err_msg = res.get("message", f"GitHub returned HTTP {status}")
134
  return False, err_msg, res
@@ -179,7 +183,11 @@ def format_problem_readme(
179
  """Formats markdown README for the individual problem folder."""
180
  num_str = f"#{problem_number} " if problem_number and problem_number > 0 else ""
181
  diff = difficulty or "Medium"
182
- badge_color = "brightgreen" if diff.lower() == "easy" else ("orange" if diff.lower() == "medium" else "red")
 
 
 
 
183
 
184
  lines = [
185
  f"# {num_str}{problem_name}",
@@ -215,15 +223,17 @@ def format_problem_readme(
215
  lines.append(f"- `{c}`")
216
  lines.append("")
217
 
218
- lines.extend([
219
- "## Complexity Analysis",
220
- "",
221
- f"- **Time Complexity:** `{optimal_time or 'O(N)'}`",
222
- f"- **Space Complexity:** `{optimal_space or 'O(1)'}`",
223
- "",
224
- "---",
225
- "*Synced via [AlgoSpaced](https://github.com/iamfebin/algospaced-dsa)*",
226
- ])
 
 
227
  return "\n".join(lines) + "\n"
228
 
229
 
@@ -269,13 +279,17 @@ def generate_root_readme(owner: str, repo: str, problems: list[dict[str, Any]])
269
  slug = slugify_problem(name, num)
270
  link = f"[Code](./solutions/{slug}/solution.py)"
271
 
272
- lines.append(f"| {num_str} | **{name}** | `{diff}` | {pattern} | `{time_c}` | `{space_c}` | {link} |")
 
 
273
 
274
- lines.extend([
275
- "",
276
- "---",
277
- "Updated automatically by [AlgoSpaced Spaced Repetition Platform](https://github.com/iamfebin/algospaced-dsa).",
278
- ])
 
 
279
  return "\n".join(lines) + "\n"
280
 
281
 
@@ -518,11 +532,13 @@ def github_oauth_callback(
518
  )
519
 
520
  token_url = "https://github.com/login/oauth/access_token"
521
- payload = json.dumps({
522
- "client_id": client_id,
523
- "client_secret": client_secret,
524
- "code": code,
525
- }).encode("utf-8")
 
 
526
  req = urllib.request.Request(
527
  token_url,
528
  data=payload,
@@ -619,7 +635,9 @@ def init_github_repo(req: InitRepoRequest):
619
  "private": req.private,
620
  "auto_init": True,
621
  }
622
- status, create_res = github_api_request("/user/repos", token, method="POST", data=create_payload)
 
 
623
  if status in (200, 201):
624
  return {
625
  "success": True,
@@ -701,7 +719,9 @@ def push_solution(req: PushSolutionRequest):
701
 
702
  return {
703
  "success": True,
704
- "html_url": code_res.get("html_url", f"https://github.com/{owner}/{repo}/blob/{branch}/{code_path}"),
 
 
705
  "slug": slug,
706
  "code_path": code_path,
707
  "message": f"Successfully pushed {req.problem_name} to {owner}/{repo}!",
@@ -737,10 +757,14 @@ def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_se
737
 
738
  # Retrieve all user problems from DB
739
  all_problems = db.get_all_problems(client)
740
- user_problems = [p for p in all_problems if p.get("user_id") == user_id or user_id == "sandbox-user-id"]
 
 
741
 
742
  # Filter problems that have code
743
- solved_problems = [p for p in user_problems if p.get("reference_code") and p["reference_code"].strip()]
 
 
744
 
745
  if not solved_problems:
746
  return {
@@ -791,7 +815,15 @@ def sync_all_solutions(req: SyncAllRequest, client: Client = Depends(get_auth_se
791
  prob.get("constraints"),
792
  )
793
  readme_path = f"solutions/{slug}/README.md"
794
- commit_file_to_github(owner, repo, readme_path, readme_content, f"docs: #{num or ''} {name} [AlgoSpaced]", branch, token)
 
 
 
 
 
 
 
 
795
  else:
796
  failed_count += 1
797
 
 
128
 
129
  if status in (200, 201):
130
  html_url = res.get("content", {}).get("html_url", "")
131
+ return (
132
+ True,
133
+ "Committed successfully",
134
+ {"html_url": html_url, "sha": res.get("commit", {}).get("sha", "")},
135
+ )
136
 
137
  err_msg = res.get("message", f"GitHub returned HTTP {status}")
138
  return False, err_msg, res
 
183
  """Formats markdown README for the individual problem folder."""
184
  num_str = f"#{problem_number} " if problem_number and problem_number > 0 else ""
185
  diff = difficulty or "Medium"
186
+ badge_color = (
187
+ "brightgreen"
188
+ if diff.lower() == "easy"
189
+ else ("orange" if diff.lower() == "medium" else "red")
190
+ )
191
 
192
  lines = [
193
  f"# {num_str}{problem_name}",
 
223
  lines.append(f"- `{c}`")
224
  lines.append("")
225
 
226
+ lines.extend(
227
+ [
228
+ "## Complexity Analysis",
229
+ "",
230
+ f"- **Time Complexity:** `{optimal_time or 'O(N)'}`",
231
+ f"- **Space Complexity:** `{optimal_space or 'O(1)'}`",
232
+ "",
233
+ "---",
234
+ "*Synced via [AlgoSpaced](https://github.com/iamfebin/algospaced-dsa)*",
235
+ ]
236
+ )
237
  return "\n".join(lines) + "\n"
238
 
239
 
 
279
  slug = slugify_problem(name, num)
280
  link = f"[Code](./solutions/{slug}/solution.py)"
281
 
282
+ lines.append(
283
+ f"| {num_str} | **{name}** | `{diff}` | {pattern} | `{time_c}` | `{space_c}` | {link} |"
284
+ )
285
 
286
+ lines.extend(
287
+ [
288
+ "",
289
+ "---",
290
+ "Updated automatically by [AlgoSpaced Spaced Repetition Platform](https://github.com/iamfebin/algospaced-dsa).",
291
+ ]
292
+ )
293
  return "\n".join(lines) + "\n"
294
 
295
 
 
532
  )
533
 
534
  token_url = "https://github.com/login/oauth/access_token"
535
+ payload = json.dumps(
536
+ {
537
+ "client_id": client_id,
538
+ "client_secret": client_secret,
539
+ "code": code,
540
+ }
541
+ ).encode("utf-8")
542
  req = urllib.request.Request(
543
  token_url,
544
  data=payload,
 
635
  "private": req.private,
636
  "auto_init": True,
637
  }
638
+ status, create_res = github_api_request(
639
+ "/user/repos", token, method="POST", data=create_payload
640
+ )
641
  if status in (200, 201):
642
  return {
643
  "success": True,
 
719
 
720
  return {
721
  "success": True,
722
+ "html_url": code_res.get(
723
+ "html_url", f"https://github.com/{owner}/{repo}/blob/{branch}/{code_path}"
724
+ ),
725
  "slug": slug,
726
  "code_path": code_path,
727
  "message": f"Successfully pushed {req.problem_name} to {owner}/{repo}!",
 
757
 
758
  # Retrieve all user problems from DB
759
  all_problems = db.get_all_problems(client)
760
+ user_problems = [
761
+ p for p in all_problems if p.get("user_id") == user_id or user_id == "sandbox-user-id"
762
+ ]
763
 
764
  # Filter problems that have code
765
+ solved_problems = [
766
+ p for p in user_problems if p.get("reference_code") and p["reference_code"].strip()
767
+ ]
768
 
769
  if not solved_problems:
770
  return {
 
815
  prob.get("constraints"),
816
  )
817
  readme_path = f"solutions/{slug}/README.md"
818
+ commit_file_to_github(
819
+ owner,
820
+ repo,
821
+ readme_path,
822
+ readme_content,
823
+ f"docs: #{num or ''} {name} [AlgoSpaced]",
824
+ branch,
825
+ token,
826
+ )
827
  else:
828
  failed_count += 1
829
 
routers/reviews.py CHANGED
@@ -1,5 +1,8 @@
 
1
  import re
 
2
  from datetime import UTC, datetime
 
3
 
4
  from fastapi import APIRouter, Depends, Header, HTTPException, Request
5
  from pydantic import BaseModel
@@ -20,6 +23,38 @@ from core.problem_utils import (
20
  router = APIRouter(tags=["reviews"])
21
 
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  @router.get("/api/streak")
24
  def get_streak(client: Client = Depends(get_auth_session)):
25
  streak_data = db.get_active_streak(client)
@@ -35,8 +70,11 @@ def get_due_reviews(client: Client = Depends(get_auth_session)):
35
  for i, review in enumerate(reviews):
36
  if "problems" in review and review["problems"]:
37
  prob = review["problems"]
38
- prob["starter_code"] = extract_starter_code(prob.get("reference_code", ""))
 
 
39
  enrich_problem_examples_and_constraints(prob, client, check_remote_cache=(i < 3))
 
40
  return reviews
41
 
42
 
@@ -54,14 +92,19 @@ def get_problems_by_number(problem_number: int, client: Client = Depends(get_aut
54
  if db.get_virtual_number(p["id"]) == problem_number:
55
  matched.append(p)
56
  for prob in matched:
57
- prob["starter_code"] = extract_starter_code(prob.get("reference_code", ""))
 
 
58
  enrich_problem_examples_and_constraints(prob, client)
59
  return matched
60
 
61
  problems = db.get_problems_by_number(problem_number, client)
62
  for prob in problems:
63
- prob["starter_code"] = extract_starter_code(prob.get("reference_code", ""))
 
 
64
  enrich_problem_examples_and_constraints(prob, client)
 
65
  return problems
66
 
67
 
@@ -71,8 +114,11 @@ def get_reviews_by_problem_id(problem_id: str, client: Client = Depends(get_auth
71
  for review in reviews:
72
  if "problems" in review and review["problems"]:
73
  prob = review["problems"]
74
- prob["starter_code"] = extract_starter_code(prob.get("reference_code", ""))
 
 
75
  enrich_problem_examples_and_constraints(prob, client)
 
76
  return reviews
77
 
78
 
@@ -323,6 +369,13 @@ class SaveReferenceRequest(BaseModel):
323
  examples: list[dict] | None = []
324
  constraints: list[str] | None = []
325
  code: str
 
 
 
 
 
 
 
326
 
327
 
328
  @router.post("/api/reviews/save-reference")
@@ -391,6 +444,56 @@ def save_reference_solution(req: SaveReferenceRequest, client: Client = Depends(
391
  if req.constraints and not existing_problem.get("constraints"):
392
  update_data["constraints"] = req.constraints
393
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
394
  db.update_problem(target_id, update_data, client)
395
  final_prob_id = target_id
396
  else:
@@ -408,6 +511,21 @@ def save_reference_solution(req: SaveReferenceRequest, client: Client = Depends(
408
  "examples": req.examples or [],
409
  "constraints": req.constraints or [],
410
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  res_p = db.insert_problem(prob_data, client)
412
  if res_p and res_p.data:
413
  final_prob_id = res_p.data[0]["id"]
 
1
+ import json
2
  import re
3
+ import uuid
4
  from datetime import UTC, datetime
5
+ from typing import Any
6
 
7
  from fastapi import APIRouter, Depends, Header, HTTPException, Request
8
  from pydantic import BaseModel
 
23
  router = APIRouter(tags=["reviews"])
24
 
25
 
26
+ def ensure_problem_solutions(prob: dict[str, Any]) -> None:
27
+ if not prob:
28
+ return
29
+ sols = prob.get("solutions")
30
+ if isinstance(sols, str):
31
+ try:
32
+ sols = json.loads(sols)
33
+ prob["solutions"] = sols
34
+ except Exception:
35
+ sols = None
36
+ if not sols or not isinstance(sols, list) or len(sols) == 0:
37
+ ref_code = prob.get("reference_code") or ""
38
+ pattern = prob.get("pattern") or "General Algorithm"
39
+ time_c = prob.get("optimal_time") or "O(N)"
40
+ space_c = prob.get("optimal_space") or "O(1)"
41
+ if ref_code or (pattern and pattern != "General Algorithm"):
42
+ prob["solutions"] = [
43
+ {
44
+ "id": "sol-default",
45
+ "name": "Optimal Solution",
46
+ "pattern": pattern,
47
+ "time_complexity": time_c,
48
+ "space_complexity": space_c,
49
+ "code": ref_code,
50
+ "explanation": prob.get("how_to_solve") or "",
51
+ "is_optimal": True,
52
+ }
53
+ ]
54
+ else:
55
+ prob["solutions"] = []
56
+
57
+
58
  @router.get("/api/streak")
59
  def get_streak(client: Client = Depends(get_auth_session)):
60
  streak_data = db.get_active_streak(client)
 
70
  for i, review in enumerate(reviews):
71
  if "problems" in review and review["problems"]:
72
  prob = review["problems"]
73
+ prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
74
+ prob.get("reference_code", "")
75
+ )
76
  enrich_problem_examples_and_constraints(prob, client, check_remote_cache=(i < 3))
77
+ ensure_problem_solutions(prob)
78
  return reviews
79
 
80
 
 
92
  if db.get_virtual_number(p["id"]) == problem_number:
93
  matched.append(p)
94
  for prob in matched:
95
+ prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
96
+ prob.get("reference_code", "")
97
+ )
98
  enrich_problem_examples_and_constraints(prob, client)
99
  return matched
100
 
101
  problems = db.get_problems_by_number(problem_number, client)
102
  for prob in problems:
103
+ prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
104
+ prob.get("reference_code", "")
105
+ )
106
  enrich_problem_examples_and_constraints(prob, client)
107
+ ensure_problem_solutions(prob)
108
  return problems
109
 
110
 
 
114
  for review in reviews:
115
  if "problems" in review and review["problems"]:
116
  prob = review["problems"]
117
+ prob["starter_code"] = prob.get("starter_code") or extract_starter_code(
118
+ prob.get("reference_code", "")
119
+ )
120
  enrich_problem_examples_and_constraints(prob, client)
121
+ ensure_problem_solutions(prob)
122
  return reviews
123
 
124
 
 
369
  examples: list[dict] | None = []
370
  constraints: list[str] | None = []
371
  code: str
372
+ solution_id: str | None = None
373
+ solution_name: str | None = None
374
+ time_complexity: str | None = None
375
+ space_complexity: str | None = None
376
+ explanation: str | None = None
377
+ is_optimal: bool | None = None
378
+ solutions: list[dict] | None = None
379
 
380
 
381
  @router.post("/api/reviews/save-reference")
 
444
  if req.constraints and not existing_problem.get("constraints"):
445
  update_data["constraints"] = req.constraints
446
 
447
+ # Multi-solution handling
448
+ if req.solutions is not None:
449
+ update_data["solutions"] = req.solutions
450
+ elif req.solution_name or req.solution_id:
451
+ curr_sols = existing_problem.get("solutions") or []
452
+ if isinstance(curr_sols, str):
453
+ try:
454
+ curr_sols = json.loads(curr_sols)
455
+ except Exception:
456
+ curr_sols = []
457
+ matched = False
458
+ for s in curr_sols:
459
+ if (req.solution_id and s.get("id") == req.solution_id) or (
460
+ req.solution_name and s.get("name") == req.solution_name
461
+ ):
462
+ s["code"] = req.code
463
+ if req.pattern:
464
+ s["pattern"] = req.pattern
465
+ if req.time_complexity:
466
+ s["time_complexity"] = req.time_complexity
467
+ if req.space_complexity:
468
+ s["space_complexity"] = req.space_complexity
469
+ if req.explanation:
470
+ s["explanation"] = req.explanation
471
+ if req.is_optimal is not None:
472
+ s["is_optimal"] = req.is_optimal
473
+ matched = True
474
+ break
475
+ if not matched:
476
+ new_sol = {
477
+ "id": req.solution_id or f"sol-{uuid.uuid4().hex[:8]}",
478
+ "name": req.solution_name or "Personal Solution",
479
+ "pattern": req.pattern
480
+ or existing_problem.get("pattern")
481
+ or "General Algorithm",
482
+ "time_complexity": req.time_complexity
483
+ or existing_problem.get("optimal_time")
484
+ or "O(N)",
485
+ "space_complexity": req.space_complexity
486
+ or existing_problem.get("optimal_space")
487
+ or "O(1)",
488
+ "code": req.code,
489
+ "explanation": req.explanation or "",
490
+ "is_optimal": req.is_optimal
491
+ if req.is_optimal is not None
492
+ else (len(curr_sols) == 0),
493
+ }
494
+ curr_sols.append(new_sol)
495
+ update_data["solutions"] = curr_sols
496
+
497
  db.update_problem(target_id, update_data, client)
498
  final_prob_id = target_id
499
  else:
 
511
  "examples": req.examples or [],
512
  "constraints": req.constraints or [],
513
  }
514
+ if req.solutions is not None:
515
+ prob_data["solutions"] = req.solutions
516
+ elif req.solution_name:
517
+ prob_data["solutions"] = [
518
+ {
519
+ "id": req.solution_id or f"sol-{uuid.uuid4().hex[:8]}",
520
+ "name": req.solution_name,
521
+ "pattern": req.pattern or "General Algorithm",
522
+ "time_complexity": req.time_complexity or req.optimal_time or "O(N)",
523
+ "space_complexity": req.space_complexity or req.optimal_space or "O(1)",
524
+ "code": req.code,
525
+ "explanation": req.explanation or "",
526
+ "is_optimal": True,
527
+ }
528
+ ]
529
  res_p = db.insert_problem(prob_data, client)
530
  if res_p and res_p.data:
531
  final_prob_id = res_p.data[0]["id"]
sandbox.py CHANGED
@@ -406,8 +406,7 @@ def run_python_sandbox(
406
  test_cases_json = json.dumps(test_cases)
407
  starter_code_str = starter_code or ""
408
  full_script = (
409
- EXECUTION_TEMPLATE
410
- .replace("__USER_CODE__", user_code)
411
  .replace("__TEST_CASES_JSON__", json.dumps(test_cases_json))
412
  .replace("__STARTER_CODE_JSON__", json.dumps(starter_code_str))
413
  )
 
406
  test_cases_json = json.dumps(test_cases)
407
  starter_code_str = starter_code or ""
408
  full_script = (
409
+ EXECUTION_TEMPLATE.replace("__USER_CODE__", user_code)
 
410
  .replace("__TEST_CASES_JSON__", json.dumps(test_cases_json))
411
  .replace("__STARTER_CODE_JSON__", json.dumps(starter_code_str))
412
  )
sandbox_db.py CHANGED
@@ -31,14 +31,20 @@ def init_db():
31
  optimal_space TEXT DEFAULT 'O(N)',
32
  description TEXT,
33
  reference_code TEXT,
 
34
  examples TEXT,
35
  constraints TEXT,
 
36
  created_at TEXT DEFAULT CURRENT_TIMESTAMP,
37
  UNIQUE(user_id, name)
38
  );
39
  """)
40
 
41
  # Safe migrations for existing SQLite databases
 
 
 
 
42
  try:
43
  cursor.execute("ALTER TABLE problems ADD COLUMN examples TEXT;")
44
  except Exception:
@@ -47,6 +53,10 @@ def init_db():
47
  cursor.execute("ALTER TABLE problems ADD COLUMN constraints TEXT;")
48
  except Exception:
49
  pass
 
 
 
 
50
 
51
  # 2. User Reviews table
52
  cursor.execute("""
@@ -439,7 +449,7 @@ class QueryBuilder:
439
 
440
  if self.table_name == "problems":
441
  for row in data:
442
- for json_col in ("examples", "constraints"):
443
  if json_col in row and isinstance(row[json_col], str):
444
  try:
445
  row[json_col] = json.loads(row[json_col])
@@ -473,6 +483,11 @@ class QueryBuilder:
473
  if isinstance(v, (list, dict)):
474
  row_copy[k] = json.dumps(v)
475
 
 
 
 
 
 
476
  columns = list(row_copy.keys())
477
  placeholders = ", ".join(["?"] * len(columns))
478
  query = f"INSERT INTO {self.table_name} ({', '.join(columns)}) VALUES ({placeholders})"
@@ -487,6 +502,12 @@ class QueryBuilder:
487
  for k, v in update_copy.items():
488
  if isinstance(v, (list, dict)):
489
  update_copy[k] = json.dumps(v)
 
 
 
 
 
 
490
  columns = list(update_copy.keys())
491
  set_clause = ", ".join([f"{col} = ?" for col in columns])
492
  params = list(update_copy.values())
 
31
  optimal_space TEXT DEFAULT 'O(N)',
32
  description TEXT,
33
  reference_code TEXT,
34
+ how_to_solve TEXT,
35
  examples TEXT,
36
  constraints TEXT,
37
+ solutions TEXT,
38
  created_at TEXT DEFAULT CURRENT_TIMESTAMP,
39
  UNIQUE(user_id, name)
40
  );
41
  """)
42
 
43
  # Safe migrations for existing SQLite databases
44
+ try:
45
+ cursor.execute("ALTER TABLE problems ADD COLUMN how_to_solve TEXT;")
46
+ except Exception:
47
+ pass
48
  try:
49
  cursor.execute("ALTER TABLE problems ADD COLUMN examples TEXT;")
50
  except Exception:
 
53
  cursor.execute("ALTER TABLE problems ADD COLUMN constraints TEXT;")
54
  except Exception:
55
  pass
56
+ try:
57
+ cursor.execute("ALTER TABLE problems ADD COLUMN solutions TEXT;")
58
+ except Exception:
59
+ pass
60
 
61
  # 2. User Reviews table
62
  cursor.execute("""
 
449
 
450
  if self.table_name == "problems":
451
  for row in data:
452
+ for json_col in ("examples", "constraints", "solutions"):
453
  if json_col in row and isinstance(row[json_col], str):
454
  try:
455
  row[json_col] = json.loads(row[json_col])
 
483
  if isinstance(v, (list, dict)):
484
  row_copy[k] = json.dumps(v)
485
 
486
+ cursor.execute(f"PRAGMA table_info({self.table_name});")
487
+ existing_cols = {col_info[1] for col_info in cursor.fetchall()}
488
+ if existing_cols:
489
+ row_copy = {k: v for k, v in row_copy.items() if k in existing_cols}
490
+
491
  columns = list(row_copy.keys())
492
  placeholders = ", ".join(["?"] * len(columns))
493
  query = f"INSERT INTO {self.table_name} ({', '.join(columns)}) VALUES ({placeholders})"
 
502
  for k, v in update_copy.items():
503
  if isinstance(v, (list, dict)):
504
  update_copy[k] = json.dumps(v)
505
+
506
+ cursor.execute(f"PRAGMA table_info({self.table_name});")
507
+ existing_cols = {col_info[1] for col_info in cursor.fetchall()}
508
+ if existing_cols:
509
+ update_copy = {k: v for k, v in update_copy.items() if k in existing_cols}
510
+
511
  columns = list(update_copy.keys())
512
  set_clause = ", ".join([f"{col} = ?" for col in columns])
513
  params = list(update_copy.values())
tests/unit/test_gdrive_sync.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from gdrive_sync import parse_problem_body
2
+
3
+
4
+ class TestGdriveSyncParsing:
5
+ def test_single_method_with_generic_header(self):
6
+ """When a doc has 'Method 1:' without a specific name, clean name to problem_name."""
7
+ body = """
8
+ Easy
9
+ Method 1:
10
+ Time Complexity: O(N)
11
+ Space Complexity: O(N)
12
+ def solve(): pass
13
+ """
14
+ methods = parse_problem_body("Two Sum", body)
15
+ assert len(methods) == 1
16
+ assert methods[0]["name"] == "Two Sum"
17
+ assert methods[0]["pattern"] == "General Algorithm"
18
+ assert methods[0]["difficulty"] == "Easy"
19
+ assert methods[0]["optimal_time"] == "O(N)"
20
+ assert methods[0]["optimal_space"] == "O(N)"
21
+
22
+ def test_single_method_with_named_approach(self):
23
+ """When a doc has 'Method 1 (Hash Map (One-Pass)):', capture the approach."""
24
+ body = """
25
+ Easy
26
+ Method 1 (Hash Map (One-Pass)):
27
+ Time Complexity: O(N)
28
+ Space Complexity: O(N)
29
+ def solve(): pass
30
+ """
31
+ methods = parse_problem_body("Two Sum", body)
32
+ assert len(methods) == 1
33
+ assert methods[0]["name"] == "Two Sum - Method 1 (Hash Map (One-Pass))"
34
+ assert methods[0]["pattern"] == "Hash Map (One-Pass)"
35
+
36
+ def test_multiple_methods_distinction(self):
37
+ """When multiple methods are present, ensure distinct method indices without echo."""
38
+ body = """
39
+ Medium
40
+ Method 1:
41
+ Time Complexity: O(N^2)
42
+ Space Complexity: O(1)
43
+ def solve_brute(): pass
44
+
45
+ Method 2 (Two Pointers):
46
+ Time Complexity: O(N)
47
+ Space Complexity: O(1)
48
+ def solve_two_pointers(): pass
49
+ """
50
+ methods = parse_problem_body("Two Sum II", body)
51
+ assert len(methods) == 2
52
+ assert methods[0]["name"] == "Two Sum II - Method 1"
53
+ assert methods[0]["pattern"] == "General Algorithm"
54
+ assert methods[1]["name"] == "Two Sum II - Method 2 (Two Pointers)"
55
+ assert methods[1]["pattern"] == "Two Pointers"
56
+
57
+ def test_no_method_headers_fallback(self):
58
+ """When no 'Method X' headers exist, problem should have clean name."""
59
+ body = """
60
+ Easy
61
+ Pattern: Arrays & Hashing
62
+ Time Complexity: O(N)
63
+ Space Complexity: O(N)
64
+ def solve(): pass
65
+ """
66
+ methods = parse_problem_body("Contains Duplicate", body)
67
+ assert len(methods) == 1
68
+ assert methods[0]["name"] == "Contains Duplicate"
69
+ assert methods[0]["pattern"] == "Arrays & Hashing"
tests/unit/test_github_sync.py CHANGED
@@ -31,11 +31,11 @@ def test_format_solution_file():
31
  optimal_space="O(N)",
32
  code=code,
33
  )
34
- assert 'Problem: #1 Two Sum' in res
35
- assert 'Difficulty: Easy' in res
36
- assert 'Pattern: Arrays & Hashing' in res
37
- assert 'Time Complexity: O(N)' in res
38
- assert 'Space Complexity: O(N)' in res
39
  assert code in res
40
 
41
 
@@ -120,7 +120,9 @@ def test_push_solution_endpoint(mock_api, mock_commit):
120
  mock_commit.return_value = (
121
  True,
122
  "Committed successfully",
123
- {"html_url": "https://github.com/octocat/algospaced-solutions/blob/main/solutions/0001-two-sum/solution.py"},
 
 
124
  )
125
 
126
  payload = {
@@ -184,6 +186,7 @@ def test_oauth_callback_endpoint_success(mock_urlopen, monkeypatch):
184
 
185
  # Mock token exchange response
186
  import io
 
187
  mock_resp = io.BytesIO(b'{"access_token": "gho_testtoken999", "scope": "repo"}')
188
  mock_resp.status = 200
189
  mock_urlopen.return_value.__enter__.return_value = mock_resp
@@ -195,8 +198,9 @@ def test_oauth_callback_endpoint_success(mock_urlopen, monkeypatch):
195
 
196
 
197
  def test_oauth_callback_endpoint_error():
198
- res = client.get("/api/github/oauth/callback?error=access_denied&error_description=User+cancelled")
 
 
199
  assert res.status_code == 200
200
  assert "GITHUB_OAUTH_ERROR" in res.text
201
  assert "User cancelled" in res.text
202
-
 
31
  optimal_space="O(N)",
32
  code=code,
33
  )
34
+ assert "Problem: #1 Two Sum" in res
35
+ assert "Difficulty: Easy" in res
36
+ assert "Pattern: Arrays & Hashing" in res
37
+ assert "Time Complexity: O(N)" in res
38
+ assert "Space Complexity: O(N)" in res
39
  assert code in res
40
 
41
 
 
120
  mock_commit.return_value = (
121
  True,
122
  "Committed successfully",
123
+ {
124
+ "html_url": "https://github.com/octocat/algospaced-solutions/blob/main/solutions/0001-two-sum/solution.py"
125
+ },
126
  )
127
 
128
  payload = {
 
186
 
187
  # Mock token exchange response
188
  import io
189
+
190
  mock_resp = io.BytesIO(b'{"access_token": "gho_testtoken999", "scope": "repo"}')
191
  mock_resp.status = 200
192
  mock_urlopen.return_value.__enter__.return_value = mock_resp
 
198
 
199
 
200
  def test_oauth_callback_endpoint_error():
201
+ res = client.get(
202
+ "/api/github/oauth/callback?error=access_denied&error_description=User+cancelled"
203
+ )
204
  assert res.status_code == 200
205
  assert "GITHUB_OAUTH_ERROR" in res.text
206
  assert "User cancelled" in res.text
 
tests/unit/test_problem_utils.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from core.problem_utils import extract_starter_code
2
+
3
+
4
+ class TestExtractStarterCode:
5
+ def test_extract_starter_code_single_method(self):
6
+ ref = """class Solution:
7
+ def containsDuplicate(self, nums: list[int]) -> bool:
8
+ seen = set()
9
+ for n in nums:
10
+ if n in seen:
11
+ return True
12
+ seen.add(n)
13
+ return False
14
+ """
15
+ starter = extract_starter_code(ref)
16
+ assert "class Solution:" in starter
17
+ assert "def containsDuplicate(self, nums: list[int]) -> bool:" in starter
18
+ assert "pass" in starter
19
+ assert "seen" not in starter
20
+ assert "return True" not in starter
21
+
22
+ def test_extract_starter_code_multi_method(self):
23
+ ref = """class MinStack:
24
+ def __init__(self):
25
+ self.stack = []
26
+ self.min_stack = []
27
+
28
+ def push(self, val: int) -> None:
29
+ self.stack.append(val)
30
+
31
+ def pop(self) -> None:
32
+ self.stack.pop()
33
+
34
+ def top(self) -> int:
35
+ return self.stack[-1]
36
+
37
+ def getMin(self) -> int:
38
+ return self.min_stack[-1]
39
+ """
40
+ starter = extract_starter_code(ref)
41
+ assert "class MinStack:" in starter
42
+ assert "def __init__(self):" in starter
43
+ assert "def push(self, val: int) -> None:" in starter
44
+ assert "def pop(self, val" not in starter
45
+ assert "def pop(self) -> None:" in starter
46
+ assert "def top(self) -> int:" in starter
47
+ assert "def getMin(self) -> int:" in starter
48
+ assert "self.stack.append" not in starter
49
+ assert "self.min_stack" not in starter
50
+
51
+ def test_extract_starter_code_definition_comment(self):
52
+ ref = """# Definition for singly-linked list.
53
+ # class ListNode:
54
+ # def __init__(self, val=0, next=None):
55
+ # self.val = val
56
+ class Solution:
57
+ def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
58
+ prev = None
59
+ return prev
60
+ """
61
+ starter = extract_starter_code(ref)
62
+ assert "# Definition for singly-linked list." in starter
63
+ assert "# class ListNode:" in starter
64
+ assert "def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:" in starter
65
+ assert "pass" in starter
66
+ assert "prev = None" not in starter
67
+
68
+ def test_extract_starter_code_standalone_function(self):
69
+ ref = """def two_sum(nums, target):
70
+ seen = {}
71
+ return []
72
+ """
73
+ starter = extract_starter_code(ref)
74
+ assert "def two_sum(nums, target):" in starter
75
+ assert "pass" in starter
76
+ assert "seen = {}" not in starter
77
+
78
+ def test_extract_starter_code_no_leak_when_no_defs(self):
79
+ ref = """# Solution using dynamic programming
80
+ total = sum([1, 2, 3])
81
+ print(total)
82
+ """
83
+ starter = extract_starter_code(ref)
84
+ assert "def solve():" in starter
85
+ assert "pass" in starter
86
+ assert "print(total)" not in starter
87
+ assert "total = sum" not in starter
88
+
89
+ def test_extract_starter_code_empty(self):
90
+ assert extract_starter_code("") == ""
91
+ assert extract_starter_code(" ") == ""
tests/unit/test_reviews_lookup.py CHANGED
@@ -23,5 +23,7 @@ class TestReviewsLookup:
23
 
24
  def test_get_reviews_nonexistent_returns_empty(self):
25
  """Test that an unknown problem ID returns an empty list without error."""
26
- reviews = db.get_reviews_by_problem_id("nonexistent-id", client_or_user_id="sandbox-user-id")
 
 
27
  assert reviews == []
 
23
 
24
  def test_get_reviews_nonexistent_returns_empty(self):
25
  """Test that an unknown problem ID returns an empty list without error."""
26
+ reviews = db.get_reviews_by_problem_id(
27
+ "nonexistent-id", client_or_user_id="sandbox-user-id"
28
+ )
29
  assert reviews == []