import{r as e,j as s}from"./vendor-react-DcxrbCFs.js";import{u as a,M as t}from"./vendor-intl-C0z7gCkr.js";import{a0 as l}from"./c4b350ac1-BTR_0NaM.js";import{f as n,P as i,B as o,I as r}from"./vendor-ant-cds-BOj-tX6j.js";import{u as d,b as m,g as p,f as c,a as h,F as f}from"./c0632795f-CL3ffsDQ.js";import{S as u}from"./c2eed10ca-CNMgnIW2.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(),[b,v]=e.useState(null),[F,y]=e.useState(!1),[w,C,M]=d(),S=e.useMemo(()=>n.length>0?m(n):null,[n]),L=e.useRef(!1);e.useEffect(()=>{if(S&&!L.current){L.current=!0;const e=p(S),s=c(S);if(s){const a=s.split("/");for(let s=1;s<a.length;s++)e.add(a.slice(0,s).join("/"))}M(e)}},[S,M]);const B=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(B?1:0).join("/"):null,t=b??a??(S?c(S):null)??n[0].path,l=B?`${B}/${t}`:t;return{...n.find(s=>e(s.path)===l)??n[0],path:t}},[n,S,b,B]),z=e.useCallback((e,s)=>{"file"===s.type&&(v(s.path),y(!1))},[]),I=!!S&&n.length>1,P=l(k?.path.split("/").pop()??k?.path??""),T=I?s.jsxs(s.Fragment,{children:[s.jsxs(i.Root,{open:F,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:S,selectedPath:k?.path??null,expandedFolders:w,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};
