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