import{Kc as j,Lc as E}from"./cli-0.5.4-q7qfy21z.mjs";import{UH as X,WH as Y,dI as Z,en as W,fI as w,hn as v,jI as _,lI as $,qI as f}from"./cli-0.5.4-k5fz4zd3.mjs";import{B6 as Q,C_ as A,J6 as T,Paa as V,_aa as N,p_ as S}from"./cli-0.5.4-cbq01zg3.mjs";import{Pfa as B,Sfa as R}from"./cli-0.5.4-end8wj9r.mjs";import{Gga as L,Nga as K}from"./cli-0.5.4-sgcaw17t.mjs";import{Zma as y}from"./cli-0.5.4-aacw1src.mjs";function d(q){if(J=q,G!==null&&G.length>0)q(G),G=null;return()=>{J=null}}async function C(){let q=await Y(),D=X(),x=new Set;for(let[z,h]of Object.entries(q)){let F=D[z]?.autoUpdate;if(F!==void 0?F:S(z,h))x.add(z.toLowerCase())}return x}async function M(q,D){let x=!1;for(let{scope:z}of D)try{let h=await j(q,z);if(h.success&&!h.alreadyUpToDate)x=!0,B(`Plugin autoupdate: updated ${q} from ${h.oldVersion} to ${h.newVersion}`);else if(!h.alreadyUpToDate)B(`Plugin autoupdate: failed to update ${q}: ${h.message}`,{level:"warn"})}catch(h){B(`Plugin autoupdate: error updating ${q}: ${L(h)}`,{level:"warn"})}return x?q:null}async function P(q){let D=_(),x=Object.keys(D.plugins);if(x.length===0)return[];return(await Promise.allSettled(x.map(async(h)=>{let{marketplace:F}=W(h);if(!F||!q.has(F.toLowerCase()))return null;let H=D.plugins[h];if(!H||H.length===0)return null;let O=H.filter($);if(O.length===0)return null;return M(h,O)}))).filter((h)=>h.status==="fulfilled"&&h.value!==null).map((h)=>h.value)}async function m(q){return P(q)}function t(){(async()=>{if(V()){B("Plugin autoupdate: skipped (auto-updater disabled)");return}try{let q=await C();if(q.size===0)return;let x=(await Promise.allSettled(Array.from(q).map(async(h)=>{try{await Z(h,void 0,{disableCredentialHelper:!0})}catch(F){B(`Plugin autoupdate: failed to refresh marketplace ${h}: ${L(F)}`,{level:"warn"})}}))).filter((h)=>h.status==="rejected");if(x.length>0)B(`Plugin autoupdate: ${x.length} marketplace refresh(es) failed`,{level:"warn"});B("Plugin autoupdate: checking installed plugins");let z=await m(q);if(z.length>0)if(J)J(z);else G=z}catch(q){Q(q)}})()}var J=null,G=null;var U=y(()=>{E();N();R();K();T();f();w();v();A()});
export{d as gc,P as hc,t as ic,U as jc};
