import{Input as e,Tree as n}from"antd";import{useState as t,useEffect as s}from"react";import{getTreeNodePaths as r}from"../../../utils/index.js";import{jsxs as d,jsx as o}from"react/jsx-runtime";const{Search:a}=e,i=e=>{const{onGetData:i,onSelect:c,onGetNodePaths:l,onGetNodePathsIsIncludeOneself:h,getNodePathsIsIncludeOneself:u=!0,expandedKeys:f,treeData:m=[],nameKey:p="name",idKey:y="id",childrenKey:g="children",...I}=e;void 0!==h&&console.warn("【BasicLeftTree】 onGetNodePathsIsIncludeOneself 参数已弃用，请使用 getNodePathsIsIncludeOneself 参数");const x=void 0!==h?h:u,[K,N]=t([]),[v,O]=t(""),[P,G]=t(!0);s(()=>{N(f)},[f]);const S=(e,n,t=[])=>(e.forEach(e=>{e[g]&&((e[p].includes(n)||e[g].some(e=>e[p].includes(n)))&&t.push(e[y]),S(e[g],n,t))}),t),B=(e,n)=>n?e.reduce((e,t)=>{const s=t[p].includes(n),r=t[g]?B(t[g],n):[];return(s||r.length>0)&&e.push({...t,[g]:r.length>0?r:void 0}),e},[]):e,D=e=>{if(!v)return e;const n=e.indexOf(v);if(-1===n)return e;const t=e.substring(0,n),s=e.substring(n+v.length);return d("span",{children:[t,o("span",{style:{color:"#f50"},children:v}),s]})},E=e=>e.map(e=>({...e,[p]:D(e[p]),[g]:e[g]?E(e[g]):void 0})),b=B(m,v),j=E(b);return s(()=>{i?.(m)},[m]),d("div",{style:{width:300},children:[o(a,{style:{marginBottom:8},placeholder:"输入关键字进行过滤",onSearch:async e=>{e!==v&&(e=>{if(O(e),G(!0),!e)return void N([]);const n=S(m,e);N(n)})(e)}}),o(n,{onExpand:e=>{N(e),G(!1)},onSelect:(e,n)=>{if(e.length>0&&l){const n=e[0],t=r({data:m,targetId:n,idKey:y,childrenKey:g,isIncludeOneself:x});l?.(t)}c?.(e,n)},autoExpandParent:P,expandedKeys:K,treeData:j,fieldNames:{title:p,key:y,children:g},...I})]})};i.displayName="BasicLeftTree";export{i as default};
