Liferay.Loader.define("@liferay/commerce-product-definitions-web@7.0.66/js/InstanceDetails",["module","exports","require","commerce-frontend-js/components/autocomplete/entry"],(function(e,t,n){var o;window;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function(e){(function({initialLabel:e,initialValue:t,namespace:n}){const o=document.getElementById("".concat(n,"discontinued")),c=document.getElementById("".concat(n,"discontinuedDate")),d=document.getElementById("".concat(n,"replacementAutocompleteWrapper"));o.addEventListener("change",(e=>{e.target.checked?(c.disabled=!1,c.classList.remove("disabled"),d.classList.remove("d-none")):(c.disabled=!0,c.classList.add("disabled"),d.classList.add("d-none"))})),(0,a.default)("autocomplete","autocomplete-root",{apiUrl:"/o/headless-commerce-admin-catalog/v1.0/skus",initialLabel:e,initialValue:t,inputId:"replacementId",inputName:"".concat(n,"replacementCPInstanceId"),itemsKey:"id",itemsLabel:"sku",showDeleteButton:!0})})(e),function({WORKFLOW_ACTION_PUBLISH:e,namespace:t}){document.getElementById("".concat(t,"publishButton")).addEventListener("click",(()=>{const n=document.getElementById("".concat(t,"workflowAction"));n&&(n.value=e)}))}(e),function({cpDefinitionId:e,namespace:t}){const n=document.getElementById("".concat(t,"fm"));let o=[];function a(){const o=Liferay.component("ProductOptions".concat(e,"DDMForm")),a=document.getElementById("".concat(t,"ddmFormValues"));if(o){const e=o.getImmediateFields().map((e=>{const t={key:e.get("fieldName")},n=e.getValue();return t.value=Array.isArray(n)?n:[n],t}));a.value=JSON.stringify(e)}submitForm(n)}Liferay.componentReady("ProductOptions".concat(e)).then((e=>{e.unstable_onEvent((e=>{if("field_change"===e.type){const n=e.payload.fieldInstance.fieldName,a={key:n,value:e.payload.value};o.some((e=>e.key===n))?o=o.reduce(((e,t)=>e.concat(t.key===n?a:t)),[]):o.push(a);document.getElementById("".concat(t,"ddmFormValues")).value=JSON.stringify(o)}}))})),n.addEventListener("submit",a)}(e)};var a=(o=n("commerce-frontend-js/components/autocomplete/entry"))&&o.__esModule?o:{default:o}}));
//# sourceMappingURL=InstanceDetails.js.map