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