import{Ar as e,Er as t,Gn as n,J as r,Kn as i,L as a,Lt as o,M as s,N as c,Or as l,P as u,Qn as d,T as f,Un as p,Wn as m,Y as h,Yn as g,Zn as _,br as v,dr as y,er as b,gr as x,j as S,kr as C,lr as w,mr as T,q as E,qn as D}from"./index-MZ_Fxgyv.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-KagoqJUL.js";import{t as N}from"./_plugin-vue_export-helper-BDNMzG2s.js";var P={key:0,class:`text-caption text-medium-emphasis pa-3`},F=[`onClick`],I=[`onClick`],L=N(b({__name:`FileDirectoryTree`,props:{serverId:{},currentPath:{}},emits:[`navigate`],setup(b,{emit:N}){let L=b,R=N,z=v(!1),B=v(null),V=v(new Set([j])),H=v(new Map),U=n(()=>{let e=[],t=(n,r)=>{let i=H.value.get(n)??[];for(let n of i)e.push({...n,depth:r}),V.value.has(n.path)&&t(n.path,r+1)};return t(j,0),e});async function W(e){if(!L.serverId)return[];let{items:t}=O(await o.post(`/sync/browse`,{server_id:L.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 G(e){if(L.serverId){B.value=e;try{let t=await W(e);H.value.set(e,t);let n=H.value;t.forEach(e=>{n.has(e.path)||n.set(e.path,[])})}finally{B.value=null}}}async function K(){if(L.serverId){z.value=!0,H.value=new Map,V.value=new Set([j]);try{await G(j),H.value.get(j)?.forEach(e=>{H.value.set(e.path,[])})}finally{z.value=!1}}}async function q(e){if(V.value.has(e.path)){V.value.delete(e.path);return}H.value.has(e.path)||await G(e.path),V.value.add(e.path)}function J(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}`,V.value.add(r);V.value.add(j)}T(()=>L.serverId,e=>{e?K():(H.value=new Map,V.value=new Set)},{immediate:!0});async function Y(e){if(!L.serverId)return;let t=k(e);if(J(t),H.value.has(`/www/wwwroot`)||await G(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)H.value.has(i)||await G(i),i=A(i,e)}return T(()=>L.currentPath,e=>{e&&Y(e)}),(n,o)=>(w(),D(s,{border:``,rounded:`lg`,class:`file-dir-tree d-flex flex-column`},{default:x(()=>[d(u,{class:`text-subtitle-2 py-2 px-3 d-flex align-center`},{default:x(()=>[d(h,{size:`18`,class:`mr-1`},{default:x(()=>[...o[0]||=[_(`mdi-file-tree`,-1)]]),_:1}),o[1]||=_(` 目录 `,-1),d(M),d(a,{icon:`mdi-refresh`,size:`x-small`,variant:`text`,disabled:!b.serverId,onClick:K},null,8,[`disabled`])]),_:1}),d(S),d(c,{class:`file-dir-tree-body pa-0 flex-grow-1`},{default:x(()=>[b.serverId?z.value?(w(),D(E,{key:1,indeterminate:``})):(w(),D(f,{key:2,density:`compact`,nav:``,class:`py-0`},{default:x(()=>[(w(!0),g(m,null,y(U.value,n=>(w(),g(`div`,{key:n.path,class:`file-dir-tree-row d-flex align-center`,style:C({paddingLeft:`${8+n.depth*14}px`})},[i(`button`,{type:`button`,class:`file-dir-tree-toggle`,onClick:p(e=>q(n),[`stop`])},[B.value===n.path?(w(),D(r,{key:0,indeterminate:``,size:`14`,width:`2`})):(w(),D(h,{key:1,size:`16`},{default:x(()=>[_(e(V.value.has(n.path)?`mdi-chevron-down`:`mdi-chevron-right`),1)]),_:2},1024))],8,F),i(`button`,{type:`button`,class:l([`file-dir-tree-label text-body-2 text-truncate`,{"file-dir-tree-label--active":t(k)(b.currentPath)===n.path}]),onClick:e=>R(`navigate`,n.path)},[d(h,{size:`14`,class:`mr-1`},{default:x(()=>[...o[2]||=[_(`mdi-folder-outline`,-1)]]),_:1}),_(` `+e(n.name),1)],10,I)],4))),128))]),_:1})):(w(),g(`div`,P,`请先选择服务器`))]),_:1})]),_:1}))}}),[[`__scopeId`,`data-v-3ebb4390`]]);export{L as default};