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