import e from"@babel/runtime/helpers/defineProperty";import r from"@babel/runtime/helpers/slicedToArray";import{memo as t,useState as i,useRef as o,useMemo as n,useCallback as a,useEffect as s}from"react";import p from"classnames";import l from"prop-types";import{makeStyles as c,Tooltip as d}from"@material-ui/core";import u from"./AutoCompleteDialog.js";import{isMobileDetected as m}from"../../../../../utils/mobileDetect.js";import{getUnitDisplay as f}from"../../../../../utils/index.js";import{jsxs as g,jsx as b}from"react/jsx-runtime";function h(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);r&&(i=i.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,i)}return t}function x(r){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?h(Object(i),!0).forEach((function(t){e(r,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(i)):h(Object(i)).forEach((function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(i,e))}))}return r}var y=c((function(e){return{suggestions:{width:"100%",marginBottom:"16px",marginLeft:function(e){return e.isMobile?"8px":0}},tagsContainer:{width:"100%",position:"relative"},tags:{width:"100%",overflowX:"auto",display:"flex",paddingBottom:function(e){return e.isMobile?"8px":"5px"},"&::-webkit-scrollbar":{height:"6px"},"&::-webkit-scrollbar-thumb":{backgroundColor:"rgba(20, 20, 20, 0.8)",borderRadius:"10px",border:"1px solid rgba(28, 28, 28, 0.01)",backgroundClip:"padding-box",boxShadow:"0px 2px 2px rgba(0, 0, 0, 0.25)"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"}},tagWrapper:{marginRight:"10px"},tag:{maxWidth:"150px",padding:"3.5px 10px 3.5px",fontSize:"13px",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",color:e.palette.primary.text6,border:"1px solid #616161",borderRadius:"40px",cursor:"pointer","&:hover":{color:e.palette.primary.main,border:"1px solid ".concat(e.palette.primary.main)}},tooltip:{background:"rgba(59,59,59,0.9)",borderRadius:"4px",padding:"8px"},cta:{marginTop:"2px",color:e.palette.primary.main,fontSize:"14px",fontWeight:400,letterSpacing:"0.15px",lineHeight:"19px",cursor:"pointer","&:hover":{textDecoration:"underline"}},shadow:{width:"24px",height:"100%",position:"absolute",zIndex:2,top:0},leftShadow:{left:0,background:"linear-gradient(-90deg, rgba(39, 39, 39, 0) 0%, ".concat(e.palette.background.b5," 100%)")},rightShadow:{right:0,background:"linear-gradient(90deg, rgba(39, 39, 39, 0) 0%, ".concat(e.palette.background.b5," 100%)")},tooltipContainer:{background:e.palette.background.b8,opacity:.9,fontSize:"14px",display:"flex",flexDirection:"column",gap:"4px"},tooltipLine:{height:"20px",display:"flex",alignItems:"center"},tooltipUnit:{fontSize:"12px",color:e.palette.primary.text6}}})),v=function(e){var r=e.descriptionKeys,t=e.columnMaps,i=e.dataItem,o=y();return b("div",{className:o.tooltipContainer,children:r.map((function(e){return g("div",{className:o.tooltipLine,children:[g("span",{children:[t[e].label,": "]}),b("span",{children:i[e]||"-"}),t[e].unitType&&g("span",{className:o.tooltipUnit,children:[" ",f(t[e].unitType)]})]},e)}))})};function w(t){var l=t.data,c=t.allData,f=t.columns,h=t.displayKeys,w=t.descriptionKeys,O=t.onSelect,k=t.isCasing,S=i(!1),j=r(S,2),C=j[0],R=j[1],N=y({isMobile:m}),D=i(!1),P=r(D,2),q=P[0],K=P[1],M=o(),z=n((function(){return f.reduce((function(r,t){return x(x({},r),{},e({},t.key,t))}),{})}),[f]),T=a((function(){if(M.current){var e=M.current.scrollLeft;K(!!e)}}),[]);s((function(){var e=new ResizeObserver(T);return M.current&&e.observe(M.current),function(){e.disconnect()}}),[]);var I=function(e){return k?h.map((function(r){return"".concat(e[r],'"')})).join("/"):h.map((function(r){return e[r]})).join(" ")};return g("div",{className:N.suggestions,children:[g("div",{className:N.tagsContainer,children:[b("div",{className:N.tags,ref:M,onScroll:T,children:l.map((function(e,r){return b("div",{className:N.tagWrapper,children:b(d,{classes:{tooltip:N.tooltip},title:b(v,{descriptionKeys:w,columnMaps:z,dataItem:e}),children:b("div",{className:N.tag,onClick:function(){return O(e)},children:I(e)})})},r)}))}),q&&b("div",{className:p(N.shadow,N.leftShadow)}),b("div",{className:p(N.shadow,N.rightShadow)})]}),b("div",{className:N.cta,onClick:function(){R(!0)},children:"Show all AutoComplete results"}),C&&b(u,{data:c,columns:f,onClose:function(){R(!1)},onSelect:function(e){R(!1),O(e)},isMobile:m})]})}v.propTypes={descriptionKeys:l.arrayOf(l.string).isRequired,columnMaps:l.shape({}).isRequired,dataItem:l.shape({}).isRequired},w.propTypes={data:l.arrayOf(l.shape({})).isRequired,allData:l.arrayOf(l.shape({})).isRequired,columns:l.arrayOf(l.shape({})).isRequired,displayKeys:l.arrayOf(l.string).isRequired,descriptionKeys:l.arrayOf(l.string).isRequired,onSelect:l.func.isRequired,isCasing:l.bool},w.defaultProps={isCasing:!1};var O=t(w);export{O as default};
