Liferay.Loader.define("@liferay/object-web@1.0.181/js/components/ObjectField/useObjectFieldForm",["module","exports","require","@liferay/object-js-components-web","frontend-js-web","../../utils/constants","../../utils/fieldSettings"],(function(e,i,t){window;Object.defineProperty(i,"__esModule",{value:!0}),i.useObjectFieldForm=function useObjectFieldForm({forbiddenChars:e,forbiddenLastChars:i,forbiddenNames:t,initialValues:o,onSubmit:u}){const{errors:r,handleChange:d,handleSubmit:m,setValues:c,values:f}=(0,a.useForm)({initialValues:o,onSubmit:u,validate:o=>{var u,r;const d={},m=null===(u=o.label)||void 0===u?void 0:u[l.defaultLanguageId],c=(0,s.normalizeFieldSettings)(o.objectFieldSettings);if((0,a.invalidateRequired)(m)&&(d.label=a.REQUIRED_MSG),(0,a.invalidateRequired)(null!==(r=o.name)&&void 0!==r?r:m)&&(d.name=a.REQUIRED_MSG),o.businessType){if("Aggregation"===o.businessType)c.function||(d.function=a.REQUIRED_MSG),"COUNT"===c.function||c.objectFieldName||(d.objectFieldName=a.REQUIRED_MSG),c.objectRelationshipName||(d.objectRelationshipName=a.REQUIRED_MSG);else if("Attachment"===o.businessType){const l=Math.floor(Liferay.PropsValues.UPLOAD_SERVLET_REQUEST_IMPL_MAX_SIZE/1048576);if((0,a.invalidateRequired)(c.acceptedFileExtensions)&&(d.acceptedFileExtensions=a.REQUIRED_MSG),c.fileSource||(d.fileSource=a.REQUIRED_MSG),c.maximumFileSize||0===c.maximumFileSize?c.maximumFileSize>l?d.maximumFileSize=(0,n.sub)(Liferay.Language.get("file-size-is-larger-than-the-allowed-overall-maximum-upload-request-size-x-mb"),l):c.maximumFileSize<0&&(d.maximumFileSize=(0,n.sub)(Liferay.Language.get("only-integers-greater-than-or-equal-to-x-are-allowed"),0)):d.maximumFileSize=a.REQUIRED_MSG,c.showFilesInDocumentsAndMedia)if((0,a.invalidateRequired)(c.storageDLFolderPath))d.storageDLFolderPath=a.REQUIRED_MSG;else{const a=(a=>{const l=a[a.length-1];if(null==i?void 0:i.some((e=>e===l)))return(0,n.sub)(Liferay.Language.get("the-folder-name-cannot-end-with-the-following-characters-x"),i.join(" "));if(null==e?void 0:e.some((e=>a.includes(e))))return(0,n.sub)(Liferay.Language.get("the-folder-name-cannot-contain-the-following-invalid-characters-x"),e.join(" "));const s=new Set(t);return t&&a.split("/").some((e=>s.has(e)))?(0,n.sub)(Liferay.Language.get("the-folder-name-cannot-have-a-reserved-word-such-as-x"),t.join(", ")):null})(c.storageDLFolderPath);null!==a&&(d.storageDLFolderPath=a)}}else if("Formula"===o.businessType)(0,a.invalidateRequired)(c.output)&&(d.output=a.REQUIRED_MSG);else if("LongText"===o.businessType||"Text"===o.businessType)c.showCounter&&!c.maxLength&&(d.maxLength=a.REQUIRED_MSG);else if("Picklist"===o.businessType){var f,b;o.listTypeDefinitionId||(d.listTypeDefinitionId=a.REQUIRED_MSG);const e=null===(f=o.objectFieldSettings)||void 0===f?void 0:f.some((e=>"defaultValueType"===e.name&&e.value)),i=null===(b=o.objectFieldSettings)||void 0===b?void 0:b.some((e=>"defaultValue"===e.name&&e.value));o.id?e&&!i&&(d.defaultValue=a.REQUIRED_MSG):o.state&&!i&&(d.defaultValue=a.REQUIRED_MSG)}}else d.businessType=a.REQUIRED_MSG;return d}});return{errors:r,handleChange:d,handleSubmit:m,setValues:c,values:f}};var a=t("@liferay/object-js-components-web"),n=t("frontend-js-web"),l=t("../../utils/constants"),s=t("../../utils/fieldSettings")}));
//# sourceMappingURL=useObjectFieldForm.js.map