Liferay.Loader.define("data-engine-js-components-web@1.0.89/js/core/utils/fields",["module","exports","require","../../utils/FormSupport.es","../../utils/fieldSupport","../../utils/fields.es","../../utils/settingsContext","../../utils/strings","../../utils/visitors.es"],(function(e,t,i){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.generateFieldName=function generateFieldName(e,t,i=null,r=[],d){let o,s;if(d){let l=0;for(o=(0,a.normalizeFieldName)(t),s=(0,n.findFieldByFieldName)(e,o);s&&s.fieldName!==i||r.includes(o);)l>0&&(o=(0,a.normalizeFieldName)(t)+l),s=(0,n.findFieldByFieldName)(e,o),l++;return(0,a.normalizeFieldName)(o)}for(o=t,s=(0,n.findFieldByFieldName)(e,o);s&&s.fieldName!==i||r.includes(o);)o=(0,l.getDefaultFieldName)(),s=(0,n.findFieldByFieldName)(e,o);return o},t.getFieldProperty=getFieldProperty,t.getFieldValue=function getFieldValue(e,t){return getFieldProperty(e,t,"value")},t.getField=function getField(e,t){let i;return new o.PagesVisitor(e).mapFields((e=>{e.fieldName===t&&(i=e)})),i},t.getFieldLocalizedValue=getFieldLocalizedValue,t.getLabel=getLabel,t.updateFieldValidationProperty=function updateFieldValidationProperty(e,t,i,n){return new o.PagesVisitor(e).mapFields((e=>{if("validation"===e.fieldName&&e.value){const l=e.value.expression;"fieldName"===i&&l&&l.value&&(l.value=l.value.replaceAll(t,n)),e=_objectSpread(_objectSpread({},e),{},{validation:_objectSpread(_objectSpread({},e.validation),{},{[i]:n}),value:_objectSpread(_objectSpread({},e.value),{},{expression:l})})}return e}))},t.getValidation=getValidation,t.createDuplicatedField=function createDuplicatedField(e,t,i=[]){var n;const{availableLanguageIds:a,defaultLanguageId:d,editingLanguageId:s,fieldNameGenerator:u,generateFieldNameUsingFieldLabel:c}=t,g=u((0,l.getDefaultFieldName)(),null,i);let p=(0,r.updateField)(t,e,"name",g);p=(0,r.updateField)(t,p,"fieldReference",g),p.instanceId=(0,l.generateInstanceId)(),a.forEach((t=>{const i=getLabel(e,d,t);i&&(p=(0,r.updateFieldLabel)(d,t,u,p,c,i))})),(null===(n=p.nestedFields)||void 0===n?void 0:n.length)>0&&(p.nestedFields=p.nestedFields.map((e=>{const n=createDuplicatedField(e,t,i);i.push(n.fieldName);let{rows:l=[]}=p;"string"==typeof l&&(l=JSON.parse(l));const a=new o.PagesVisitor([{rows:l}]).mapColumns((t=>_objectSpread(_objectSpread({},t),{},{fields:t.fields.map((t=>t===e.fieldName?n.fieldName:t))})));return p.rows=a[0].rows,n})),p.settingsContext=(0,r.updateSettingsContextProperty)(d,t.editingLanguageId,p.settingsContext,"rows",p.rows),p.ddmStructureLayoutId="",p.settingsContext=(0,r.updateSettingsContextProperty)(d,t.editingLanguageId,p.settingsContext,"ddmStructureLayoutId",p.ddmStructureLayoutId));const f=(0,r.updateSettingsContextInstanceId)(p),F=new o.PagesVisitor(f.pages);return p.settingsContext=_objectSpread(_objectSpread({},f),{},{pages:F.mapFields((e=>(0,l.localizeField)(e,d,s)))}),(0,r.updateField)(t,p,"validation",getValidation(p))},t.findInvalidFieldReference=function findInvalidFieldReference(e,t,i){let n=!1;return new o.PagesVisitor(t).mapFields((t=>{const l=(0,r.getSettingsContextProperty)(t.settingsContext,"fieldReference");e.fieldName!==t.fieldName&&(null==l?void 0:l.toLowerCase())===(null==i?void 0:i.toLowerCase())&&(n=!0)}),!0,!0),n};var n=i("../../utils/FormSupport.es"),l=i("../../utils/fieldSupport"),a=i("../../utils/fields.es"),r=i("../../utils/settingsContext"),d=i("../../utils/strings"),o=i("../../utils/visitors.es");function ownKeys(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}return i}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(i),!0).forEach((function(t){_defineProperty(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):ownKeys(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}function _defineProperty(e,t,i){return t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function getFieldProperty(e,t,i){let n;return new o.PagesVisitor(e).mapFields((e=>{e.fieldName===t&&(n=e[i])}),!0,!0),n}function getFieldLocalizedValue(e,t,i){return getFieldProperty(e,t,"localizedValue")[i]}function getLabel(e,t,i){const n=getFieldLocalizedValue(e.settingsContext.pages,"label",i);if(n)return(0,d.sub)(Liferay.Language.get("copy-of-x"),[n])}function getValidation(e){return(0,r.getSettingsContextProperty)(e.settingsContext,"validation")}}}));
//# sourceMappingURL=fields.js.map