import{someType as e}from"../_util/type.mjs";import t from"../_util/classNames.mjs";import n from"../_util/props-util/initDefaultProps.mjs";import{filterEmpty as r}from"../_util/props-util/index.mjs";import i from"../config-provider/hooks/useConfigInject.mjs";import{conductExpandParent as a}from"../vc-tree/util.mjs";import{convertDataToEntities as o,convertTreeToData as s,fillFieldNames as c}from"../vc-tree/utils/treeUtil.mjs";import l,{treeProps as u}from"./Tree.mjs";import{calcRangeKeys as d,convertDirectoryKeysToNodes as f}from"./utils/dictUtil.mjs";import{computed as p,createVNode as m,defineComponent as h,nextTick as g,onUpdated as _,ref as v,watch as y}from"vue";import{FileOutlined as b,FolderOpenOutlined as x,FolderOutlined as S}from"@antsoo-lib/icons";import C from"lodash-es/debounce";var w=()=>({...u(),expandAction:e([Boolean,String])});function T(e){let{isLeaf:t,expanded:n}=e;return m(t?b:n?x:S,null,null)}var E=h({compatConfig:{MODE:3},name:`ADirectoryTree`,inheritAttrs:!1,props:n(w(),{showIcon:!0,expandAction:`click`}),slots:Object,setup(e,{attrs:n,slots:u,emit:h,expose:b}){let x=v(e.treeData||s(r(u.default?.())));y(()=>e.treeData,()=>{x.value=e.treeData}),_(()=>{g(()=>{e.treeData===void 0&&u.default&&(x.value=s(r(u.default?.())))})});let S=v(),w=v(),E=p(()=>c(e.fieldNames)),D=v();b({scrollTo:e=>{D.value?.scrollTo(e)},selectedKeys:p(()=>D.value?.selectedKeys),checkedKeys:p(()=>D.value?.checkedKeys),halfCheckedKeys:p(()=>D.value?.halfCheckedKeys),loadedKeys:p(()=>D.value?.loadedKeys),loadingKeys:p(()=>D.value?.loadingKeys),expandedKeys:p(()=>D.value?.expandedKeys)});let O=()=>{let{keyEntities:t}=o(x.value,{fieldNames:E.value}),n;return n=e.defaultExpandAll?Object.keys(t):e.defaultExpandParent?a(e.expandedKeys||e.defaultExpandedKeys||[],t):e.expandedKeys||e.defaultExpandedKeys,n},k=v(e.selectedKeys||e.defaultSelectedKeys||[]),A=v(O());y(()=>e.selectedKeys,()=>{e.selectedKeys!==void 0&&(k.value=e.selectedKeys)},{immediate:!0}),y(()=>e.expandedKeys,()=>{e.expandedKeys!==void 0&&(A.value=e.expandedKeys)},{immediate:!0});let j=C((e,t)=>{let{isLeaf:n}=t;n||e.shiftKey||e.metaKey||e.ctrlKey||D.value.onNodeExpand(e,t)},200,{leading:!0}),M=(t,n)=>{e.expandedKeys===void 0&&(A.value=t),h(`update:expandedKeys`,t),h(`expand`,t,n)},N=(t,n)=>{let{expandAction:r}=e;r===`click`&&j(t,n),h(`click`,t,n)},P=(t,n)=>{let{expandAction:r}=e;(r===`dblclick`||r===`doubleclick`)&&j(t,n),h(`doubleclick`,t,n),h(`dblclick`,t,n)},F=(t,n)=>{let{multiple:r}=e,{node:i,nativeEvent:a}=n,o=i[E.value.key],s={...n,selected:!0},c=a?.ctrlKey||a?.metaKey,l=a?.shiftKey,u;r&&c?(u=t,S.value=o,w.value=u,s.selectedNodes=f(x.value,u,E.value)):r&&l?(u=Array.from(new Set([...w.value||[],...d({treeData:x.value,expandedKeys:A.value,startKey:o,endKey:S.value,fieldNames:E.value})])),s.selectedNodes=f(x.value,u,E.value)):(u=[o],S.value=o,w.value=u,s.selectedNodes=f(x.value,u,E.value)),h(`update:selectedKeys`,u),h(`select`,u,s),e.selectedKeys===void 0&&(k.value=u)},I=(e,t)=>{h(`update:checkedKeys`,e),h(`check`,e,t)},{prefixCls:L,direction:R}=i(`tree`,e);return()=>{let r=t(`${L.value}-directory`,{[`${L.value}-directory-rtl`]:R.value===`rtl`},n.class),{icon:i=u.icon,blockNode:a=!0,...o}=e;return m(l,{...n,icon:i||T,ref:D,blockNode:a,...o,prefixCls:L.value,class:r,expandedKeys:A.value,selectedKeys:k.value,onSelect:F,onClick:N,onDblclick:P,onExpand:M,onCheck:I},u)}}});export{E as default,w as directoryTreeProps};