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