import{r,j as u}from"./iframe-p4aYZyoq.js";import{c as V}from"./index-Dx18ixSn.js";import{S as O}from"./substring-highlight-D19--ls-.js";import{S as B}from"./search-input-P8XqbDB1.js";import{g as A,p as H,b as M}from"./utils-pBtDpbI-.js";/* empty css                 */const w=({item:e,active:s,substringToHighlight:a,handleOnClick:l})=>{const o=r.useRef(null);return r.useEffect(()=>{s&&o.current&&o.current.scrollIntoView({block:"nearest",inline:"nearest"})}),u.jsx("li",{ref:o,"data-testid":"autocomplete-item",children:u.jsx("button",{type:"button",onClick:c=>l(e,c),className:s?"hover":"",children:a?u.jsx(O,{substring:a,children:e.pathLabel}):e.itemLabel})})};try{autocompleteitem.displayName="autocompleteitem",autocompleteitem.__docgenInfo={description:"",displayName:"autocompleteitem",props:{item:{defaultValue:null,description:"",name:"item",required:!0,type:{name:"AutocompleteItemType"}},active:{defaultValue:null,description:"",name:"active",required:!0,type:{name:"boolean"}},substringToHighlight:{defaultValue:null,description:"",name:"substringToHighlight",required:!0,type:{name:"string"}},handleOnClick:{defaultValue:null,description:"",name:"handleOnClick",required:!0,type:{name:"(item: string | AutocompleteItemType, e: MouseEvent<HTMLButtonElement, MouseEvent>) => void"}}}}}catch{}const y=(e,s)=>e.filter(a=>{var l;return A(a.pathLabel,s)>=0||((l=a.tags)==null?void 0:l.some(o=>A(o,s)>=0))}),S=(e,s,a,l,o)=>{const c=e.trim();let n=!1;return c&&!a&&c.length>=o&&(n=(l?y(s,c):s).length>0),n},Q=({data:e,onSelect:s,onChange:a,onDropdownChange:l,clearOnSelect:o=!1,placeholder:c="",filter:n=!0,value:f="",minCharsToShowDropdown:_=0,isLoading:q=!1,autoFocus:k=!1,className:j,...E})=>{const[m,h]=r.useState(f),[p,d]=r.useState(-1),[N,I]=r.useState(!1);r.useEffect(()=>{h(f)},[f]),r.useEffect(()=>()=>{l==null||l(!1)},[l]);const T=r.useCallback(t=>{const{value:i}=t.target,v=S(i,e,!1,n,_);l==null||l(v),h(i),I(!1),a==null||a(i),v&&d(0)},[e,n,_,a,l]),b=r.useCallback(t=>{const i=typeof t=="string"?t:t==null?void 0:t.pathLabel;h(o?"":i),d(-1),I(!0),l==null||l(!1),s(t)},[o,s,l]),L=r.useCallback(t=>{if(t.key==="ArrowUp")t.preventDefault(),d(p<=0?-1:p-1);else if(t.key==="ArrowDown"){t.preventDefault();const i=n?y(e,m):e;d(Math.min(i.length-1,p+1))}else if(t.key==="Escape")t.preventDefault(),d(-1),I(!0);else if(t.key==="Enter")if(t.preventDefault(),p>=0){const i=n?y(e,m):e;b(i[p])}else b(m)},[e,n,b,p,m]),x=S(m,e,N,n,_);let g=[];return x&&(g=(n?y(e,m):e).map((t,i)=>u.jsx(w,{item:t,active:p===i,substringToHighlight:m,handleOnClick:b},t.id))),u.jsxs("div",{className:V("autocomplete-container",j),...E,children:[u.jsx(B,{value:m,onChange:T,onKeyDown:L,placeholder:c,isLoading:q,autoFocus:k}),u.jsx("div",{className:V("autocomplete-menu",{"dropdown-menu-open":x}),children:u.jsx("div",{className:"dropdown-menu__panel",children:g.length?u.jsx("ul",{children:g}):null})})]})};try{autocomplete.displayName="autocomplete",autocomplete.__docgenInfo={description:"",displayName:"autocomplete",props:{data:{defaultValue:null,description:"",name:"data",required:!0,type:{name:"AutocompleteItemType[]"}},onSelect:{defaultValue:null,description:"",name:"onSelect",required:!0,type:{name:"(selected: string | AutocompleteItemType) => void"}},onChange:{defaultValue:null,description:"",name:"onChange",required:!1,type:{name:"((textInput: string) => void)"}},onDropdownChange:{defaultValue:null,description:"",name:"onDropdownChange",required:!1,type:{name:"((dropdownShown: boolean) => void)"}},clearOnSelect:{defaultValue:{value:"false"},description:"",name:"clearOnSelect",required:!1,type:{name:"boolean"}},placeholder:{defaultValue:{value:""},description:"",name:"placeholder",required:!1,type:{name:"string"}},filter:{defaultValue:{value:"true"},description:"",name:"filter",required:!1,type:{name:"boolean"}},value:{defaultValue:{value:""},description:"",name:"value",required:!1,type:{name:"string"}},minCharsToShowDropdown:{defaultValue:{value:"0"},description:"",name:"minCharsToShowDropdown",required:!1,type:{name:"number"}},isLoading:{defaultValue:{value:"false"},description:"",name:"isLoading",required:!1,type:{name:"boolean"}}}}}catch{}const P=[{label:"Item 1",id:"item_1",items:[{label:"Item 1a",id:"item_1a"},{label:"Item 1b",id:"item_1b",items:[{label:"Item 1b A",id:"item_1b_A"},{label:"Item 1b B",id:"item_1b_B"}],tags:["tag2","tag3"]}]},{label:"Some Item 2",id:"item_2"},{label:"Another reaaaaalllllyyyyy looooooong Item 3",id:"item_3",items:[{label:"Item 3a (single child, open by default)",id:"item_3a",items:[{label:"Item 3a A",id:"item_3a_A"},{label:"Item 3a B",id:"item_3a_B"}]}]}],K=M(P),W=H(K);export{Q as A,W as f,P as t};
