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