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