import{r as e}from"./rolldown-runtime-hePW80VL.js";import{n as t,t as n}from"./jsx-runtime-DE3RlOCf.js";import{t as r}from"./utils-kzSVkeKt.js";function i(e,t){let n=e=>e==null||typeof e==`string`||typeof e==`object`&&e?.id!==void 0;return t&&t in e&&n(e[t])?t:Object.keys(e).find(t=>(t===`parent`||t.startsWith(`parent_`))&&n(e[t]))??null}function a(e,t,n){if(!e.length)return[];let r=i(e[0],t),a=e=>e==null?null:typeof e==`object`?e.id??null:String(e),o=e.map(e=>({id:e.id,label:e.name||e.display||e.id,code:e.code||``,level:e.level??0,parentId:r?a(e[r]):null,isExpanded:n??!1,children:[],rawData:e})),s=new Map;o.forEach(e=>s.set(e.id,e));let c=[];o.forEach(e=>{if(e.parentId){let t=s.get(e.parentId);t?t.children.push(e):(e.isExpanded=!0,c.push(e))}else e.isExpanded=!0,c.push(e)});let l=e=>{e.children&&e.children.length>0&&(e.children.sort((e,t)=>e.code.localeCompare(t.code)),e.children.forEach(l))};return c.sort((e,t)=>e.code.localeCompare(t.code)),c.forEach(l),c}function o(e,t){return e.map(e=>e.id===t?{...e,isExpanded:!e.isExpanded}:e.children?{...e,children:o(e.children,t)}:e)}t();var s=e(n(),1),c=({node:e,level:t,onToggle:n,onSelect:i,selectedNodeId:a,countMap:o,selfRef:l,onViewLeaf:u,onKeyDown:d})=>{let f=e.children&&e.children.length>0||e.rawData?.is_group===!0,p=a===e.id,m=l&&!f,h=()=>{f&&n(e.id),m?u?.(e.rawData):i(e.id)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(`div`,{tabIndex:0,role:`treeitem`,"aria-expanded":f?e.isExpanded:void 0,"aria-selected":p,className:r(`relative flex items-center gap-1.5 py-[5px] cursor-pointer text-sm transition-colors select-none`,`hover:bg-primary/[0.05]`,`focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset rounded`,p?`bg-primary/[0.08] border-l-2 border-primary text-primary`:`border-l-2 border-transparent`,t===0&&!p&&`text-foreground`,t>0&&!p&&`text-foreground/80`),style:{paddingLeft:`${t*16+10}px`,paddingRight:`8px`},onKeyDown:d?t=>d(t,e):t=>{t.key===`Enter`?(t.preventDefault(),h()):(t.key===`ArrowRight`&&f&&!e.isExpanded||t.key===`ArrowLeft`&&f&&e.isExpanded)&&(t.preventDefault(),n(e.id))},onClick:h,children:[t>0&&(0,s.jsx)(`span`,{className:`absolute top-0 bottom-0 w-px bg-border/40`,style:{left:`${(t-1)*16+18}px`}}),f?(0,s.jsx)(`span`,{className:r(`shrink-0 flex items-center justify-center w-3.5 h-3.5 rounded-full border text-[9px] font-bold leading-none`,p?`border-primary text-primary`:`border-foreground/40 text-foreground/50`),onClick:t=>{t.stopPropagation(),f&&n(e.id),m||i(e.id)},children:e.isExpanded?`−`:`+`}):(0,s.jsx)(`span`,{className:r(`shrink-0 w-1.5 h-1.5 rounded-full`,p?`bg-primary`:`bg-foreground/30`)}),(0,s.jsx)(`span`,{className:r(`truncate text-xs leading-snug flex-1`,f&&!p&&`font-medium text-foreground/90`),children:e.label}),o&&(o[e.id]??0)>0&&(0,s.jsx)(`span`,{className:`shrink-0 text-[9px] font-medium px-1.5 py-0.5 rounded-full bg-muted text-muted-foreground tabular-nums leading-none`,children:o[e.id]})]}),e.isExpanded&&e.children?.map(e=>(0,s.jsx)(c,{node:e,level:t+1,onToggle:n,onSelect:i,selectedNodeId:a,countMap:o,selfRef:l,onViewLeaf:u,onKeyDown:d},e.id))]})};export{a as n,o as r,c as t};