import{r as e,j as s}from"./vendor-react-Dp9pL_Wn.js";import{u as a,M as t}from"./vendor-intl-D2wGIp4M.js";import{a7 as l}from"./c6eedc03a-CsEFTfjy.js";import{b as n,P as i,B as o,I as r}from"./vendor-ant-cds-bBedrtIN.js";import{ao as d,ap as m,aq as p,ar as c,as as h,at as f}from"./index-DhMXk6CR.js";import{S as u}from"./c0659e756-Cln-oPN5.js";const x=e.memo(({children:e,className:a})=>s.jsx("div",{className:n("flex-1 flex flex-col min-h-0 overflow-hidden bg-surface-1 text-body border border-border-300 rounded-xl p-5",a),children:e}));x.displayName="FileContentContainer";const j=e.memo(({files:n,isLoading:j=!1,hideCopyButton:g})=>{const N=a(),[v,b]=e.useState(null),[w,y]=e.useState(!1),[F,C,S]=d(),M=e.useMemo(()=>n.length>0?m(n):null,[n]),B=e.useRef(!1);e.useEffect(()=>{if(M&&!B.current){B.current=!0;const e=p(M),s=c(M);if(s){const a=s.split("/");for(let s=1;s<a.length;s++)e.add(a.slice(0,s).join("/"))}S(e)}},[M,S]);const L=e.useMemo(()=>h(n),[n]),k=e.useMemo(()=>{if(0===n.length)return null;const e=e=>e.split("/").filter(Boolean).join("/"),s=n.find(e=>"SKILL.md"===e.path||e.path.endsWith("/SKILL.md")),a=s?e(s.path).split("/").slice(L?1:0).join("/"):null,t=v??a??(M?c(M):null)??n[0].path,l=L?`${L}/${t}`:t;return{...n.find(s=>e(s.path)===l)??n[0],path:t}},[n,M,v,L]),z=e.useCallback((e,s)=>{"file"===s.type&&(b(s.path),y(!1))},[]),I=!!M&&n.length>1,P=l(k?.path.split("/").pop()??k?.path??""),T=I?s.jsxs(s.Fragment,{children:[s.jsxs(i.Root,{open:w,onOpenChange:y,children:[s.jsx(i.Trigger,{render:s.jsxs(o,{variant:"secondary",size:"sm","aria-label":N.formatMessage({defaultMessage:"{name}. Choose a file in this skill",id:"iaA9zpzp0N"},{name:P}),children:[s.jsx("span",{className:"truncate max-w-[220px] font-normal",children:P}),s.jsx(r,{name:"CaretDown",size:"sm"})]})}),s.jsx(i.Popup,{side:"bottom",align:"start",className:"w-[260px] max-h-[min(400px,60vh)] p-sm overflow-y-auto",children:s.jsx(f,{fileTree:M,selectedPath:k?.path??null,expandedFolders:F,onFileSelect:z,onToggleFolder:C,variant:"settings",className:"w-full"})})]}),s.jsx("span",{className:"text-muted text-caption shrink-0",children:s.jsx(t,{defaultMessage:"{total, plural, one {# file} other {# files}}",id:"fy9BG3dE9F",values:{total:n.length}})})]}):null;return s.jsx(x,{className:"min-w-0 p-0",children:s.jsx(u,{file:k,isLoading:j,hideFileName:!0,hideCopyButton:g,hideDescriptionHeading:!0,leadingActions:T})})});j.displayName="SkillFileBrowser";export{x as F,j as S};
