Liferay.Loader.define("commerce-frontend-js@4.0.75/utilities/forms/DDMFormHandler",["module","exports","require","../AJAX/index","../eventsDefinitions","./formsHelper"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var s=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(n("../AJAX/index")),i=n("../eventsDefinitions"),a=n("./formsHelper");class DDMFormHandler{constructor({DDMFormInstance:e,actionURL:t,namespace:n,portletId:s}){this.actionURL=t,this.DDMFormInstance=e,this.namespace=n,this.portletId=s,this.fields=(0,a.getDefaultFieldsShape)(e.reactComponentRef.current.toJSON()),this._attachFormListener(),this.checkCPInstance()}_attachFormListener(){this.DDMFormInstance.unstable_onEvent((({payload:e,type:t})=>{"field_change"===t&&(this.fields=(0,a.updateFields)(this.fields,e),this.checkCPInstance())}))}checkCPInstance(){const e=JSON.stringify(this.fields),t=new FormData;t.append("_".concat(this.portletId,"_ddmFormValues"),e),s.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 n={cpInstance:t,formFields:this.fields,namespace:this.namespace};Liferay.fire("".concat(this.namespace).concat(i.CP_INSTANCE_CHANGED),n)}}))}checkCPInstanceOptions(){let e=!1;for(const t of this.fields){if(t.required)if(t.value.length)for(const n of t.value){if(null===n||""===n){e=!0;break}e=!1}else e=!0;if(e)break}return e}}var r=DDMFormHandler;t.default=r}}));
//# sourceMappingURL=DDMFormHandler.js.map