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