function Q(e){var t,T,k,H,A;return`
# ${e.title}

**Difficulty:** ${e.difficulty}  
**Pattern:** ${e.pattern??"Uncategorized"}  
**Language:** ${e.language}  
**LeetCode:** ${e.url}

---

## Intuition
${((t=e.intuition)==null?void 0:t.trim())||"_Write your first thoughts and observations here._"}

---

## Approach
${((T=e.approach)==null?void 0:T.trim())||"_Explain the algorithm step by step._"}

---

## Example Walkthrough
${((k=e.walkthrough)==null?void 0:k.trim())||"_Walk through a small example to show how the logic works._"}

---

## Time Complexity
${((H=e.timeComplexity)==null?void 0:H.trim())||"_O(?)_"}

---

## Space Complexity
${((A=e.spaceComplexity)==null?void 0:A.trim())||"_O(?)_"}

---

## Code

\`\`\`${e.language}
${e.code}
\`\`\`

---
<p align="right"><sub>LeetSync Watermark | Synced from browser extension</sub></p>
`.trim()}const X=["Arrays & Hashing","Two Pointers","Sliding Window","Stack","Binary Search","Linked List","Trees","Heap / Priority Queue","Backtracking","Tries","Graphs","Advanced Graphs","1-D Dynamic Programming","2-D Dynamic Programming","Greedy","Intervals","Math & Geometry","Bit Manipulation"],m=document.getElementById("setupView"),h=document.getElementById("mainView"),D=document.getElementById("setupStepLabel"),U=document.getElementById("setupTitle"),I=document.getElementById("setupHelp"),g=document.getElementById("setupInput"),x=document.getElementById("setupBackBtn"),p=document.getElementById("setupNextBtn"),w=document.getElementById("setupStatus"),f=document.getElementById("profileView"),M=document.getElementById("profileAvatar"),W=document.getElementById("profileName"),N=document.getElementById("profileRepo"),R=document.getElementById("profileEditBtn"),S=document.getElementById("profileLogoutBtn"),O=document.getElementById("profileFinishBtn"),P=document.getElementById("openSettingsBtn"),_=document.getElementById("extractBtn"),v=document.getElementById("saveBtn"),n=document.getElementById("status"),s=document.getElementById("difficulty"),d=document.getElementById("patternSelect"),q=document.getElementById("codePreview"),r=document.getElementById("intuition"),l=document.getElementById("approach"),u=document.getElementById("walkthrough"),c=document.getElementById("timeComplexity"),a=document.getElementById("spaceComplexity"),C=[{key:"githubToken",title:"Connect GitHub",help:"Enter your GitHub Personal Access Token.",placeholder:"ghp_...",inputType:"password"},{key:"githubOwner",title:"GitHub Username",help:"Enter the GitHub username that owns the repository.",placeholder:"your-username",inputType:"text"},{key:"githubRepo",title:"Repository / Folder",help:"Enter the repository name where LeetSync should save files.",placeholder:"leetcode",inputType:"text"}];let y=0,o={},i=null,E=null;v&&(v.disabled=!0);function $(e){return typeof e=="string"&&e.trim().length>0}function z(e){if(!e||typeof e!="object")return!1;const t=e;return $(t.githubToken)&&$(t.githubOwner)&&$(t.githubRepo)}async function F(){const e=await chrome.storage.local.get(["githubToken","githubOwner","githubRepo"]);return z(e)?{githubToken:e.githubToken.trim(),githubOwner:e.githubOwner.trim(),githubRepo:e.githubRepo.trim()}:null}function J(){f==null||f.classList.add("hidden"),h==null||h.classList.add("hidden"),m==null||m.classList.remove("hidden")}function j(){f==null||f.classList.add("hidden"),m==null||m.classList.add("hidden"),h==null||h.classList.remove("hidden")}function K(){h==null||h.classList.add("hidden"),m==null||m.classList.add("hidden"),f==null||f.classList.remove("hidden")}async function Y(){var t;if(!i||!M||!W||!N)return;const e=i.githubOwner;M.textContent=((t=e[0])==null?void 0:t.toUpperCase())||"?",W.textContent=e,N.textContent=`Repository: ${i.githubRepo}`}function B(){Y(),K()}function G(){const e=C[y];e&&(D&&(D.textContent=`Step ${y+1} of ${C.length}`),U&&(U.textContent=e.title),I&&(I.textContent=e.help),g&&(g.type=e.inputType,g.placeholder=e.placeholder,g.value=o[e.key]??"",g.focus(),g.select()),x&&(x.disabled=!1),p&&(p.textContent=y===C.length-1?"Finish":"Next"),w&&(w.textContent=""))}function L(e=!1){e&&(y=0),o={githubToken:(i==null?void 0:i.githubToken)??o.githubToken??"",githubOwner:(i==null?void 0:i.githubOwner)??o.githubOwner??"",githubRepo:(i==null?void 0:i.githubRepo)??o.githubRepo??""},J(),G()}chrome.storage.local.get(["intuition","approach","walkthrough","timeComplexity","spaceComplexity","difficulty","pattern"],e=>{r&&typeof e.intuition=="string"&&(r.value=e.intuition),l&&typeof e.approach=="string"&&(l.value=e.approach),u&&typeof e.walkthrough=="string"&&(u.value=e.walkthrough),c&&typeof e.timeComplexity=="string"&&(c.value=e.timeComplexity),a&&typeof e.spaceComplexity=="string"&&(a.value=e.spaceComplexity),s&&typeof e.difficulty=="string"&&(s.value=e.difficulty),d&&typeof e.pattern=="string"&&(d.value=e.pattern)});function b(){chrome.storage.local.set({intuition:(r==null?void 0:r.value)??"",approach:(l==null?void 0:l.value)??"",walkthrough:(u==null?void 0:u.value)??"",timeComplexity:(c==null?void 0:c.value)??"",spaceComplexity:(a==null?void 0:a.value)??"",difficulty:(s==null?void 0:s.value)??"Unknown",pattern:(d==null?void 0:d.value)??"Uncategorized"})}r==null||r.addEventListener("input",b);l==null||l.addEventListener("input",b);u==null||u.addEventListener("input",b);c==null||c.addEventListener("input",b);a==null||a.addEventListener("input",b);s==null||s.addEventListener("change",b);d==null||d.addEventListener("change",b);d&&X.forEach(e=>{const t=document.createElement("option");t.value=e,t.textContent=e,d.appendChild(t)});x==null||x.addEventListener("click",()=>{if(y===0){i?B():j();return}y-=1,G()});g==null||g.addEventListener("keydown",e=>{e.key==="Enter"&&(e.preventDefault(),p==null||p.click())});p==null||p.addEventListener("click",async()=>{const e=C[y];if(!e||!g)return;const t=g.value.trim();if(!t){w&&(w.textContent="This field is required.");return}if(o[e.key]=t,y<C.length-1){y+=1,G();return}if(!z(o)){w&&(w.textContent="Setup is incomplete.");return}await chrome.storage.local.set({githubToken:o.githubToken,githubOwner:o.githubOwner,githubRepo:o.githubRepo,setupDate:Date.now()}),i={githubToken:o.githubToken.trim(),githubOwner:o.githubOwner.trim(),githubRepo:o.githubRepo.trim()},B(),n&&(n.textContent="GitHub settings saved.")});R==null||R.addEventListener("click",()=>{L(!0)});S==null||S.addEventListener("click",async()=>{confirm("Are you sure you want to logout? All GitHub settings will be cleared.")&&(await chrome.storage.local.remove(["githubToken","githubOwner","githubRepo"]),i=null,L(!0),n&&(n.textContent="Logged out."))});O==null||O.addEventListener("click",()=>{j()});P==null||P.addEventListener("click",async()=>{const e=await F();e?(i=e,B()):L(!0)});_==null||_.addEventListener("click",async()=>{n&&(n.textContent="Extracting...");const[e]=await chrome.tabs.query({active:!0,currentWindow:!0});if(!(e!=null&&e.id)){n&&(n.textContent="No active tab");return}chrome.tabs.sendMessage(e.id,{type:"EXTRACT_PROBLEM"},t=>{if(chrome.runtime.lastError||!(t!=null&&t.success)||!(t!=null&&t.data)){n&&(n.textContent="Extraction failed");return}E=t.data,s&&typeof t.data.difficulty=="string"&&(s.value=t.data.difficulty),q&&(q.textContent=t.data.code??""),v&&(v.disabled=!1),n&&(n.textContent="✓ Extracted")})});v==null||v.addEventListener("click",()=>{if(!i){n&&(n.textContent="Complete GitHub setup first"),L(!0);return}if(!E){n&&(n.textContent="Extract first");return}const e=(s==null?void 0:s.value)??"Unknown",t=(d==null?void 0:d.value)??"Uncategorized",T=Q({title:E.title,difficulty:e,pattern:t,language:E.language,url:E.url,code:E.code,intuition:(r==null?void 0:r.value)??"",approach:(l==null?void 0:l.value)??"",walkthrough:(u==null?void 0:u.value)??"",timeComplexity:(c==null?void 0:c.value)??"",spaceComplexity:(a==null?void 0:a.value)??""});n&&(n.textContent="Saving..."),chrome.runtime.sendMessage({type:"SAVE_TO_GITHUB",payload:{title:E.title,difficulty:e,pattern:t,markdown:T,questionId:"0567"}},k=>{if(chrome.runtime.lastError||!(k!=null&&k.success)){n&&(n.textContent="Save failed");return}n&&(n.textContent="✓ Saved successfully"),r&&(r.value=""),l&&(l.value=""),u&&(u.value=""),c&&(c.value=""),a&&(a.value=""),chrome.storage.local.remove(["intuition","approach","walkthrough","timeComplexity","spaceComplexity"])})});(async()=>{i=await F();const e=new URLSearchParams(window.location.search).get("setup")==="1";if(!i||e){L(!0);return}B()})();
