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