import t from"@babel/runtime/helpers/slicedToArray";import e from"prop-types";import{useState as o,useEffect as s,useMemo as n}from"react";import{debounce as r}from"lodash";import{makeStyles as a,Chip as i}from"@material-ui/core";import{Search as p}from"../../Search/Search.js";import"../../Search/components/Listbox.js";import"../../Search/components/Paper.js";import"../../Search/components/RecentSearches.js";import l from"../../Search/components/InputAdornmentLeft.js";import c from"../../Search/components/Groups.js";import"../../Search/components/SelectAllListItem.js";import{usePrimaryAssetSelectData as u}from"../effects/usePrimaryAssetSelectData.js";import{ACTIVE_STATUS as m}from"../constants.js";import d from"./SelectItem.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{ASSET_TYPES as g}from"../../../constants/assetTypes.js";import"../../../utils/env.js";import"../../GradientManager/configuration/constants.js";import{PER_PAGE as f}from"../../AssetEditor/constants.js";import{jsx as h}from"react/jsx-runtime";var j=a({paper:{boxShadow:"0px 3px 10px 0px #00000066"},listbox:{maxHeight:210,"& .MuiAutocomplete-option":{padding:"0px 0px 0px 16px"}},option:{padding:"6px 0","&:hover":{backgroundColor:"initial"}},groupChip:{height:32,padding:0},activeChip:{fontWeight:500,backgroundColor:"#75DB29",color:"#212121",fontSize:10,cursor:"pointer",height:12,textTransform:"uppercase",marginRight:12,letterSpacing:1}}),b=function(e){var a=e.placeholder,b=e.label,A=e["data-testid"],C=e.appKey,x=e.assetFields,v=e.assetType,S=e.company,I=e.currentOption,y=e.currentValue,P=e.defaultValue,R=e.disableClearable,G=e.disabled,T=e.groups,F=e.isDrillingPlatformApp,O=e.isNullable,L=e.isRequiredAssetId,N=e.multiple,V=e.onActiveAssetIdChange,k=e.onChange,D=e.onGroupChange,H=e.onGroupReset,M=e.onInputReset,q=e.selectedGroup,E=e.setCurrentOption,K=o(""),_=t(K,2),w=_[0],z=_[1],B=o(1),W=t(B,2),J=W[0],Q=W[1],U=o(!0),X=t(U,2),Y=X[0],Z=X[1],$=v===g.rig.type?"Search Rig...":"Search Pad / Frac Fleet...",tt=j(),et=u({isDrillingPlatformApp:F,searchValue:w,scrollPage:J,appKey:C,assetType:v,company:S,groups:T,isRequiredAssetId:L,assetFields:x,selectedGroup:q,currentValue:y,setCurrentOption:E,onActiveAssetIdChange:V}),ot=et.assets,st=et.loading;s((function(){var t=ot.length>=f*J;Z(t)}),[ot,J]);var nt=n((function(){return r((function(t,e){"input"===e&&(Q(1),z(t))}),200)}),[]),rt=n((function(){return r((function(){return Q((function(t){return t+1}))}),250)}),[]);return h(p,{classes:{paper:tt.paper,listbox:tt.listbox,groupChip:tt.groupChip},defaultValue:P,disableClearable:R||G,disabled:G,isNullable:O,loading:st,onGroupChange:D,placeholder:a||$,selectedGroup:q,onGroupReset:H,onChange:function(t,e){k(e)},"data-testid":A,multiple:N,onInputChangeCallback:nt,onInputReset:function(){M(),E(null)},TextFieldProps:{label:b,value:w,endAdornment:(null==I?void 0:I.status)===m&&h(i,{"data-not-migrated-muichip":!0,className:tt.activeChip,label:"Active"})},ListboxProps:{onScroll:function(t){if(Y&&!st){var e=t.currentTarget;e.scrollTop+e.clientHeight>e.scrollHeight-800&&rt()}}},isHiddenAllOption:!0,value:I,options:ot,renderCustomOption:function(t,e){var o=t.status,s=t.name,n=t.id,r=e.selected;return h(d,{className:tt.option,assetName:s,multiple:N,selected:r,value:n,status:o&&m,"data-testid":"".concat(A,"_option_").concat(s,"MenuItem")},n)},getOptionLabel:function(t){return t.name||""},GroupsComponent:c,groups:T,InputProps:{startAdornment:h(l,{})}})};b.propTypes={assetFields:e.array,"data-testid":e.string,onInputReset:e.func,onActiveAssetIdChange:e.func,placeholder:e.string},b.defaultProps={assetFields:[],"data-testid":"PrimaryAssetEditorAutocomplete",onInputReset:function(){},onActiveAssetIdChange:function(){},placeholder:null};export{b as default};
