import e from"@babel/runtime/helpers/slicedToArray";import t from"prop-types";import{useState as o,useEffect as r,useMemo as n}from"react";import{debounce as s}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 u from"../../Search/components/Groups.js";import"../../Search/components/SelectAllListItem.js";import{usePrimaryAssetSelectData as c}from"../effects/usePrimaryAssetSelectData.js";import{ACTIVE_STATUS as d}from"../constants.js";import{getSearchPlaceholder as m}from"../utils/index.js";import f from"./SelectItem.js";import{PER_PAGE as h}from"../../AssetEditor/constants.js";import{jsx as g}from"react/jsx-runtime";var A=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(t){var a=t.placeholder,b=t.label,C=t["data-testid"],x=t.appKey,S=t.assetFields,v=t.assetType,I=t.company,y=t.currentOption,j=t.currentValue,P=t.defaultValue,R=t.disableClearable,G=t.disabled,T=t.groups,O=t.isDrillingPlatformApp,F=t.isNullable,L=t.isRequiredAssetId,N=t.isSecondaryAssetPresent,V=t.multiple,D=t.onActiveAssetIdChange,H=t.onChange,k=t.onGroupChange,q=t.onGroupReset,E=t.onInputReset,K=t.selectedGroup,M=t.setCurrentOption,_=o(""),w=e(_,2),z=w[0],B=w[1],W=o(1),J=e(W,2),Q=J[0],U=J[1],X=o(!0),Y=e(X,2),Z=Y[0],$=Y[1],ee=o(!1),te=e(ee,2),oe=te[0],re=te[1],ne=m(v,N),se=A(),ae=c({isDrillingPlatformApp:O,searchValue:oe&&z?z:"",scrollPage:Q,appKey:x,assetType:v,company:I,groups:T,isRequiredAssetId:L,assetFields:S,selectedGroup:K,currentValue:j,setCurrentOption:M,onActiveAssetIdChange:D}),ie=ae.assets,pe=ae.loading;r((function(){var e=ie.length>=h*Q;$(e)}),[ie,Q]);var le=n((function(){return s((function(e,t){"input"===t?(U(1),B(e),re(!0)):"reset"!==t&&"clear"!==t||(re(!1),B(""))}),200)}),[]),ue=n((function(){return s((function(){return U((function(e){return e+1}))}),250)}),[]);return g(p,{classes:{paper:se.paper,listbox:se.listbox,groupChip:se.groupChip},defaultValue:P,disableClearable:R||G,disabled:G,isNullable:F,loading:pe,onGroupChange:k,placeholder:a||ne,selectedGroup:K,onGroupReset:q,onChange:function(e,t){H(t),re(!1),B("")},onClose:function(){re(!1),B("")},onOpen:function(){z||re(!1)},"data-testid":C,multiple:V,onInputChangeCallback:le,onInputReset:function(){E(),M(null),re(!1),B("")},TextFieldProps:{label:b,value:z,endAdornment:(null==y?void 0:y.status)===d&&g(i,{"data-not-migrated-muichip":!0,className:se.activeChip,label:"Active"})},ListboxProps:{onScroll:function(e){if(Z&&!pe){var t=e.currentTarget;t.scrollTop+t.clientHeight>t.scrollHeight-800&&ue()}}},isHiddenAllOption:!0,value:y,options:ie,renderCustomOption:function(e,t){var o=e.status,r=e.name,n=e.id,s=t.selected;return g(f,{className:se.option,assetName:r,multiple:V,selected:s,value:n,status:o&&d,"data-testid":"".concat(C,"_option_").concat(r,"MenuItem")},n)},getOptionLabel:function(e){return e.name||""},GroupsComponent:u,groups:T,InputProps:{startAdornment:g(l,{})}})};b.propTypes={isSecondaryAssetPresent:t.bool,assetFields:t.array,"data-testid":t.string,onInputReset:t.func,onActiveAssetIdChange:t.func,placeholder:t.string},b.defaultProps={assetFields:[],isSecondaryAssetPresent:!0,"data-testid":"PrimaryAssetEditorAutocomplete",onInputReset:function(){},onActiveAssetIdChange:function(){},placeholder:null};export{b as default};
//# sourceMappingURL=PrimaryAssetSelectV2.js.map
