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