Liferay.Loader.define("data-engine-js-components-web@1.0.86/js/core/utils/rules",["module","exports","require","../../utils/Token","../../utils/Tokenizer","../../utils/visitors.es"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.renameFieldInsideExpression=renameFieldInsideExpression,t.updateRulesReferences=function updateRulesReferences(e,t,r){const n=t.fieldName,o=r.fieldName,s=new i.RulesVisitor(e);return e=s.mapActions((e=>(e.target===n&&(e=_objectSpread(_objectSpread({},e),{},{target:o})),"calculate"===e.action?e=_objectSpread(_objectSpread({},e),{},{expression:renameFieldInsideExpression(e.expression,n,o)}):"auto-fill"===e.action&&(e=_objectSpread(_objectSpread({},e),{},{inputs:renameFieldInsideAutofill(e.inputs,n,o),outputs:renameFieldInsideAutofill(e.outputs,n,o)})),e))),s.setRules(e),s.mapConditions((e=>_objectSpread(_objectSpread({},e),{},{operands:e.operands.map(((i,s)=>{const a=t.options,p=r.options;if("field"===i.type&&i.value===n)return _objectSpread(_objectSpread({},i),{},{value:o});if(1===s&&isFieldValueOperand(e.operands)&&isEqualLengthOptions(a,p)&&isOptionReferencedByOperand(a,i.value)){const e=p.find((({value:e})=>e===a.find((({label:e})=>e===i.value)).value));if(e)return _objectSpread(_objectSpread({},i),{},{value:e.label})}return i}))})))};var n=r("../../utils/Token"),o=r("../../utils/Tokenizer"),i=r("../../utils/visitors.es");function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const isEqualLengthOptions=(e,t)=>!(!e||!t)&&e.length===t.length,isFieldValueOperand=e=>2===e.length&&"field"===e[0].type&&"string"===e[1].type,isOptionReferencedByOperand=(e,t)=>e.some((({label:e})=>t===e));function renameFieldInsideExpression(e,t,r){const i=o.Tokenizer.tokenize(e);return o.Tokenizer.stringifyTokens(i.map((e=>(e.type===n.Token.VARIABLE&&e.value===t&&(e=new n.Token(n.Token.VARIABLE,r)),e))))}const renameFieldInsideAutofill=(e,t,r)=>(Object.keys(e).map((n=>{e[n]===t&&(e[n]=r)})),e)}}));
//# sourceMappingURL=rules.js.map