import t from"@babel/runtime/helpers/toConsumableArray";import e from"prop-types";import{capitalize as s}from"lodash";import{makeStyles as a,FormControl as n,InputLabel as r,Select as i,CircularProgress as o}from"@material-ui/core";import{useSecondaryAssetSelectData as p}from"../effects/index.js";import{ACTIVE_STATUS as l,ACTIVE_ASSET_ID as c,DEFAULT_ASSET_TYPE as d,ACTIVE_ASSETS_ID as u}from"../constants.js";import m 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 f}from"../../../constants/assetTypes.js";import"../../../constants/corvaCompanyId.js";import"../../GradientManager/configuration/constants.js";import{jsxs as g,jsx as v}from"react/jsx-runtime";var y="DC_SingleAssetEditor",b=a((function(t){return{container:{position:"relative"},select:{display:"flex",alignItems:"center",justifyContent:"space-between",paddingBottom:0,paddingTop:0},formControl:{marginTop:16,width:"100%","& .MuiInput-underline.Mui-disabled, & .MuiFilledInput-underline.Mui-disabled":{"&::before":{borderBottom:"1px solid #808080"}}},selectValue:function(e){return{cursor:"pointer",padding:0,color:e.disabled?t.palette.primary.text7:t.palette.primary.contrastText,"&:hover":{backgroundColor:"initial"}}},option:function(e){return{cursor:"pointer",padding:"0px 0px 0px 16px",color:e.disabled?t.palette.primary.text7:t.palette.primary.contrastText,"&:hover":{backgroundColor:"rgba(255, 255, 255, 0.16)"}}},activeAssets:{color:"#9E9E9E",padding:"8px 0 6px"},progress:{position:"absolute",right:20,bottom:4},noActiveAsset:{color:"#9E9E9E",padding:"8px 0 6px"}}})),A=function(e){var a=e.appKey,A=e.primaryAssetLabel,h=e.isRequiredAssetId,j=e.secondaryAssetLabel,x=e.company,N=e.currentValue,T=e.defaultValue,I=e.onChange,C=e.disabled,V=e.parentAssetId,E=e.assetType,_=e.parentAssetType,M=e.assetFields,F=e.activeWellId,k=e.isDrillingPlatformApp,q=p({appKey:a,assetId:N,assetType:k?d:E,company:x,parentAssetId:V,parentAssetType:_,isRequiredAssetId:h,assetFields:M,activeWellId:F}),K=q.assets,P=q.loading,R=b({disabled:C}),W=N||T,w=K.some((function(t){return t.status===l}));_===f.intervention_unit.type&&(w=K.some((function(t){return Number(t.id)===Number(F)})));var B=s(E),D=[{name:"Active ".concat(B),id:c}].concat(t(K));return g("div",{className:R.container,children:[g(n,{className:R.formControl,disabled:P,children:[v(r,{shrink:!!W,children:j}),v(i,{"data-testid":e["data-testid"],classes:{select:R.select},value:W,disabled:C,onChange:function(t){var e=t.target,s=e.value===c?{id:c}:null==K?void 0:K.find((function(t){return t.id===e.value}));I(s)},fullWidth:!0,renderValue:function(t){if(t===u)return v("span",{className:R.activeAssets,children:"Active ".concat(B,"s")});if(t===c&&!w)return v("span",{className:R.noActiveAsset,children:"".concat(A," has No Active ").concat(j)});if(t===c&&w){var e=_===f.intervention_unit.type?K.find((function(t){return Number(t.id)===Number(F)})):K.find((function(t){return t.status===l}));return v(m,{className:R.selectValue,assetName:e.name,status:e.status})}var s=K.find((function(e){return e.id===t}));return v(m,{className:R.selectValue,assetName:null==s?void 0:s.name,status:null==s?void 0:s.status})},children:D.map((function(t){var e=t.id,s=t.name,a=t.status,n=s||"";return v(m,{className:R.option,assetName:n,"data-testid":"".concat(y,"_option_").concat(n,"MenuItem"),value:e,status:a},e)}))})]}),P&&v(o,{"data-testid":"".concat(y,"_CircularProgress"),size:20,className:R.progress})]})};A.propTypes={appType:e.shape({constants:e.shape({})}),currentValue:e.oneOfType([e.number,e.string]),defaultValue:e.any,onChange:e.func.isRequired,parentAssetId:e.number,parentAssetType:e.string,assetType:e.string.isRequired,"data-testid":e.string,appKey:e.string,assetFields:e.array},A.defaultProps={currentValue:"",defaultValue:"",appType:void 0,parentAssetId:void 0,parentAssetType:void 0,"data-testid":"".concat(y,"_autoComplete"),appKey:null,assetFields:[]};export{y as PAGE_NAME,A as default};
//# sourceMappingURL=SecondaryAssetSelect.js.map
