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