const p="manifest.json",h={config:0,skill:1,cron:2,dockerfile:3,other:4};function y(r,n,o){return{key:r,name:n,type:"folder",children:[],resourceType:o}}function F(r){return[...r].sort((n,o)=>n.type!==o.type?n.type==="folder"?-1:1:n.name.localeCompare(o.name)).map(n=>n.type==="folder"&&n.children?{...n,children:F(n.children)}:n)}function m(r,n,o){const u=n.split("/").filter(Boolean);let l=r,s="";for(const i of u){s=s?`${s}/${i}`:i;const d=`${o}/${s}/`;let e=l.children?.find(t=>t.type==="folder"&&t.key===d);e||(e=y(d,i,o),l.children.push(e)),l=e}return l}function x(r,n,o=[]){const u=[],l=new Set;u.push({key:p,name:p,type:"file"});const s=new Map,i=e=>{let t=s.get(e);return t||(t=y(`${e}/`,`${e}/`,e),s.set(e,t)),t};for(const e of o){const t=e.replace(/^\/+|\/+$/g,"");if(!t)continue;const[c,...a]=t.split("/");if(c){if(a.length===0){i(c),l.add(c);continue}m(i(c),a.join("/"),c)}}for(const e of Object.values(r)){const t=e.type||"other",c=i(t),a=e.name.split("/").filter(Boolean),f=a.pop();if(!f)continue;(a.length>0?m(c,a.join("/"),t):c).children.push({key:`${t}/${e.name}`,name:f,type:"file",resourceType:t})}const d=[...s.keys()].sort((e,t)=>(h[e]??99)-(h[t]??99));for(const e of d){const t=s.get(e);((t.children?.length??0)>0||l.has(e))&&u.push({...t,children:F(t.children)})}return u}function k(r){if(r==="Dockerfile"||r.endsWith("/Dockerfile"))return"dockerfile";const n=r.lastIndexOf(".");if(n===-1)return"plaintext";switch(r.slice(n).toLowerCase()){case".json":return"json";case".md":return"markdown";case".js":return"javascript";case".ts":return"typescript";case".yaml":case".yml":return"yaml";case".xml":return"xml";case".html":return"html";case".css":return"css";case".sh":return"shell";default:return"plaintext"}}export{x as b,k as g};
