import{r as e,j as n,M as l}from"./react-B_SyE9nW.js";import{o,br as t,n as r}from"./index-Flm6m8Wj.js";import{I as a}from"./ItemLoading-wir9MCjq.js";import{D as u}from"./DownIco-uXp5N5Ip.js";import{g as i}from"./styles-BKX5ijFq.js";import{L as s,A as d,c as p}from"./Autocomplete-BQWOUXOt.js";function c(n){const{data:l,index:o,style:t}=n;return e.cloneElement(l[o],{style:{...t,top:t.top}})}const v=e.createContext({}),m=e.forwardRef(((l,o)=>{const t=e.useContext(v);return n.jsx("div",{ref:o,...l,...t})}));m.displayName="OuterElementType";const f=e.forwardRef((function(o,t){const{children:r,...a}=o,u=e.Children.toArray(r),i=u.length,d=n=>e.isValidElement(n)&&n.type===s?48:36,p=function(n){const l=e.useRef(null);return e.useEffect((()=>{null!=l.current&&l.current.resetAfterIndex(0,!0)}),[n]),l}(i);return n.jsx("div",{ref:t,children:n.jsx(v.Provider,{value:a,children:n.jsx(l,{itemData:u,height:(i>8?288:u.map(d).reduce(((e,n)=>e+n),0))+2,width:"100%",ref:p,outerElementType:m,innerElementType:"ul",itemSize:e=>d(u[e]),overscanCount:5,itemCount:i,children:c})})})})),h=e=>[n.jsx(s,{component:"div",children:e.group},e.key),e.children];const b=o((function({fieldState:l,options:o,groupBy:s,renderOption:c,onChangeInput:v,label:m,required:b,disabled:x,popupIcon:g,hiddenLabel:C=!0,validateOnBlur:y=!1,startAdornment:j,endAdornment:I,disableClearable:O,hidePopupIndicator:P=!1,placeholder:E,listBoxComponent:L=f,filterOptions:T=p({matchFrom:"start"}),ignoreListBox:A=!1,clearOnSelect:B=!1,style:w={width:"100%"},noOptionsText:S=r("noOptions"),sx:F,open:q,onChange:R,onBlur:V,loading:D,onFocus:k,disablePortal:G,PopperComponent:K,onInputKeyPress:N,renderGroup:z=h,isOptionEqualToValue:M,readOnly:W,dataTest:X,...H}){const J=e.useRef(""),[Q,U]=e.useState(null);e.useEffect((()=>{if(!B)if(!(null==Q?void 0:Q.value)&&o.length||(null==Q?void 0:Q.value)!==(null==l?void 0:l.value)&&(null==l?void 0:l.value)){const e=o.find((({value:e})=>e===(null==l?void 0:l.value)))||{value:"",label:""};e.value&&U(e)}else(null==l?void 0:l.value)||U({value:"",label:""})}),[o.length,null==l?void 0:l.value]),e.useEffect((()=>()=>{U({value:"",label:""})}),[]);const Y=()=>{null==l||l.setError(""),null==l||l.validate(),null==V||V()};return n.jsx(d,{selectOnFocus:!1,loadingText:n.jsx(a,{}),id:null==l?void 0:l.id,className:P?"enj-hide-popup-indicator":"",disableListWrap:!0,onBlur:y?Y:V,ListboxComponent:A?void 0:L,autoComplete:!0,groupBy:s,options:o,renderOption:c,disabled:x,filterOptions:T,disableClearable:O,noOptionsText:S,open:q,disablePortal:G,PopperComponent:K,renderGroup:z,style:w,onFocus:k,value:Q,loading:D,sx:F,onInputChange:(e,n,o)=>{null==v||v("input"===o?n:"",o),"clear"===o&&(null==l||l.onChange(""),U({value:"",label:""}))},renderInput:e=>(j&&(e.InputProps.startAdornment=j),I&&(e.InputProps.endAdornment=I),W&&(e.inputProps.readOnly=W),n.jsx(t,{render:()=>n.jsx(i,{...e,...H,InputProps:{...e.InputProps,...H.InputProps,"data-test":X||""},value:e.inputProps.value||J.current,onChange:e=>{J.current=e.target.value},label:m,disabled:x,hiddenLabel:C,InputLabelProps:{shrink:!0,hidden:C},required:b&&!(null==l?void 0:l.value),helperText:(null==l?void 0:l.hasError)?null==l?void 0:l.error:"",error:null==l?void 0:l.hasError,onBlur:y?Y:void 0,placeholder:E,onKeyPress:N})})),popupIcon:g??n.jsx(u,{}),isOptionEqualToValue:M??((e,n)=>{const o=null==e?void 0:e.value,t=null==n?void 0:n.value,r=null==l?void 0:l.value;return o===t||o===r}),getOptionLabel:e=>(null==e?void 0:e.label)||"",onChange:(e,n)=>{const o=null==n?void 0:n.value;o&&(null==l||l.onChange(o),U(B?{value:"",label:""}:n||{})),null==R||R(String(o||""))},filterOptions:(e,n)=>e.filter((e=>e.label.trimStart().toLowerCase().includes(n.inputValue.trimStart().toLowerCase())))})}));export{b as F};