Liferay.Loader.define("@liferay/layout-content-page-editor-web@3.0.145/page_editor/app/utils/useCheckFormsValidity",["module","exports","require","../config/constants/fragmentEntryTypes","../config/constants/freemarkerFragmentEntryProcessor","../config/constants/layoutDataItemTypes","../contexts/FormValidationContext","../contexts/GlobalContext","../contexts/StoreContext","../services/FormService","./cache","./getDescendantIds","./getFormErrorDescription","./getLayoutDataItemUniqueClassName","./hasRequiredInputChild","./hasVisibleSubmitChild","./isLayoutDataItemDeleted","./isVisible"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function useCheckFormsValidity(){const e=(0,o.useGlobalContext)(),t=(0,d.useSelectorRef)((e=>e)),n=(0,s.useSetFormValidations)(),r=new Map;return async()=>{const{fragmentEntryLinks:s,layoutData:o,selectedViewportSize:d}=t.current,I=function getFormItems(e){return Object.values(e.items).filter((t=>t.type===a.LAYOUT_DATA_ITEM_TYPES.form&&"0"!==t.config.classNameId&&!(0,p.isLayoutDataItemDeleted)(e,t.itemId)))}(o).filter((t=>{const n=document.querySelector(".".concat((0,f.default)(t.itemId)));return(0,y.default)(n,e)}));if(!I.length)return Promise.resolve(!0);for(const t of I)(0,g.default)(t.itemId,e)||addError(r,t,m.FORM_ERROR_TYPES.missingSubmit),await checkUnmappedInputChild(t,s,o,r);const R=I.map((e=>{const{config:{classNameId:t,classTypeId:n},itemId:r}=e,i=(0,l.getCacheKey)([l.CACHE_KEYS.formFields,t,n]),{data:a}=(0,l.getCacheItem)(i);return a?Promise.resolve({fields:a,itemId:r}):c.default.getFormFields({classNameId:t,classTypeId:n}).then((e=>({fields:e,itemId:r})))}));return Promise.all(R).then((e=>(e.forEach((({fields:e,itemId:t})=>{const n=o.items[t];(0,E.default)({checkHidden:!0,formFields:e,fragmentEntryLinks:s,itemId:t,layoutData:o,selectedViewportSize:d})&&addError(r,n,m.FORM_ERROR_TYPES.hiddenFields),function hasUnmappedRequiredField(e,t,n,r){const s=(0,u.getDescendantIds)(r,e);return n.flatMap((e=>e.fields)).filter((e=>e.required)).some((e=>!s.some((n=>{const s=r.items[n];if(s.type!==a.LAYOUT_DATA_ITEM_TYPES.fragment)return!1;const{inputFieldId:o}=t[s.config.fragmentEntryLinkId].editableValues[i.FREEMARKER_FRAGMENT_ENTRY_PROCESSOR]||{};return o===e.key}))))}(t,s,e,o)&&addError(r,n,m.FORM_ERROR_TYPES.missingFields)})),!r.size||(n(Array.from(r.values())),!1))))}};var r=n("../config/constants/fragmentEntryTypes"),i=n("../config/constants/freemarkerFragmentEntryProcessor"),a=n("../config/constants/layoutDataItemTypes"),s=n("../contexts/FormValidationContext"),o=n("../contexts/GlobalContext"),d=n("../contexts/StoreContext"),c=_interopRequireDefault(n("../services/FormService")),l=n("./cache"),u=n("./getDescendantIds"),m=n("./getFormErrorDescription"),f=_interopRequireDefault(n("./getLayoutDataItemUniqueClassName")),E=_interopRequireDefault(n("./hasRequiredInputChild")),g=_interopRequireDefault(n("./hasVisibleSubmitChild")),p=n("./isLayoutDataItemDeleted"),y=_interopRequireDefault(n("./isVisible"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function addError(e,t,n){const r=e.get(t.itemId),i=[...r?r.errors:[],n];e.set(t.itemId,{classNameId:t.config.classNameId,errors:i})}async function checkUnmappedInputChild(e,t,n,s){const o=(0,u.getDescendantIds)(n,e.itemId);for(const d of o){const o=n.items[d];if(o.type!==a.LAYOUT_DATA_ITEM_TYPES.fragment)continue;const l=t[o.config.fragmentEntryLinkId];if(l.fragmentEntryType!==r.FRAGMENT_ENTRY_TYPES.input)continue;const{inputFieldId:u}=l.editableValues[i.FREEMARKER_FRAGMENT_ENTRY_PROCESSOR]||{};if(u)continue;const f=await c.default.getFragmentEntryInputFieldTypes({fragmentEntryKey:l.fragmentEntryKey,groupId:l.groupId});f.includes("captcha")||f.includes("categorization")||addError(s,e,m.FORM_ERROR_TYPES.missingFragments)}}}}));
//# sourceMappingURL=useCheckFormsValidity.js.map