import{at as m,E as g,t as p,Q as f,d as w,e as I,V as y,o as _,c as b,Z as C,a as k,b as v,r as u}from"./index-ongssuUn.js";import{A}from"./add-custom-DckXlY1T.js";const N=(e,t)=>{if(!e)return null;if(e.id===t)return e;if(e.children)for(const n of e.children){const c=N(n,t);if(c)return c}return null};function R(e,t){var n;return!e||e.id===t?null:(e.children=(n=e.children)==null?void 0:n.map(c=>R(c,t)).filter(c=>c!==null),e)}const l=new Map;function x(e){var t,n;if(!e)return"";if(l.has(e))return l.get(e)||"";try{let c="";if((n=(t=window.chrome)==null?void 0:t.runtime)!=null&&n.getURL){const s=new URL(window.chrome.runtime.getURL("/_favicon/"));s.searchParams.set("pageUrl",e),s.searchParams.set("size","32"),c=s.toString()}else c=`https://www.google.com/s2/favicons?domain=${new URL(e).hostname}&sz=32`;return l.set(e,c),c}catch{return l.set(e,""),""}}const U=async e=>{for(let t=0;t<e.length;t++)e[t].children?await U(e[t].children):e[t].src=x(e[t].url)},D=(e,t,n)=>{var c,s;if(e)if((c=e.children)!=null&&c.length)for(let i=0;i<e.children.length;i++)e.children[i].children?D(e.children[i],t,n):typeof((s=e.children[i])==null?void 0:s[t])=="boolean"&&(e.children[i][t]=n);else typeof(e==null?void 0:e[t])=="boolean"&&(e[t]=n)};function S(e){if(!e)return[];let t=e.selectedAdd?[e]:[];for(const n of(e==null?void 0:e.children)??[])t=t.concat(S(n));return t}function L(e,t){if(!e)return[];let n=e.title.indexOf(t)!==-1?[e]:[];for(const c of(e==null?void 0:e.children)??[])n=n.concat(L(c,t));return n}const h=async e=>{var c,s,i,r;let t="";const n=await m({url:e.url});return n.code==0&&(t=((s=(c=n.data)==null?void 0:c[0])==null?void 0:s.src)??"",g({message:p("获取图标成功!"),grouping:!0,type:"success"})),{src:t,background:((r=(i=n.data)==null?void 0:i[0])==null?void 0:r.background)??"rgba(255, 255, 255, 1)"}},T=async e=>{var n;const t=[];for(let c=0;c<e.length;c++){const s=e[c];if(s.url){const{src:i,background:r}=await h(s),a={id:f(),name:s.title,type:"icon",url:s.url,background:r,src:i};t.push(a)}else if((n=s==null?void 0:s.children)!=null&&n.length){const i=await T(s.children),r={id:f(),name:s.title,isList:!0,type:"component",component:"Folder",size:"2x2",children:i};t.push(r)}}return t},M=w({name:"EditIconDialog",__name:"tree-add-dialog",props:{editIconItem:{}},setup(e){const t=e,n=u();I(()=>{y(async()=>{var a,o,d;if(!t.editIconItem)return;const{src:i,background:r}=await h(t.editIconItem);(d=n.value)==null||d.setFormData({name:((a=t.editIconItem)==null?void 0:a.title)??"",url:((o=t.editIconItem)==null?void 0:o.url)??"",src:i,iconType:0,iconColor:r})})});const c=u(),s=()=>{var i;(i=c.value)==null||i.close()};return(i,r)=>(_(),b(C,{ref_key:"DialogRef",ref:c,title:i.$t("添加书签到分组"),"append-to-body":"",width:"600"},{default:k(({})=>[v(A,{type:"bookMarks",ref_key:"AddCustomRef",ref:n,onSeve:s},null,512)]),_:1},8,["title"]))}});export{M as _,L as a,S as b,U as c,R as d,x as e,N as f,T as g,D as s};
