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{useMemo as n,useState as i,useEffect as p}from"react";import a from"prop-types";import l from"classnames";import{noop as c,identity as u,get as s}from"lodash";import{makeStyles as f}from"@material-ui/core";import m from"@material-ui/lab/Autocomplete";import b from"@material-ui/icons/Close";import{Tooltip as h}from"../Tooltip/Tooltip.js";import"../Tooltip/ScrollableTooltip.js";import{jsx as d}from"react/jsx-runtime";var g=["isCreatable","options","value","getOptionLabel","onInputChange","onChange","renderOption","classes"];function O(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 v(r){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?O(Object(o),!0).forEach((function(t){e(r,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):O(Object(o)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))}))}return r}var C=function(e){return s(s(e.split('Create "'),"1","").split('"'),"0","")},x=f((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}}})),y=function(a){var c=a.isCreatable,u=a.options,s=a.value,f=a.getOptionLabel,O=a.onInputChange,y=a.onChange,j=a.renderOption,w=a.classes,I=o(a,g),P=x(),L=n((function(){return null==u?void 0:u.map((function(e){return c?f(e):e}))}),[u]),T=n((function(){return c?f(s)||"":s}),[s]),S=i(L),D=t(S,2),A=D[0],q=D[1],E=i(null),H=t(E,2),N=H[0],R=H[1];p((function(){q(L)}),[L]);return d(m,v({value:T,onChange:c?function(e,t){return function(e){if(null!=e&&e.includes('Create "')&&f(e)===f(N)){R(null);var t=C(N);q([].concat(r(L),[t])),y(t,!0)}else y(e,!1)}(t)}:y,onInputChange:c?function(e,t){return function(e){if(""===e)R(null),q(L);else if(L.find((function(r){return r===e}))){var t=L.filter((function(e){return!e.includes('Create "')}));q(t)}else{var o=function(e){return'Create "'.concat(e,'"')}(e);R(o),q([].concat(r(L),[o]))}}(t)}:O,options:A,getOptionLabel:c?function(e){return e}:f,renderOption:c?function(r){var t=C(r);return d(h,{title:r,children:d("div",{className:l(e({},P.createLabel,t&&r!==t),P.option,null==w?void 0:w.optionLabelClass),children:r})})}:j,classes:v({root:l(P.root,null==w?void 0:w.root),paper:l(P.paper,null==w?void 0:w.paper),popupIndicator:P.openIcon},w),closeIcon:(T||N)&&d(b,{className:P.closeIcon})},I))};y.propTypes={value:a.oneOfType([a.string,a.shape({})]).isRequired,options:a.shape([]).isRequired,isCreatable:a.bool,getOptionLabel:a.func,onChange:a.func,onInputChange:a.func,renderOption:a.func,classes:a.shape()},y.defaultProps={isCreatable:!1,onChange:c,getOptionLabel:u,onInputChange:c,renderOption:u,classes:{}};export{y as default};
