"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),t=require("react"),i=require("prop-types"),r=require("lodash/get"),o=require("@material-ui/core"),l=require("@material-ui/icons/Close"),a=require("./AssetTypesSection.js"),n=require("./AssetResultSection.js"),s=require("./effects/useAssetsData.js"),u=require("./constants.js"),c=require("react/jsx-runtime");function p(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=p(e),f=p(i),x=p(r),h=p(l),m=o.withStyles((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"}}}))(o.Tooltip),b=o.makeStyles((function(e){return{wrapper:{width:function(e){var t=e.isTablet,i=e.isMobile;return!t&&i?"100%":"472px"},height:function(e){var t=e.isTablet,i=e.isMobile;return!t&&i&&"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"}}})),y=function(e){var i=e.onClickAsset,r=e.company,l=e.isTablet,p=e.isMobile,f=t.useState(null),y=d.default(f,2),C=y[0],g=y[1],A=t.useState(null),I=d.default(A,2),S=I[0],j=I[1],v=t.useState(1),q=d.default(v,2),w=q[0],R=q[1],T=b({isTablet:l,isMobile:p}),E=t.useRef(),k=s.useAssetsData(S,C,w,r),D=d.default(k,2),M=D[0],B=D[1];return c.jsxs("div",{className:T.wrapper,children:[c.jsx("div",{className:T.inputWrapper,children:c.jsxs("div",{className:T.searchInput,children:[c.jsx(o.Input,{"data-testid":"".concat("AutoCompleteAssetSearch","_searchInput"),inputRef:E,autoFocus:!0,disableUnderline:!0,fullWidth:!0,value:S||"",placeholder:"Search ".concat(x.default(u.SEARCH_CATEGORIES,[C,"labelPlural"],"assets"),"..."),onChange:function(e){var t=e.target.value;j(t),R(1)},onKeyUp:function(e){var t=e.target.value,i=e.keyCode,r=u.CATEGORY_KEY_VALUES.find((function(e){var i=d.default(e,2);return i[0],i[1].autoCategorizedKey===t.trim().toLowerCase()}));if(r&&(13===i||32===i))return j(""),g(r[0]),void R(1);""===t&&8===i&&(g(null),R(1))}}),c.jsx(m,{title:"Clear",children:c.jsx(h.default,{className:C||S?T.selectedChipDeleteIcon:T.disabledIcon,onClick:function(){E.current.focus(),j(""),g(null),R(1)}})})]})}),C&&c.jsx(o.Chip,{"data-not-migrated-muichip":!0,classes:{root:T.selectedChip,deleteIcon:T.deleteIcon},color:"primary",label:x.default(u.SEARCH_CATEGORIES,[C,"labelPlural"],"Assets"),deleteIcon:c.jsx(h.default,{}),onDelete:function(){g(null),R(1)}}),!C&&!S&&c.jsx(a,{onClickAssetType:function(e){E.current.focus(),g(e),R(1)}}),(C||S)&&c.jsx(n,{loading:M,page:w,groupedAssets:B,onClickAsset:i,onScrollReached:function(e){"top"===e&&w>1&&R((function(e){return e-1})),"bottom"===e&&R((function(e){return e+1}))},isTablet:l,isMobile:p})]})};y.propTypes={company:f.default.number.isRequired,onClickAsset:f.default.func.isRequired,isTablet:f.default.bool.isRequired,isMobile:f.default.bool.isRequired},module.exports=y;
//# sourceMappingURL=AutoCompleteAssetSearch.js.map
