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