import{$n as e,Ar as t,Gn as n,It as r,J as i,Jn as a,L as o,M as s,Mr as c,N as l,Or as u,P as d,Sr as f,Wn as p,Y as m,Yn as h,Zn as g,dr as _,er as v,gr as y,j as b,jr as x,nr as S,pr as C,q as w,qn as T,vr as E,w as D}from"./index-9ZGEqHPG.js";import{t as O}from"./fileBrowse-D87Kx7nu.js";import{i as k,r as A,t as j}from"./remotePath-BY9H9-d2.js";import{t as M}from"./VSpacer-Cu4v-Rar.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(S({__name:`FileDirectoryTree`,props:{serverId:{},currentPath:{},embedded:{type:Boolean}},emits:[`navigate`,`paste-target`],setup(S,{emit:N}){let R=S,z=N,B=f(!1),V=f(null),H=f(new Set([j])),U=f(new Map),W=T(()=>{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 r.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)}),(r,f)=>(_(),h(s,{border:``,rounded:`lg`,class:t([`file-dir-tree d-flex flex-column`,{"file-dir-tree--embedded":S.embedded}])},{default:E(()=>[S.embedded?(_(),g(`div`,P,[v(m,{size:`16`,class:`mr-1 text-medium-emphasis`},{default:E(()=>[...f[2]||=[e(`mdi-file-tree`,-1)]]),_:1}),f[3]||=a(`span`,{class:`text-caption text-medium-emphasis`},`目录`,-1),v(M),v(o,{icon:`mdi-refresh`,size:`x-small`,variant:`text`,disabled:!S.serverId,onClick:q},null,8,[`disabled`])])):(_(),h(d,{key:0,class:`text-subtitle-2 py-2 px-3 d-flex align-center`},{default:E(()=>[v(m,{size:`18`,class:`mr-1`},{default:E(()=>[...f[0]||=[e(`mdi-file-tree`,-1)]]),_:1}),f[1]||=e(` 目录 `,-1),v(M),v(o,{icon:`mdi-refresh`,size:`x-small`,variant:`text`,disabled:!S.serverId,onClick:q},null,8,[`disabled`])]),_:1})),v(b),v(l,{class:`file-dir-tree-body pa-0 flex-grow-1`},{default:E(()=>[S.serverId?B.value?(_(),h(w,{key:1,indeterminate:``})):(_(),h(D,{key:2,density:`compact`,nav:``,class:`py-0`},{default:E(()=>[(_(!0),g(n,null,C(W.value,n=>(_(),g(`div`,{key:n.path,class:`file-dir-tree-row d-flex align-center`,style:x({paddingLeft:`${8+n.depth*14}px`})},[a(`button`,{type:`button`,class:`file-dir-tree-toggle`,onClick:p(e=>J(n),[`stop`])},[V.value===n.path?(_(),h(i,{key:0,indeterminate:``,size:`14`,width:`2`})):(_(),h(m,{key:1,size:`16`},{default:E(()=>[e(c(H.value.has(n.path)?`mdi-chevron-down`:`mdi-chevron-right`),1)]),_:2},1024))],8,I),a(`button`,{type:`button`,class:t([`file-dir-tree-label text-body-2 text-truncate`,{"file-dir-tree-label--active":u(k)(S.currentPath)===n.path}]),onClick:e=>z(`navigate`,n.path),onContextmenu:p(e=>z(`paste-target`,n.path),[`prevent`])},[v(m,{size:`14`,class:`mr-1`},{default:E(()=>[...f[4]||=[e(`mdi-folder-outline`,-1)]]),_:1}),e(` `+c(n.name),1)],42,L)],4))),128))]),_:1})):(_(),g(`div`,F,`请先选择服务器`))]),_:1})]),_:1},8,[`class`]))}}),[[`__scopeId`,`data-v-0bdd7943`]]);export{R as default};