"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/toConsumableArray"),t=require("prop-types"),a=require("lodash"),s=require("@material-ui/core"),r=require("../effects/index.js"),n=require("../constants.js"),i=require("./SelectItem.js"),l=require("react/jsx-runtime");function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=o(e),d=o(t),c="DC_SingleAssetEditor",p=s.makeStyles((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"}}})),f=function(e){var t=e.appKey,o=e.primaryAssetLabel,d=e.isRequiredAssetId,f=e.secondaryAssetLabel,A=e.company,m=e.currentValue,T=e.defaultValue,y=e.onChange,v=e.disabled,x=e.parentAssetId,I=e.assetType,g=e.parentAssetType,b=e.assetFields,E=e.activeWellId,S=e.isDrillingPlatformApp,_=r.useSecondaryAssetSelectData({appKey:t,assetId:m,assetType:S?n.DEFAULT_ASSET_TYPE:I,company:A,parentAssetId:x,parentAssetType:g,isRequiredAssetId:d,assetFields:b,activeWellId:E}),C=_.assets,h=_.loading,V=p({disabled:v}),j=m||T,N=C.some((function(e){return e.status===n.ACTIVE_STATUS})),q=a.capitalize(I),D=[{name:"Active ".concat(q),id:n.ACTIVE_ASSET_ID}].concat(u.default(C));return l.jsxs("div",{className:V.container,children:[l.jsxs(s.FormControl,{className:V.formControl,disabled:h,children:[l.jsx(s.InputLabel,{shrink:!!j,children:f}),l.jsx(s.Select,{"data-testid":e["data-testid"],classes:{select:V.select},value:j,disabled:v,onChange:function(e){var t=e.target,a=t.value===n.ACTIVE_ASSET_ID?{id:n.ACTIVE_ASSET_ID}:null==C?void 0:C.find((function(e){return e.id===t.value}));y(a)},fullWidth:!0,renderValue:function(e){if(e===n.ACTIVE_ASSETS_ID)return l.jsx("span",{className:V.activeAssets,children:"Active ".concat(q,"s")});if(e===n.ACTIVE_ASSET_ID&&!N)return l.jsx("span",{className:V.noActiveAsset,children:"".concat(o," has No Active ").concat(f)});if(e===n.ACTIVE_ASSET_ID&&N){var t=C.find((function(e){return e.status===n.ACTIVE_STATUS}));return l.jsx(i,{className:V.selectValue,assetName:t.name,status:t.status})}var a=C.find((function(t){return t.id===e}));return l.jsx(i,{className:V.selectValue,assetName:null==a?void 0:a.name,status:null==a?void 0:a.status})},children:D.map((function(e){var t=e.id,a=e.name,s=e.status,r=a||"";return l.jsx(i,{className:V.option,assetName:r,"data-testid":"".concat(c,"_option_").concat(r,"MenuItem"),value:t,status:s},t)}))})]}),h&&l.jsx(s.CircularProgress,{"data-testid":"".concat(c,"_CircularProgress"),size:20,className:V.progress})]})};f.propTypes={appType:d.default.shape({constants:d.default.shape({})}),currentValue:d.default.oneOfType([d.default.number,d.default.string]),defaultValue:d.default.any,onChange:d.default.func.isRequired,parentAssetId:d.default.number,parentAssetType:d.default.string,assetType:d.default.string.isRequired,"data-testid":d.default.string,appKey:d.default.string,assetFields:d.default.array},f.defaultProps={currentValue:"",defaultValue:"",appType:void 0,parentAssetId:void 0,parentAssetType:void 0,"data-testid":"".concat(c,"_autoComplete"),appKey:null,assetFields:[]},exports.PAGE_NAME=c,exports.default=f;
