import{$n as e,Ar as t,Dr as n,J as r,Jn as i,Kn as a,L as o,Lt as s,M as c,N as l,P as u,Qn as d,T as f,Un as p,Wn as m,Xn as h,Y as g,_r as _,fr as v,hr as y,j as b,jr as x,kr as S,q as C,qn as w,tr as T,ur as E,xr as D}from"./index-B44VVsv4.js";import{t as O}from"./fileBrowse-DPJUbvU6.js";import{i as k,r as A,t as j}from"./remotePath-Dnz5p3-E.js";import{t as M}from"./VSpacer-v09_iay_.js";import{t as N}from"./_plugin-vue_export-helper-BDNMzG2s.js";var P={key:1,class:`file-dir-tree-embedded-bar d-flex align-center px-2 py-1`},F={key:0,class:`text-caption text-medium-emphasis pa-3`},I=[`onClick`],L=[`onClick`,`onContextmenu`],R=N(T({__name:`FileDirectoryTree`,props:{serverId:{},currentPath:{},embedded:{type:Boolean}},emits:[`navigate`,`paste-target`],setup(T,{emit:N}){let R=T,z=N,B=D(!1),V=D(null),H=D(new Set([j])),U=D(new Map),W=a(()=>{let e=[],t=(n,r)=>{let i=U.value.get(n)??[];for(let n of i)e.push({...n,depth:r}),H.value.has(n.path)&&t(n.path,r+1)};return t(j,0),e});async function G(e){if(!R.serverId)return[];let{items:t}=O(await s.post(`/sync/browse`,{server_id:R.serverId,path:k(e)}));return t.filter(e=>e.type===`directory`).sort((e,t)=>e.name.localeCompare(t.name)).map(t=>({path:A(e,t.name),name:t.name,depth:0,hasChildren:!0,loaded:!1}))}async function K(e){if(R.serverId){V.value=e;try{let t=await G(e);U.value.set(e,t);let n=U.value;t.forEach(e=>{n.has(e.path)||n.set(e.path,[])})}finally{V.value=null}}}async function q(){if(R.serverId){B.value=!0,U.value=new Map,H.value=new Set([j]);try{await K(j),U.value.get(j)?.forEach(e=>{U.value.set(e.path,[])})}finally{B.value=!1}}}async function J(e){if(H.value.has(e.path)){H.value.delete(e.path);return}U.value.has(e.path)||await K(e.path),H.value.add(e.path)}function Y(e){let t=k(e);if(t===`/www/wwwroot`)return;let n=t.split(`/`).filter(Boolean),r=``;for(let e of n)r=r?`${r}/${e}`:`/${e}`,H.value.add(r);H.value.add(j)}y(()=>R.serverId,e=>{e?q():(U.value=new Map,H.value=new Set)},{immediate:!0});async function X(e){if(!R.serverId)return;let t=k(e);if(Y(t),U.value.has(`/www/wwwroot`)||await K(j),t===`/www/wwwroot`)return;let n=(`/www/wwwroot`.endsWith(`/`),j),r=(t.startsWith(n)?t.slice(n.length):t).split(`/`).filter(Boolean),i=j;for(let e of r)U.value.has(i)||await K(i),i=A(i,e)}return y(()=>R.currentPath,e=>{e&&X(e)}),(a,s)=>(E(),i(c,{border:``,rounded:`lg`,class:S([`file-dir-tree d-flex flex-column`,{"file-dir-tree--embedded":T.embedded}])},{default:_(()=>[T.embedded?(E(),h(`div`,P,[e(g,{size:`16`,class:`mr-1 text-medium-emphasis`},{default:_(()=>[...s[2]||=[d(`mdi-file-tree`,-1)]]),_:1}),s[3]||=w(`span`,{class:`text-caption text-medium-emphasis`},`目录`,-1),e(M),e(o,{icon:`mdi-refresh`,size:`x-small`,variant:`text`,disabled:!T.serverId,onClick:q},null,8,[`disabled`])])):(E(),i(u,{key:0,class:`text-subtitle-2 py-2 px-3 d-flex align-center`},{default:_(()=>[e(g,{size:`18`,class:`mr-1`},{default:_(()=>[...s[0]||=[d(`mdi-file-tree`,-1)]]),_:1}),s[1]||=d(` 目录 `,-1),e(M),e(o,{icon:`mdi-refresh`,size:`x-small`,variant:`text`,disabled:!T.serverId,onClick:q},null,8,[`disabled`])]),_:1})),e(b),e(l,{class:`file-dir-tree-body pa-0 flex-grow-1`},{default:_(()=>[T.serverId?B.value?(E(),i(C,{key:1,indeterminate:``})):(E(),i(f,{key:2,density:`compact`,nav:``,class:`py-0`},{default:_(()=>[(E(!0),h(m,null,v(W.value,a=>(E(),h(`div`,{key:a.path,class:`file-dir-tree-row d-flex align-center`,style:t({paddingLeft:`${8+a.depth*14}px`})},[w(`button`,{type:`button`,class:`file-dir-tree-toggle`,onClick:p(e=>J(a),[`stop`])},[V.value===a.path?(E(),i(r,{key:0,indeterminate:``,size:`14`,width:`2`})):(E(),i(g,{key:1,size:`16`},{default:_(()=>[d(x(H.value.has(a.path)?`mdi-chevron-down`:`mdi-chevron-right`),1)]),_:2},1024))],8,I),w(`button`,{type:`button`,class:S([`file-dir-tree-label text-body-2 text-truncate`,{"file-dir-tree-label--active":n(k)(T.currentPath)===a.path}]),onClick:e=>z(`navigate`,a.path),onContextmenu:p(e=>z(`paste-target`,a.path),[`prevent`])},[e(g,{size:`14`,class:`mr-1`},{default:_(()=>[...s[4]||=[d(`mdi-folder-outline`,-1)]]),_:1}),d(` `+x(a.name),1)],42,L)],4))),128))]),_:1})):(E(),h(`div`,F,`请先选择服务器`))]),_:1})]),_:1},8,[`class`]))}}),[[`__scopeId`,`data-v-0bdd7943`]]);export{R as default};