import e from"@babel/runtime/helpers/slicedToArray";import{useState as t,useRef as o}from"react";import r from"prop-types";import i from"lodash/get";import{withStyles as n,Tooltip as l,makeStyles as a,Chip as c,Input as p}from"@material-ui/core";import s from"@material-ui/icons/Close";import u from"./AssetTypesSection.js";import d from"./AssetResultSection.js";import{useAssetsData as f}from"./effects/useAssetsData.js";import{SEARCH_CATEGORIES as m,CATEGORY_KEY_VALUES as h}from"./constants.js";import{jsxs as x,jsx as g}from"react/jsx-runtime";var y=n((function(){return{tooltip:{backgroundColor:"#414141",color:"#ffffff",fontSize:"11px",lineHeight:"16px",borderRadius:"4px",boxShadow:"0px 4px 4px rgba(0, 0, 0, 0.12)",padding:"4px"}}}))(l),C=a((function(e){return{wrapper:{width:"472px",display:"flex",flexDirection:"column",padding:16},inputWrapper:{display:"flex",width:"auto",margin:"0 8px 8px",alignItems:"center",flexWrap:"nowrap",justifyContent:"space-between"},selectedChip:{height:"24px",margin:"4px"},selectedChipDeleteIcon:{width:"16px",height:"16px",color:e.palette.primary.text6,"&:hover":{color:e.palette.primary.text1}},disabledIcon:{width:"16px",height:"16px",color:e.palette.primary.text6,opacity:.4},closeIconButton:{padding:0,"&:hover $closeIcon":{color:e.palette.primary.text1}},searchInput:{width:"100%",display:"flex",flexDirection:"row",justifyContent:"space-between",alignItems:"center",borderBottom:"2px solid #03BCD4"},closeIcon:{color:e.palette.primary.text6,fontSize:"18px"}}})),b=function(r){var n=r.onClickAsset,l=r.company,a=t(null),b=e(a,2),I=b[0],v=b[1],w=t(null),A=e(w,2),D=A[0],S=A[1],j=t(1),k=e(j,2),R=k[0],N=k[1],T=C(),W=o(),z=f(D,I,R,l),B=e(z,2),q=B[0],K=B[1];return x("div",{className:T.wrapper,children:[g("div",{className:T.inputWrapper,children:x("div",{className:T.searchInput,children:[I&&g(c,{"data-not-migrated-muichip":!0,classes:{root:T.selectedChip,deleteIcon:T.selectedChipDeleteIcon},label:i(m,[I,"labelPlural"],"Assets"),deleteIcon:g(s,{}),onDelete:function(){v(null),N(1)}}),g(p,{"data-testid":"".concat("AutoCompleteAssetSearch","_searchInput"),inputRef:W,autoFocus:!0,disableUnderline:!0,fullWidth:!0,value:D||"",placeholder:"Search ".concat(i(m,[I,"labelPlural"],"assets"),"..."),onChange:function(e){var t=e.target.value;S(t),N(1)},onKeyUp:function(t){var o=t.target.value,r=t.keyCode,i=h.find((function(t){var r=e(t,2);return r[0],r[1].autoCategorizedKey===o.trim().toLowerCase()}));if(i&&(13===r||32===r))return S(""),v(i[0]),void N(1);""===o&&8===r&&(v(null),N(1))}}),g(y,{title:"Clear",children:g(s,{className:I||D?T.selectedChipDeleteIcon:T.disabledIcon,onClick:function(){W.current.focus(),S(""),v(null),N(1)}})})]})}),!I&&!D&&g(u,{onClickAssetType:function(e){W.current.focus(),v(e),N(1)}}),(I||D)&&g(d,{loading:q,page:R,groupedAssets:K,onClickAsset:n,onScrollReached:function(e){"top"===e&&R>1&&N((function(e){return e-1})),"bottom"===e&&N((function(e){return e+1}))}})]})};b.propTypes={company:r.number.isRequired,onClickAsset:r.func.isRequired};export{b as default};
//# sourceMappingURL=AutoCompleteAssetSearch.js.map
