import e from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/toConsumableArray";import t from"@babel/runtime/helpers/slicedToArray";import o from"@babel/runtime/helpers/objectWithoutProperties";import{jsx as n}from"react/jsx-runtime";import{useMemo as i,useState as p,useEffect as a}from"react";import l from"classnames";import{get as c,noop as u}from"lodash";import{makeStyles as s}from"@material-ui/core";import f from"@material-ui/lab/Autocomplete";import m from"@material-ui/icons/Close";import{Tooltip as b}from"../Tooltip/Tooltip.js";import"../Tooltip/ScrollableTooltip.js";var h=["isCreatable","options","value","getOptionLabel","onInputChange","onChange","renderOption","classes"];function d(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function g(r){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?d(Object(o),!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):d(Object(o)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}var O=function(e){return c(c(e.split('Create "'),"1","").split('"'),"0","")},v=s((function(e){return{root:{width:200},paper:{maxHeight:400,boxShadow:"0px 5px 5px -3px rgb(0 0 0 / 20%), 0px 8px 10px 1px rgb(0 0 0 / 14%), 0px 3px 14px 2px rgb(0 0 0 / 12%)",margin:0},createLabel:{fontSize:"16px",lineHeight:"22.5px",color:e.palette.primary.main},openIcon:{marginLeft:5},option:{overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",width:"100%"},closeIcon:{width:16,height:16}}})),x=function(c){var s=c.isCreatable,d=c.options,x=c.value,j=c.getOptionLabel,y=c.onInputChange,C=c.onChange,w=void 0===C?u:C,P=c.renderOption,I=c.classes,L=o(c,h),S=v(),T=i((function(){return null==d?void 0:d.map((function(e){return s?j(e):e}))}),[d]),D=i((function(){return s?x?j(x):"":x}),[x]),A=p(T),E=t(A,2),H=E[0],N=E[1],k=p(null),z=t(k,2),W=z[0],q=z[1];a((function(){N(T)}),[T]);return n(f,g({value:D,onChange:s?function(e,t){return function(e){if(null!=e&&e.includes('Create "')&&W&&j(e)===j(W)){q(null);var t=O(W);N([].concat(r(T),[t])),w(t,!0)}else w(e,!1)}(t)}:w,onInputChange:s?function(e,t){return function(e){if(""===e)q(null),N(T);else if(T.find((function(r){return r===e}))){var t=T.filter((function(e){return!e.includes('Create "')}));N(t)}else{var o=function(e){return'Create "'.concat(e,'"')}(e);q(o),N([].concat(r(T),[o]))}}(t)}:y,options:H,getOptionLabel:s?function(e){return String(e)}:j,renderOption:s?function(r){var t=O(r);return n(b,{title:r,children:n("div",{className:l(e({},S.createLabel,t&&r!==t),S.option,null==I?void 0:I.optionLabelClass),children:r})})}:P,classes:g({root:l(S.root,null==I?void 0:I.root),paper:l(S.paper,null==I?void 0:I.paper),popupIndicator:S.openIcon},I),closeIcon:(D||W)&&n(m,{className:S.closeIcon})},L))};export{x as default};
//# sourceMappingURL=Autocomplete.js.map
