import"./modulepreload-polyfill-B5Qt9EMX.js";import{k as p,B as m}from"./bootstrap-DlNJH-GE.js";const g=await p({surface:"popup"}),h=g.get(m),n=t=>document.getElementById(t),u=n("status"),o=t=>{u&&(u.textContent=t)},i=n("currentUrl");try{const s=(await chrome.tabs?.query?.({active:!0,currentWindow:!0}))?.[0];s&&i&&(i.textContent=s.url??"(no active tab)")}catch{i&&(i.textContent="(headless / no chrome.tabs)")}n("openSidepanel")?.addEventListener("click",async()=>{try{await chrome.runtime.sendMessage({kind:"wkms/open-sidepanel"})}finally{window.close?.()}});n("saveAllGroups")?.addEventListener("click",async()=>{o("capturing…"),await h.publish("wkms.capture.requested",{source:"popup-button",at:new Date().toISOString()});try{const t=await chrome.runtime.sendMessage({kind:"wkms/save-all-groups",payload:d()});o(t?.ok?`saved (+${t.result?.newNodes??0})`:`error: ${t?.error??"unknown"}`)}catch(t){o(`error: ${String(t)}`)}});n("save")?.addEventListener("click",async()=>{const t=d();o(`would save: ${t.userTags.length} tags`)});n("addTag")?.addEventListener("click",()=>{const t=n("newTag");if(!t||!t.value.trim())return;const e=t.value.trim();t.value="",v(e)});n("searchTag")?.addEventListener("input",t=>{const e=t.target.value.toLowerCase(),s=n("searchTagMatches");if(s&&(s.innerHTML="",!!e))for(const a of document.querySelectorAll("[data-testid=wkms-popup-tag-vocab] .chip")){const r=a.textContent?.replace(/[×x]\s*$/,"").trim()??"";if(r.toLowerCase().includes(e)){const c=document.createElement("li");c.textContent=r,s.appendChild(c)}}});n("tagVocab")?.addEventListener("click",t=>{const e=t.target;if(e.classList.contains("x")){e.parentElement?.remove();return}e.closest(".chip")?.classList.toggle("selected")});function v(t,e){const s=n("tagVocab");if(!s)return;const a=document.createElement("li");a.className="chip selected",a.innerHTML=`<span class="dot"></span>${f(t)}<button class="x" aria-label="remove">×</button>`,s.appendChild(a)}function f(t){return t.replace(/[&<>"']/g,e=>({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"})[e])}function d(){const t=n("comment")?.value.trim()||void 0,s=(n("tags")?.value||"").split(",").map(c=>c.trim()).filter(Boolean),a=[];for(const c of document.querySelectorAll("[data-testid=wkms-popup-tag-vocab] .chip.selected")){const l=c.textContent?.replace(/[×x]\s*$/,"").trim();l&&a.push(l)}const r=[...new Set([...a,...s])];return{userComment:t,userTags:r}}o("ready");
//# sourceMappingURL=popup-XQIYCqDn.js.map
