import{n as y,u as f,e as B,j as e,T as D,B as u,L as A,S as R,f as V,g as $,h as H,i as _,c as p,_ as N,k as h,l as C,m as U}from"./index-O0BQoyzo.js";import{r as v}from"./react-Cb2sDjhD.js";import{E as z}from"./empty-state-C-qjOHyu.js";import{u as W,a as Z,b as I}from"./use-workspace-BHG7h3jQ.js";import{L as P}from"./loader-circle-9VUMGitw.js";import{R as O}from"./refresh-ccw-D2CWiyU_.js";import"./useQuery-PdiC7-sY.js";/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Q=y("File",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const S=y("FolderTree",[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]);/**
 * @license lucide-react v0.469.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const q=y("Folder",[["path",{d:"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z",key:"1kt360"}]]);function re(){const{t}=f(["workspace","common"]),[r,c]=B(),s=r.get("agent")??"",n=r.get("path")??"",i=W().data??{},o=v.useMemo(()=>Object.keys(i).sort(),[i]),d=Z(s,n,{enabled:!!s}),l=d.data,g=l?.type==="dir",T=l?.type==="file";function k(a){const m=new URLSearchParams(r);for(const[F,b]of Object.entries(a))b==null||b===""?m.delete(F):m.set(F,b);c(m,{replace:!1})}function E(a){k({agent:a||null,path:null})}function j(a){k({path:a||null})}function w(){if(!n)return;const a=n.lastIndexOf("/"),m=a>=0?n.slice(0,a):"";j(m)}return e.jsxs("div",{className:"flex min-h-dvh flex-col bg-bg",children:[e.jsx(D,{}),e.jsxs("main",{className:"mx-auto flex w-full max-w-7xl flex-1 flex-col gap-4 px-3 py-4 sm:px-4 pb-safe",children:[e.jsxs("header",{className:"flex flex-col gap-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("h1",{className:"text-xl font-semibold",children:t("pageTitle")}),e.jsxs(u,{variant:"ghost",size:"sm",className:"ml-auto",onClick:()=>d.refetch(),disabled:!s||d.isFetching,"aria-label":t("actions.refresh",{ns:"common"}),children:[d.isFetching?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(O,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:t("actions.refresh",{ns:"common"})})]})]}),e.jsx("p",{className:"text-sm text-text-dim",children:t("subtitle")})]}),e.jsx("div",{className:"flex flex-wrap items-end gap-2",children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(A,{htmlFor:"agent",className:"text-xs text-text-dim",children:t("agentPicker.label")}),e.jsxs(R,{value:s||"__placeholder__",onValueChange:a=>E(a==="__placeholder__"?"":a),children:[e.jsx(V,{id:"agent",className:"w-64",children:e.jsx($,{placeholder:t("agentPicker.placeholder")})}),e.jsxs(H,{children:[e.jsx(_,{value:"__placeholder__",disabled:!0,children:t("agentPicker.placeholder")}),o.map(a=>e.jsx(_,{value:a,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono text-xs",children:a}),e.jsx("span",{className:p("inline-block h-1.5 w-1.5 rounded-full",i[a]?"bg-success":"bg-text-muted")}),e.jsx("span",{className:"text-text-dim text-xs",children:i[a]?t("agentPicker.online"):t("agentPicker.offline")})]})},a))]})]})]})}),s?e.jsxs(e.Fragment,{children:[e.jsx(K,{path:n,onNavigate:j,onUp:w}),d.isLoading?e.jsx("div",{className:"h-32 rounded-md bg-surface-2 animate-pulse"}):g&&l?.type==="dir"?e.jsx(G,{entries:l.entries,onEnter:a=>j(n?`${n}/${a.name}`:a.name)}):T&&l?.type==="file"?e.jsx(J,{file:l,agent:s,onBack:w}):e.jsx(z,{icon:e.jsx(S,{}),title:t("editor.loadFailed"),description:d.error?.message??""})]}):e.jsx(z,{icon:e.jsx(S,{}),title:t("noAgent.title"),description:t("noAgent.description")})]})]})}function K({path:t,onNavigate:r,onUp:c}){const{t:s}=f("workspace"),n=t?t.split("/"):[];return e.jsxs("div",{className:"flex flex-wrap items-center gap-1 text-sm",children:[e.jsx(u,{type:"button",variant:"ghost",size:"sm",onClick:c,disabled:!t,"aria-label":s("tree.up"),children:e.jsx(N,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",onClick:()=>r(""),className:"text-text-dim hover:text-text rounded px-1 py-0.5",children:s("tree.rootLabel")}),n.map((x,i)=>{const o=n.slice(0,i+1).join("/");return e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"text-text-muted",children:"/"}),e.jsx("button",{type:"button",onClick:()=>r(o),className:"text-text-dim hover:text-text rounded px-1 py-0.5",children:x})]},o)})]})}function G({entries:t,onEnter:r}){const{t:c}=f("workspace");return t.length===0?e.jsx("div",{className:"rounded-md border border-border bg-surface p-3 text-sm text-text-dim",children:c("tree.empty")}):e.jsx("ul",{className:"divide-y divide-border rounded-md border border-border bg-surface",children:t.map(s=>e.jsx("li",{children:e.jsxs("button",{type:"button",onClick:()=>r(s),disabled:s.broken||s.symlink_escape,className:p("flex w-full items-center gap-2 px-3 py-2 text-sm text-left","transition-colors hover:bg-surface-hover disabled:opacity-50 disabled:cursor-not-allowed"),children:[s.isDir?e.jsx(q,{className:"h-4 w-4 text-accent"}):e.jsx(Q,{className:"h-4 w-4 text-text-dim"}),e.jsx("span",{className:s.isDir?"font-medium text-text":"text-text",children:s.name}),s.symlink_escape&&e.jsx(h,{variant:"warning",className:"ml-2",children:c("tree.symlinkEscape")}),s.broken&&!s.symlink_escape&&e.jsx(h,{variant:"danger",className:"ml-2",children:c("tree.broken")}),!s.isDir&&s.size!=null&&e.jsx("span",{className:"ml-auto text-xs text-text-muted tabular-nums",children:M(s.size)}),s.mtime&&e.jsx("span",{className:p("text-xs text-text-muted tabular-nums",!s.isDir&&s.size!=null?"ml-3":"ml-auto"),children:L(s.mtime)})]})},s.name))})}function J({file:t,agent:r,onBack:c}){const{t:s}=f(["workspace","common"]),[n,x]=v.useState(t.content);v.useEffect(()=>{x(t.content)},[t.content]);const i=n!==t.content,o=I();async function d(){try{await o.mutateAsync({agent:r,path:t.path,body:{content:n}}),C.success(s("toast.saved",{path:t.path}))}catch(l){const{message:g}=U(l,s);C.error(g)}}return t.encoding==="base64"?e.jsxs("div",{className:"rounded-md border border-border bg-surface p-4 text-sm",children:[e.jsxs(u,{variant:"ghost",size:"sm",onClick:c,className:"mb-3",children:[e.jsx(N,{className:"h-4 w-4"}),s("tree.up")]}),e.jsx("p",{className:"text-text-dim",children:s("editor.binary")}),e.jsxs("p",{className:"mt-2 text-xs text-text-muted tabular-nums",children:[t.path," · ",M(t.size)]})]}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(u,{variant:"ghost",size:"sm",onClick:c,children:[e.jsx(N,{className:"h-4 w-4"}),s("tree.up")]}),e.jsx("code",{className:"rounded bg-surface-2 px-1.5 py-0.5 text-xs font-mono",children:t.path}),t.truncated&&e.jsx(h,{variant:"warning",children:"truncated"}),i&&e.jsx(h,{variant:"info",children:s("editor.dirtyHint")}),e.jsxs(u,{type:"button",size:"sm",className:"ml-auto",onClick:()=>void d(),disabled:!i||o.isPending||t.truncated,children:[o.isPending?e.jsx(P,{className:"h-4 w-4 animate-spin"}):null,o.isPending?s("editor.saving"):s("editor.save")]})]}),t.truncated&&e.jsx("p",{className:"text-xs text-warning",children:s("editor.truncated")}),e.jsx("textarea",{value:n,onChange:l=>x(l.target.value),rows:24,spellCheck:!1,className:p("w-full resize-y rounded-md border bg-bg px-3 py-2","font-mono text-xs leading-5","focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-1 focus:ring-offset-bg",i?"border-accent":"border-border")}),!i&&e.jsx("p",{className:"text-xs text-text-muted",children:s("editor.savedMeta",{size:t.size,at:L(t.mtime)})})]})}function L(t){if(t==null)return"—";try{const r=new Date(t);return Number.isNaN(r.getTime())?t:r.toLocaleString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}catch{return t}}function M(t){return t<1024?`${t} B`:t<1024*1024?`${(t/1024).toFixed(1)} KiB`:`${(t/1024/1024).toFixed(1)} MiB`}export{re as default};
//# sourceMappingURL=workspace-BnXrWS3j.js.map
