import{__rest as o,__assign as e,__spreadArray as n}from'./../../ext-esm/tslib/tslib.es6.js';import{jsx as t}from"react/jsx-runtime";import{useMemo as r,useState as i,useEffect as l}from"react";import a from"classnames";import{get as p,noop as u}from"lodash";import{makeStyles as c}from"@material-ui/core";import s from"@material-ui/lab/Autocomplete";import f from"@material-ui/icons/Close";import{Tooltip as m}from"../Tooltip/Tooltip.js";import"../Tooltip/ScrollableTooltip.js";var d=function(o){return p(p(o.split('Create "'),"1","").split('"'),"0","")},h=c((function(o){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:o.palette.primary.main},openIcon:{marginLeft:5},option:{overflow:"hidden",whiteSpace:"nowrap",textOverflow:"ellipsis",width:"100%"},closeIcon:{width:16,height:16}}})),x=function(p){var c=p.isCreatable,x=p.options,g=p.value,v=p.getOptionLabel,b=p.onInputChange,C=p.onChange,I=void 0===C?u:C,w=p.renderOption,L=p.classes,O=o(p,["isCreatable","options","value","getOptionLabel","onInputChange","onChange","renderOption","classes"]),S=h(),j=r((function(){return null==x?void 0:x.map((function(o){return c?v(o):o}))}),[x]),T=r((function(){return c?v(g)||"":g}),[g]),H=i(j),N=H[0],y=H[1],z=i(null),A=z[0],_=z[1];l((function(){y(j)}),[j]);return t(s,e({value:T,onChange:c?function(o,e){return function(o){if((null==o?void 0:o.includes('Create "'))&&v(o)===v(A)){_(null);var e=d(A);y(n(n([],j,!0),[e],!1)),I(e,!0)}else I(o,!1)}(e)}:I,onInputChange:c?function(o,e){return function(o){if(""===o)_(null),y(j);else if(j.find((function(e){return e===o}))){var e=j.filter((function(o){return!o.includes('Create "')}));y(e)}else{var t=function(o){return'Create "'.concat(o,'"')}(o);_(t),y(n(n([],j,!0),[t],!1))}}(e)}:b,options:N,getOptionLabel:c?function(o){return String(o)}:v,renderOption:c?function(o){var n,r=d(o);return t(m,e({title:o},{children:t("div",e({className:a((n={},n[S.createLabel]=r&&o!==r,n),S.option,null==L?void 0:L.optionLabelClass)},{children:o}))}))}:w,classes:e({root:a(S.root,null==L?void 0:L.root),paper:a(S.paper,null==L?void 0:L.paper),popupIndicator:S.openIcon},L),closeIcon:(T||A)&&t(f,{className:S.closeIcon})},O))};export{x as default};
