import _defineProperty from"@babel/runtime/helpers/defineProperty";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";var _excluded=["items","groups","disabled","getItemLabel","getItemKey","isLoading","getItemGroupKey","getGroupKey","getGroupLabel","onBlur","inputRef","onFocus","dropdownRef","dropdownClassName","dropdownForm","value","form","view","size","onChange","inputContainerRef","style","renderItem","searchFunction","id","name","className","virtualScroll","onScrollToBottom","onDropdownOpen","dropdownOpen","ignoreOutsideClicksRefs","rows","minRows","maxRows"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import React,{useCallback,useRef}from"react";import{SelectDropdown}from"../SelectComponents/SelectDropdown";import{SelectItem}from"../SelectComponents/SelectItem";import{defaultPropForm,defaultPropSize,defaultPropView}from"../SelectComponentsDeprecated/types";import{TextField}from"../TextField/TextField";import{useForkRef}from"../../hooks/useForkRef";import{useMutableRef}from"../../hooks/useMutableRef";import{cn}from"../../utils/bem";import{withDefaultGetters}from"./helpers";import{useAutoComplete}from"./useAutoComplete";var cnAutoComplete=cn("AutoComplete"),AutoCompleteRender=function(a,b){var c=useRef(null),d=useRef(null),e=useRef(null),f=withDefaultGetters(a),g=f.items,h=f.groups,i=void 0===h?[]:h,j=f.disabled,k=f.getItemLabel,l=f.getItemKey,m=f.isLoading,n=f.getItemGroupKey,o=f.getGroupKey,p=f.getGroupLabel,q=f.onBlur,r=f.inputRef,s=f.onFocus,t=f.dropdownRef,u=void 0===t?c:t,v=f.dropdownClassName,w=f.dropdownForm,x=void 0===w?"default":w,y=f.value,z=f.form,A=void 0===z?defaultPropForm:z,B=f.view,C=void 0===B?defaultPropView:B,D=f.size,E=void 0===D?defaultPropSize:D,F=f.onChange,G=f.inputContainerRef,H=f.style,I=f.renderItem,J=f.searchFunction,K=f.id,L=f.name,M=f.className,N=f.virtualScroll,O=f.onScrollToBottom,P=f.onDropdownOpen,Q=f.dropdownOpen,R=f.ignoreOutsideClicksRefs,S=f.rows,T=f.minRows,U=f.maxRows,V=_objectWithoutProperties(f,_excluded),W=useMutableRef(F),X=useCallback(function(a){var b,c=a.e,d=a.value,e=_objectSpread({},c),f=d?k(d):d;null===(b=W.current)||void 0===b?void 0:b.call(W,f,{e:e,id:null===K||void 0===K?void 0:K.toString(),name:L})},[K,L]),Y=useCallback(function(a,b){var c,d=b.id,f=b.name,g=b.e;null===(c=W.current)||void 0===c?void 0:c.call(W,a,{id:null===d||void 0===d?void 0:d.toString(),name:f,e:g})},[]),Z=useAutoComplete({items:g,groups:i,onChange:X,dropdownRef:u,controlRef:d,disabled:j,searchValue:null!==y&&void 0!==y?y:"",getItemLabel:k,getItemKey:l,getItemGroupKey:n,getGroupKey:o,onBlur:q,onFocus:s,searchFunction:J,isLoading:m,onDropdownOpen:P,dropdownOpen:Q,ignoreOutsideClicksRefs:R}),$=Z.getOptionProps,_=Z.isOpen,aa=Z.getKeyProps,ba=Z.visibleItems,ca=Z.handleInputFocus,da=Z.handleInputBlur,ea=Z.inputRef,fa=Z.optionsRefs;return React.createElement(React.Fragment,null,React.createElement(TextField,Object.assign({},aa(),{form:A,view:C,id:K,className:cnAutoComplete(null,[M]),name:L,disabled:j,ref:useForkRef([d,b]),inputRef:useForkRef([r,ea]),onBlur:da,inputContainerRef:useForkRef([e,G]),onClick:ca,onChange:Y,value:y,style:H,size:E,rows:S,minRows:T,maxRows:U},V)),React.createElement(SelectDropdown,{isOpen:_,size:E,controlRef:e,getOptionProps:$,dropdownRef:u,form:x,className:cnAutoComplete("List",[v]),renderItem:I||function renderItemDefault(a){var b=a.item,c=a.active,d=a.hovered,e=a.onClick,f=a.onMouseEnter,g=a.ref;return React.createElement(SelectItem,{label:k(b),active:c,hovered:d,multiple:!1,disabled:j,size:E,indent:"round"===x?"increased":"normal",onClick:e,onMouseEnter:f,ref:g})},getGroupLabel:p,visibleItems:ba,isLoading:m,hasItems:0!==g.length,itemsRefs:fa,virtualScroll:!0,style:"number"==typeof(null===H||void 0===H?void 0:H.zIndex)?{zIndex:H.zIndex+1}:void 0,onScrollToBottom:O}))};export var AutoComplete=React.forwardRef(AutoCompleteRender);export*from"./types";
//# sourceMappingURL=AutoComplete.js.map