import{hc as I,ic as T}from"./chunk-yn2wp55x.js";import{jc as _,kc as w}from"./chunk-dnw4x7bh.js";import{lc as y,oc as M}from"./chunk-ghzc37v7.js";w();async function Y(){try{let{packages:E}=await import("./chunk-n6yv503d.js");return E}catch{return{}}}async function F(E){let q=Z(E);if(!q)return null;let z=(await Y())[q];if(!z||!z.versions||z.versions.length===0)return null;return z.versions[0]}async function x(E){let q=Z(E);if(!q)return[];let z=(await Y())[q];if(!z||!z.versions)return[];return[...z.versions]}function f(E={}){let q=["8.4.11","8.3.14","8.2.26","8.1.30"],H=E.fallbackVersions||q;try{let{pantry:z}=(T(),y(I)),G=z.phpnet||z.php;if(!G||!G.versions||G.versions.length===0)return H;let K=[...G.versions],J=E.supportedBranches||D(K),Q=new Map;for(let R of K){let[U,X]=R.split(".");if(!U||!X)continue;let W=`${U}.${X}`;if(J.includes(W)&&!Q.has(W))Q.set(W,R)}let O=J.map((R)=>Q.get(R)).filter(Boolean);return O.length>0?O:H}catch{return H}}function D(E){let q=new Map;for(let z of E){let[G,K]=z.split(".");if(!G||!K)continue;let J=`${G}.${K}`;q.set(J,(q.get(J)||0)+1)}return Array.from(q.keys()).filter((z)=>{let[G]=z.split(".");return G==="8"&&q.get(z)>3}).sort((z,G)=>{let[K,J]=z.split(".").map(Number),[Q,O]=G.split(".").map(Number);if(K!==Q)return Q-K;return O-J}).slice(0,4)}async function C(E,q){return(await x(E)).includes(q)}async function h(E,q="latest"){if(q==="latest")return await F(E);let H=await x(E);if(H.length===0)return null;if(H.includes(q))return q;if(q.startsWith("^")){let G=q.slice(1).split(".")[0];return H.filter((J)=>J.startsWith(`${G}.`))[0]||null}if(q.startsWith("~")){let z=q.slice(1),[G,K]=z.split("."),J=`${G}.${K}.`;return H.filter((O)=>O.startsWith(J))[0]||null}if(q.startsWith(">=")){let G=q.slice(2).split(".").map(Number);return H.filter((J)=>{let Q=J.split(".").map(Number);for(let O=0;O<Math.max(Q.length,G.length);O++){let R=Q[O]??0,U=G[O]??0;if(R>U)return!0;if(R<U)return!1}return!0})[0]||null}return await F(E)}async function $(E){let q=Z(E);if(!q)return null;let z=(await Y())[q];if(!z)return null;let G=await F(E);if(!G)return null;return{name:String(E),domain:q,description:z.description||"",latestVersion:G,totalVersions:z.versions?.length||0,programs:[...z.programs||[]],dependencies:[...z.dependencies||[]],companions:[...z.companions||[]],versions:[...z.versions||[]]}}function Z(E){let q=String(E);if(q in _){let H=_[q];return L(H)}return L(q)}function L(E){if(E.includes("/")){let[q,...H]=E.split("/"),z=H.join("/"),G=q.replace(/\./g,""),K=z.replace(/[/\-_.]/g,"").toLowerCase();return`${G}${K}`.toLowerCase()}return E.replace(/[.\-_]/g,"").toLowerCase()}async function N(E){let q=[],H=E.toLowerCase();for(let[G,K]of Object.entries(_))if(G.toLowerCase().includes(H)){let J=await $(G);if(J)q.push(J)}let z=await Y();for(let[G,K]of Object.entries(z))if(G.toLowerCase().includes(H)||K.description?.toLowerCase().includes(H)){let J=await $(G);if(J&&!q.some((Q)=>Q.domain===G))q.push(J)}return q}async function P(E){let q=[],H=await Y();for(let z of Object.keys(H))if(E.test(z)){let G=await $(z);if(G)q.push(G)}return q}async function j(E=10){let q=[],H=await Y();for(let z of Object.keys(H)){let G=await $(z);if(G&&G.totalVersions>=E)q.push(G)}return q.sort((z,G)=>G.totalVersions-z.totalVersions)}async function S(E=50){return(await j(5)).slice(0,E)}async function V(E){try{let q=E.lastIndexOf("@");if(q===-1){let J=E;if(!Z(J))return{isValid:!1,error:`Unknown package: ${J}`};return{isValid:!0,packageName:J}}let H=E.slice(0,q),z=E.slice(q+1);if(!Z(H))return{isValid:!1,error:`Unknown package: ${H}`};if(z==="latest")return{isValid:!0,packageName:H,version:z};if(!await C(H,z))return{isValid:!1,packageName:H,version:z,error:`Version ${z} not available for package ${H}`};return{isValid:!0,packageName:H,version:z}}catch{return{isValid:!1,error:`Invalid package specification: ${E}`}}}function d(E,q){if(!q||q.length===0)return null;let H=[...q].sort((O,R)=>{let U=O.split(".").map(Number),X=R.split(".").map(Number);for(let W=0;W<Math.max(U.length,X.length);W++){let A=U[W]||0,B=X[W]||0;if(A!==B)return B-A}return 0}),z=E.replace(/^[\^~]/,""),G=z.split("."),K=Number.parseInt(G[0],10),J=Number.parseInt(G[1]||"0",10);if(E.startsWith("^"))return H.filter((R)=>{return Number.parseInt(R.split(".")[0],10)===K})[0]||null;if(E.startsWith("~"))return H.filter((R)=>{let U=R.split("."),X=Number.parseInt(U[0],10),W=Number.parseInt(U[1]||"0",10);return X===K&&W===J})[0]||null;if(H.includes(z))return z;return H.filter((O)=>O.startsWith(z))[0]||H[0]||null}
export{F as Ub,x as Vb,f as Wb,C as Xb,h as Yb,$ as Zb,Z as _b,N as $b,P as ac,j as bc,S as cc,V as dc,d as ec};
