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