Liferay.Loader.define("commerce-frontend-js@4.0.52/utilities/forms/DDMFormHandler",["module","exports","require","../AJAX/index","../eventsDefinitions","./formsHelper"],(function(e,t,s){var n;window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=(n=s("../AJAX/index"))&&n.__esModule?n:{default:n},a=s("../eventsDefinitions"),c=s("./formsHelper");class e{constructor({DDMFormInstance:e,actionURL:t,namespace:s,portletId:n}){this.actionURL=t,this.DDMFormInstance=e,this.namespace=s,this.portletId=n,this.fields=(0,c.getDefaultFieldsShape)(e.reactComponentRef.current.toJSON()),this._attachFormListener(),this.checkCPInstance()}_attachFormListener(){this.DDMFormInstance.unstable_onEvent((({payload:e,type:t})=>{"field_change"===t&&(this.fields=(0,c.updateFields)(this.fields,e),this.checkCPInstance())}))}checkCPInstance(){const e=JSON.stringify(this.fields),t=new FormData;t.append("_".concat(this.portletId,"_ddmFormValues"),e),i.default.POST(this.actionURL,null,{body:t,headers:new Headers({"x-csrf-token":Liferay.authToken})}).then((t=>{if(t.cpInstanceExist){t.disabled=this.checkCPInstanceOptions(),t.skuOptions=e,t.skuId=parseInt(t.cpInstanceId,10);const s={cpInstance:t,formFields:this.fields,namespace:this.namespace};Liferay.fire("".concat(this.namespace).concat(a.CP_INSTANCE_CHANGED),s)}}))}checkCPInstanceOptions(){let e=!1;for(const t of this.fields){if(t.required)if(0===t.value.length)e=!0;else for(const s of t.value){if(null===s||""===s){e=!0;break}e=!1}if(e)break}return e}}var o=e;t.default=o}}));
//# sourceMappingURL=DDMFormHandler.js.map