import e from"@babel/runtime/helpers/toConsumableArray";import t from"prop-types";import{capitalize as a}from"lodash";import{makeStyles as s,FormControl as r,InputLabel as n,Select as i,CircularProgress as o}from"@material-ui/core";import{useSecondaryAssetSelectData as l}from"../effects/index.js";import{ACTIVE_STATUS as d,ACTIVE_ASSET_ID as p,DEFAULT_ASSET_TYPE as c,ACTIVE_ASSETS_ID as u}from"../constants.js";import m from"./SelectItem.js";import{jsxs as f,jsx as v}from"react/jsx-runtime";var y="DC_SingleAssetEditor",g=s((function(e){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(t){return{cursor:"pointer",padding:0,color:t.disabled?e.palette.primary.text7:e.palette.primary.contrastText,"&:hover":{backgroundColor:"initial"}}},option:function(t){return{cursor:"pointer",padding:"0px 0px 0px 16px",color:t.disabled?e.palette.primary.text7:e.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(t){var s=t.appKey,A=t.primaryAssetLabel,b=t.isRequiredAssetId,h=t.secondaryAssetLabel,x=t.company,T=t.currentValue,I=t.defaultValue,C=t.onChange,N=t.disabled,V=t.parentAssetId,E=t.assetType,j=t.parentAssetType,F=t.assetFields,M=t.activeWellId,_=t.isDrillingPlatformApp,q=l({appKey:s,assetId:T,assetType:_?c:E,company:x,parentAssetId:V,parentAssetType:j,isRequiredAssetId:b,assetFields:F,activeWellId:M}),K=q.assets,R=q.loading,k=g({disabled:N}),P=T||I,W=K.some((function(e){return e.status===d})),w=a(E),B=[{name:"Active ".concat(w),id:p}].concat(e(K));return f("div",{className:k.container,children:[f(r,{className:k.formControl,disabled:R,children:[v(n,{shrink:!!P,children:h}),v(i,{"data-testid":t["data-testid"],classes:{select:k.select},value:P,disabled:N,onChange:function(e){var t=e.target,a=t.value===p?{id:p}:null==K?void 0:K.find((function(e){return e.id===t.value}));C(a)},fullWidth:!0,renderValue:function(e){if(e===u)return v("span",{className:k.activeAssets,children:"Active ".concat(w,"s")});if(e===p&&!W)return v("span",{className:k.noActiveAsset,children:"".concat(A," has No Active ").concat(h)});if(e===p&&W){var t=K.find((function(e){return e.status===d}));return v(m,{className:k.selectValue,assetName:t.name,status:t.status})}var a=K.find((function(t){return t.id===e}));return v(m,{className:k.selectValue,assetName:null==a?void 0:a.name,status:null==a?void 0:a.status})},children:B.map((function(e){var t=e.id,a=e.name,s=e.status,r=a||"";return v(m,{className:k.option,assetName:r,"data-testid":"".concat(y,"_option_").concat(r,"MenuItem"),value:t,status:s},t)}))})]}),R&&v(o,{"data-testid":"".concat(y,"_CircularProgress"),size:20,className:k.progress})]})};A.propTypes={appType:t.shape({constants:t.shape({})}),currentValue:t.oneOfType([t.number,t.string]),defaultValue:t.any,onChange:t.func.isRequired,parentAssetId:t.number,parentAssetType:t.string,assetType:t.string.isRequired,"data-testid":t.string,appKey:t.string,assetFields:t.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};
