import{g as z}from"./DWMekDlu.js";import{b as v,d as q,u as P}from"./By4k6Jl4.js";import{a as F}from"./DZ-eGQow.js";import{b as x,s as A}from"./Bsjjgt65.js";import{a as O,d as L,b as Q}from"./C0hR61LB.js";import{b as R}from"./C-zTT_Iy.js";import{i as I,h as $}from"./CgplSB0v.js";import{i as C}from"./Dxzbedgu.js";import{a as G}from"./DBS0nwNO.js";import{b as N,c as w}from"./CTTac_MU.js";import{b as k}from"./F8doVSIJ.js";import{t as M}from"./DCgJc6Y6.js";import{i as T}from"./ouiv4kfg.js";import{b as D,s as U,o as B}from"./DBmjMhyE.js";import{b as K}from"./CqhM8qkX.js";import{a as l}from"./D-ho4O35.js";import{E as p,I as g,P as W}from"./CKVH188_.js";function H(e){var t=e==null?0:e.length;return t?D(e):[]}function E(e){return U(B(e,void 0,H),e+"")}function X(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}function Y(e){return typeof e=="function"?e:I}function Z(e,t){var s=C(e)?O:R;return s(e,Y(t))}function j(e,t){return t.length<2?e:N(e,k(t,0,-1))}function J(e,t){return t=w(t,e),e=j(e,t),e==null||delete e[M(X(t))]}function V(e){return T(e)?void 0:e}var ee=1,te=2,re=4,se=E(function(e,t){var s={};if(e==null)return s;var r=!1;t=G(t,function(o){return o=w(o,e),r||(r=o.length>1),o}),L(e,K(e),s),r&&(s=Q(s,ee|te|re,V));for(var n=t.length;n--;)J(s,t[n]);return s});function ne(e,t){return x(e,t,function(s,r){return $(e,r)})}var y=E(function(e,t){return e==null?{}:ne(e,t)});function oe(e){var r,n,o,c;const t={},s={};return e.rate_plans.forEach(a=>{var m,u;(m=a.architectures)==null||m.forEach(i=>{t[i.name]||(t[i.name]=i)}),(u=a.operating_systems)==null||u.forEach(i=>{s[i.name]||(s[i.name]=i)})}),{id:e.id,name:e.name,slug:e.slug,type:e.type,publisher:e.publisher,created_at:e.created_at,updated_at:e.updated_at,short_description:e.short_description,source:e.source,star_count:e.star_count,pull_count:((c=(o=(n=(r=e.rate_plans)==null?void 0:r[0])==null?void 0:n.repositories)==null?void 0:o[0])==null?void 0:c.pull_count)??"",logo_url:e.logo_url,extension_reviewed:e.extension_reviewed,operating_systems:Object.values(s),architectures:Object.values(t),categories:e.categories,archived:e.archived}}const ie=["architectures","image_filter","operating_systems","order","from","size","query","sort","type","source","official","open_source","categories"],ae=["image_filter","order","size","from","query","sort","type","source","official","open_source","categories"],ce=["size","from","query","image_filter","extension_reviewed","type","order","sort","source","open_source"],Ae=({name:e,slug:t,type:s})=>{const r=s||g,[n,o]=(e??t).split("/");if(o&&r!==p)return l("/r/:namespace/:reponame",{namespace:n,reponame:o});switch(r){case g:return l("/_/:id",{id:v(t)});case p:{const[c,a]=v(t).split("/");return l("/extensions/:namespace/:reponame",{namespace:c,reponame:a})}default:return""}};function ue(e){var r;const t={...e};switch(t.query||(t.query=""),typeof t.type=="string"?t.type:(r=t.type)==null?void 0:r[0]){case g:return y(t,ie);case W:return y(t,ae);case p:return y(t,ce);default:return se(t,"type")}}const Oe=(e={})=>{const t=["architecture","image_filter","operating_system","page_size","page","q","sort","source","type"];let s=`${l("/search")}?`;return Z(t,r=>{if(e[r]){const n=s.endsWith("?")?"":"&";s=`${s}${n}${r}=${e[r]}`}}),s.endsWith("?")?l("/search"):s},d="/api/search/v3/catalog/search";async function S(e,t,s){var u,i,_,h;const r=ue({...e,size:e.size||z}),n={...r,operating_systems:r.operating_systems&&r.operating_systems.length?(u=e.operating_systems)==null?void 0:u.join(","):void 0,architectures:r.architectures&&r.architectures.length?(i=r.architectures)==null?void 0:i.join(","):void 0,images:r.images&&r.images.length?(_=r.images)==null?void 0:_.join(","):void 0,extension_reviewed:((h=r.extension_reviewed)==null?void 0:h.length)===2?void 0:r.extension_reviewed,categories:r.categories&&r.categories.length?r.categories.join(","):void 0},o=new URLSearchParams(Object.entries(n).filter(([,f])=>f!=null).map(([f,b])=>[f,String(b)])),a=await(await q(`${d}?${o.toString()}`,{signal:s})).json();return F("search",A({browsing:e.query==="",count:a.total,image_filter:t,operating_system:e.operating_systems,architecture:e.architectures,images:e.images,q:e.query,page:e.from&&r.size?Math.floor(e.from/r.size+1):1,page_size:r.size,source:e.source,extension_reviewed:e.extension_reviewed,official:e.official,open_source:e.open_source,order:e.order,sort:e.sort,type:e.type,categories:e.categories})),{total:a.total,results:a.results.map(f=>oe(f))}}function fe(){const e={size:15,official:!0,open_source:!1,type:g};return{queryKey:[d,e.query,e.official,e.open_source,e.source,e.type,e.operating_systems,e.architectures,e.extension_reviewed,e.from,e.size,e.sort,e.order],queryFn:()=>S(e)}}function le(e,t){return{queryKey:[d,e.query,e.official,e.open_source,e.source,e.type,e.operating_systems,e.architectures,e.extension_reviewed,e.from,e.size,e.sort,e.order,e.categories],queryFn:()=>S(e,t)}}function Le(e){return P({...fe(),...e})}function Qe(e,t,s){return P({...le(e,s),...t})}function Re(e,t){const s=e.reduce((r,n)=>(r[n.slug]=n,r),{});return t.map(r=>{const n=r.images.map(o=>s[o.slug]||o);return{...r,images:n}})}export{Ae as a,Re as b,Le as c,Oe as d,S as e,fe as g,oe as t,Qe as u};