"use strict";var e=require("@babel/runtime/helpers/slicedToArray"),t=require("prop-types"),r=require("react"),s=require("lodash"),n=require("@material-ui/core"),a=require("../../Search/Search.js");require("../../Search/components/Listbox.js"),require("../../Search/components/Paper.js"),require("../../Search/components/RecentSearches.js");var o=require("../../Search/components/InputAdornmentLeft.js"),i=require("../../Search/components/Groups.js");require("../../Search/components/SelectAllListItem.js");var u=require("../effects/usePrimaryAssetSelectData.js"),l=require("../constants.js"),c=require("./SelectItem.js");require("../../../constants/goals.js"),require("../../../constants/segment.js"),require("../../../constants/alerts.js"),require("../../../constants/apps.js"),require("../../../constants/drillstring.js"),require("../../../constants/completion.js"),require("../../../constants/appPackages.js"),require("../../../constants/notifications.js"),require("../../../constants/feed.js"),require("../../../constants/bha.js");var p=require("../../../constants/assetTypes.js");require("../../../utils/env.js"),require("../../GradientManager/configuration/constants.js");var d=require("../../AssetEditor/constants.js"),g=require("react/jsx-runtime");function h(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var f=h(e),m=h(t),q=n.makeStyles({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}}),A=function(e){var t=e.placeholder,h=e.label,m=e["data-testid"],A=e.appKey,j=e.assetFields,S=e.assetType,b=e.company,C=e.currentOption,v=e.currentValue,x=e.defaultValue,I=e.disableClearable,y=e.disabled,T=e.groups,P=e.isDrillingPlatformApp,R=e.isNullable,G=e.isRequiredAssetId,E=e.multiple,F=e.onActiveAssetIdChange,V=e.onChange,O=e.onGroupChange,_=e.onGroupReset,k=e.onInputReset,D=e.selectedGroup,L=e.setCurrentOption,M=r.useState(""),N=f.default(M,2),H=N[0],K=N[1],U=r.useState(1),w=f.default(U,2),z=w[0],B=w[1],W=r.useState(!0),Y=f.default(W,2),J=Y[0],Q=Y[1],X=S===p.ASSET_TYPES.rig.type?"Search Rig...":"Search Pad / Frac Fleet...",Z=q(),$=u.usePrimaryAssetSelectData({isDrillingPlatformApp:P,searchValue:H,scrollPage:z,appKey:A,assetType:S,company:b,groups:T,isRequiredAssetId:G,assetFields:j,selectedGroup:D,currentValue:v,setCurrentOption:L,onActiveAssetIdChange:F}),ee=$.assets,te=$.loading;r.useEffect((function(){var e=ee.length>=d.PER_PAGE*z;Q(e)}),[ee,z]);var re=r.useMemo((function(){return s.debounce((function(e,t){"input"===t&&(B(1),K(e))}),200)}),[]),se=r.useMemo((function(){return s.debounce((function(){return B((function(e){return e+1}))}),250)}),[]);return g.jsx(a,{classes:{paper:Z.paper,listbox:Z.listbox,groupChip:Z.groupChip},defaultValue:x,disableClearable:I||y,disabled:y,isNullable:R,loading:te,onGroupChange:O,placeholder:t||X,selectedGroup:D,onGroupReset:_,onChange:function(e,t){V(t)},"data-testid":m,multiple:E,onInputChangeCallback:re,onInputReset:function(){k(),L(null)},TextFieldProps:{label:h,value:H,endAdornment:(null==C?void 0:C.status)===l.ACTIVE_STATUS&&g.jsx(n.Chip,{"data-not-migrated-muichip":!0,className:Z.activeChip,label:"Active"})},ListboxProps:{onScroll:function(e){if(J&&!te){var t=e.currentTarget;t.scrollTop+t.clientHeight>t.scrollHeight-800&&se()}}},isHiddenAllOption:!0,value:C,options:ee,renderCustomOption:function(e,t){var r=e.status,s=e.name,n=e.id,a=t.selected;return g.jsx(c,{className:Z.option,assetName:s,multiple:E,selected:a,value:n,status:r&&l.ACTIVE_STATUS,"data-testid":"".concat(m,"_option_").concat(s,"MenuItem")},n)},getOptionLabel:function(e){return e.name||""},GroupsComponent:i,groups:T,InputProps:{startAdornment:g.jsx(o,{})}})};A.propTypes={assetFields:m.default.array,"data-testid":m.default.string,onInputReset:m.default.func,onActiveAssetIdChange:m.default.func,placeholder:m.default.string},A.defaultProps={assetFields:[],"data-testid":"PrimaryAssetEditorAutocomplete",onInputReset:function(){},onActiveAssetIdChange:function(){},placeholder:null},module.exports=A;
