import e from"@babel/runtime/helpers/defineProperty";import t from"@babel/runtime/helpers/slicedToArray";import{useState as a}from"react";import s from"prop-types";import{get as l,capitalize as r}from"lodash";import{Button as o}from"@material-ui/core";import i from"./SingleAssetEditor.js";import n from"./AssetEditorAutocomplete.js";import p from"./AssetEditors.css.js";import{jsxs as c,jsx as u}from"react/jsx-runtime";var d="DC_AppSettingsAssetEditor",m=function(s){var m=s.appKey,y=s.appType,A=s.defaultValue,f=s.isNullable,b=s.label,h=s.onSettingsChange,g=s.settings,C=l(y,["primaryAsset","assetType","type"]),T=l(y,["primaryAsset","assetType","id"]),v=l(y,["primaryAsset","autocompleteSelect"]),N=l(y,["secondaryAsset","assetType","type"]),V=l(y,["secondaryAsset","assetType","id"]),K=l(y,["secondaryAsset","autocompleteSelect"]),_=l(g,T),E=a(_||A),S=t(E,2),j=S[0],q=S[1],R=a(l(g,V)),k=t(R,2),x=k[0],B=k[1],D=a(!(!N||x)),I=t(D,2),P=I[0],U=I[1],W=a(!(!N||!x)),w=t(W,2),z=w[0],F=w[1],G=function(t){B(t),h(e({},V,t))},H=function(t){q(t),B(null),F(!1),U(!!N);var a=e({},T,t);V&&(a[V]=null),h(a)};return c("div",{className:p.main,children:[u("div",{className:p.title,children:"Active Asset"}),c("div",{className:p.editor,children:[v?u(n,{appKey:m,assetType:C,currentValue:j,"data-testid":"".concat(d,"_primaryAssetEditorAutocomplete"),defaultValue:A,disableClearable:!f,isNullable:f,label:b,onChange:H}):u(i,{appKey:m,assetType:C,currentValue:j,"data-testid":"".concat(d,"_primaryAutoComplete"),defaultValue:A,isNullable:f,label:b,onChange:H}),P&&u(o,{"data-testid":"".concat(d,"_changeWellButton"),color:"primary",onClick:function(){F(!0),U(!1)},disabled:!_,children:"Change ".concat(r(N))}),!P&&z&&u(o,{"data-testid":"".concat(d,"_useDefaultButton"),color:"secondary",onClick:function(){B(null),F(!1),U(!!N),h(e({},V,null))},children:"Use active asset"})]}),z&&u("div",{className:p.editor,children:K?u(n,{appKey:m,assetType:N,currentValue:x,"data-testid":"".concat(d,"_secondaryAssetEditorAutocomplete"),defaultValue:A,disableClearable:!1,isNullable:f,label:"Active ".concat(r(N)),onChange:G,parentAssetId:j,parentAssetType:C}):u(i,{"data-testid":"".concat(d,"_secondaryAutoComplete"),onChange:G,defaultValue:A,currentValue:x,isNullable:f,label:"Active ".concat(r(N)),assetType:N,parentAssetId:j,parentAssetType:C,appKey:m})})]})};m.defaultProps={label:"Choose An Asset",isNullable:!1,defaultValue:void 0,appKey:null},m.propTypes={settings:s.shape({}).isRequired,appType:s.shape({}).isRequired,defaultValue:s.any,onSettingsChange:s.func.isRequired,label:s.string,isNullable:s.bool,appKey:s.string};export{m as default};
