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