import{o as l,c as n,a as i,b as _,v as O,F as g,r as u,n as m,d as v,t as c,_ as w,f as B}from"./_plugin-vue_export-helper-CfYZ6vGb.js";import{l as T,B as k,u as h}from"./util-RBPA3Ftj.js";const E="/img/memm_40.png",I={class:"header"},R={class:"tags"},A={class:"tag"},y=["href"],M=["src"],x={class:"bm-title"},C={class:"tags"},W={class:"tag"},D={class:"info"};function N(t,s,f,p,o,a){return l(),n("div",{id:"popup",onKeydown:s[4]||(s[4]=(...e)=>a.keydown&&a.keydown(...e))},[i("div",I,[i("img",{class:"link",src:E,onClick:s[0]||(s[0]=(...e)=>a.openOptions&&a.openOptions(...e))}),s[5]||(s[5]=i("span",{class:"title"},"memm ",-1)),_(i("input",{type:"text","onUpdate:modelValue":s[1]||(s[1]=e=>o.tag=e),ref:"tag",placeholder:"put some tags here",autofocus:""},null,512),[[O,o.tag]]),i("button",{class:"options-btn",type:"button",onClick:s[2]||(s[2]=(...e)=>a.openOptions&&a.openOptions(...e)),title:"Open memm options"},"⚙")]),i("div",R,[(l(!0),n(g,null,u(o.tags,(e,r)=>(l(),n("div",A,[i("span",null,c(e),1)]))),256))]),i("div",{class:m(["bookmarks",{selected:o.selected!=-1}])},[o.tags.length?(l(),n("a",{key:0,class:m(["bookmark",{selected:o.selected==0}]),href:"#",click:"addBookmark"},"Add bookmark",2)):v("",!0),(l(!0),n(g,null,u(o.bookmarks,(e,r)=>(l(),n("a",{class:m(["bookmark",{selected:o.selected==r+1}]),href:e.url,target:"parent"},[i("img",{class:"favicon",src:a.favicon(e.url,16),alt:"",width:"16",height:"16",loading:"lazy",onError:s[3]||(s[3]=(...d)=>a.onFaviconError&&a.onFaviconError(...d))},null,40,M),i("span",x,c(e.title),1)],10,y))),256))],2),i("div",C,[(l(!0),n(g,null,u(a.selectedBookmark.tags,e=>(l(),n("div",W,[i("span",null,c(e),1)]))),256)),i("div",D,c(a.selectedBookmark.url),1)])],32)}const P={computed:{selectedBookmark(){return this.bookmarks[this.selected-1]?this.bookmarks[this.selected-1]:!1}},data(){return{tags:[],tag:"",url:"",bookmarks:[],selected:-1,title:"",tabId:void 0}},mounted(){h.getCurrentTabInfo().then(t=>{this.url=t.url,this.title=t.title,this.tabId=t.id,this.$nextTick(()=>{h.sendMessage({msg:"getURLInfo",url:t.url,tabId:this.tabId}).then(this.currentTabInfo)})}),this.$refs.tag.focus()},methods:{favicon:T,onFaviconError(t){t.target.style.visibility="hidden"},openOptions(){k.runtime.openOptionsPage()},removeTag(t){this.tags.splice(t,1),h.sendMessage({msg:"setTags",title:this.title,url:this.url,tabId:this.tabId,tags:this.tags}).then(this.currentTabInfo)},matchBookmarks(t){this.bookmarks=t.filter(s=>s.url!==this.url),this.selected!==-1&&t.length<=this.selected&&(this.selected=0)},addBookmark(){const t=this.tag.replace(/[,\s]+/,"");t&&this.tags.indexOf(t)!==-1&&this.tags.push(t),!this.tags.length===0&&this.tags.push("untagged"),this.tag="";const s={msg:"setTags",title:this.title,url:this.url,tabId:this.tabId,tags:this.tags};h.sendMessage(s),window.close()},keydown(t){if(t.which==38&&(this.selected===-1?this.selected=this.bookmarks.length:this.selected-=1),t.which===40&&(this.selected===this.bookmarks.length?this.selected=-1:this.selected+=1),t.which===32||t.which===188||t.which===9){const r=this.tag.replace(/[,\s]+/,"");if(!r||this.tags.indexOf(r)!==-1){t.preventDefault();return}this.tags.push(r),this.tag="",t.preventDefault(),h.sendMessage({msg:"searchTags",tags:this.tags}).then(d=>{this.bookmarks=d.filter(b=>b.url!=this.url)})}if(t.which===13){if(this.selected==-1){this.addBookmark();return}const r=this.tag.replace(/[,\s]+/,"");r&&this.tags.indexOf(r)===-1&&this.tags.push(r),this.selectedBookmark?k.tabs.create({url:this.selectedBookmark.url,active:!0}):h.sendMessage({msg:"searchTags",tags:this.tags}).then(d=>this.bookmarks=d),window.close()}},currentTabInfo(t){t?(this.tags=t.tags,this.bookmarks=t.related.filter(s=>s.url!==this.url)):(console.error("lastError",k.runtime.lastError),this.bookmarks=[]),this.selected!==-1&&this.info.related.length<=this.selected&&(this.selected=-1)}}},F=w(P,[["render",N]]);B(F).mount("#mount");
//# sourceMappingURL=popup.html-DErdCqKE.js.map
