import e from"@babel/runtime/helpers/slicedToArray";import{useState as t,useMemo as r,useRef as n,useEffect as o}from"react";import i from"prop-types";import{get as s}from"lodash";import{withStyles as a,Tooltip as l,makeStyles as p,Chip as c,Input as u}from"@material-ui/core";import d from"@material-ui/icons/Close";import"@babel/runtime/helpers/asyncToGenerator";import"@babel/runtime/regenerator";import"../../../utils/apiCalls.js";import"../../../effects/useAdvancedWells.js";import"@babel/runtime/helpers/toConsumableArray";import"@babel/runtime/helpers/defineProperty";import"../../../constants.js";import"../../../../../utils/index.js";import"../../../../../constants/goals.js";import"../../../../../constants/segment.js";import"../../../../../constants/alerts.js";import"../../../../../constants/apps.js";import"../../../../../constants/drillstring.js";import"../../../../../constants/completion.js";import"../../../../../constants/appPackages.js";import"../../../../../constants/notifications.js";import"../../../../../constants/feed.js";import"../../../../../constants/bha.js";import"../../../../../utils/env.js";import"../../../../GradientManager/configuration/constants.js";import"@babel/runtime/helpers/typeof";import"moment";import"react-virtualized";import{useAssetsData as m}from"../../../effects/useAssetsData.js";import f from"./AssetTypesSection.js";import h from"./AssetResultSection.js";import{SEARCH_CATEGORIES as x,CATEGORY_KEY_VALUES as g}from"./constants.js";import{jsxs as b,jsx as y,Fragment as j}from"react/jsx-runtime";var C=a((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),I=p((function(e){return{wrapper:{width:function(e){return e.searchWidth},maxWidth:"996px",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}},selectedLabel:{fontWeight:400,fontSize:"16px",lineHeight:"22px",color:e.palette.primary.text1,whiteSpace:"nowrap",paddingLeft:"4px",paddingRight:"8px"},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"}}})),v=function(i){var a=i.company,l=i.subjectWellId,p=i.value,v=i.selectedWellIds,w=i.onChange,A=t(null),W=e(A,2),R=W[0],S=W[1],k=t(null),D=e(k,2),T=D[0],q=D[1],z=t(1),N=e(z,2),L=N[0],B=N[1],P=r((function(){return window.innerWidth-32}),[]),G=I({searchWidth:P}),H=n();o((function(){q(p)}),[p]);var K=m(T,R,L,a,v),O=e(K,2),U=O[0],F=O[1],M=r((function(){return R&&F&&0!==F.length?F[0][1].filter((function(e){return e.checked})).length:0}),[R,F]);return b("div",{className:G.wrapper,children:[y("div",{className:G.inputWrapper,children:b("div",{className:G.searchInput,children:[R&&b(j,{children:[y(c,{"data-not-migrated-muichip":!0,classes:{root:G.selectedChip,deleteIcon:G.selectedChipDeleteIcon},label:s(x,[R,"labelPlural"],"Assets"),deleteIcon:y(d,{}),onDelete:function(){S(null)}}),M>0&&b("span",{className:G.selectedLabel,children:[M," Selected"]})]}),y(u,{"data-testid":"".concat("AutoCompleteAssetSearch","_searchInput"),inputRef:H,autoFocus:!0,disableUnderline:!0,fullWidth:!0,value:T||"",placeholder:"Add Offset ...",onChange:function(e){var t=e.target.value;H.current.focus(),q(t),B(1)},onKeyUp:function(t){var r=t.target.value,n=t.keyCode,o=g.find((function(t){var n=e(t,2);return n[0],n[1].autoCategorizedKey===r.trim().toLowerCase()}));if(o&&(13===n||32===n))return q(""),S(o[0]),void B(1);""===r&&8===n&&(S(null),B(1))}}),y(C,{title:"Clear",children:y(d,{className:R||T?G.selectedChipDeleteIcon:G.disabledIcon,onClick:function(){H.current.focus(),q(""),S(null),B(1)}})})]})}),!R&&!T&&y(f,{onClickAssetType:function(e){H.current.focus(),S(e),B(1)}}),(R||T)&&y(h,{subjectWellId:l,page:L,assetType:R,loading:U,groupedAssets:F,onClickAsset:function(e,t){w(!e.checked,[e.redirectAssetId],t)},onClickAllAsset:function(e,t){var r=F[0][1];w(e,r.map((function(e){return e.redirectAssetId})),t)},onScrollReached:function(e){"top"===e&&L>1&&B((function(e){return e-1})),"bottom"===e&&B((function(e){return e+1}))}})]})};v.propTypes={subjectWellId:i.number.isRequired,company:i.number.isRequired,value:i.string.isRequired,selectedWellIds:i.arrayOf(i.number).isRequired,onChange:i.func.isRequired};export{v as default};
