Liferay.Loader.define("@liferay/commerce-product-definitions-web@7.0.84/js/InstanceDetails",["module","exports","require","commerce-frontend-js/components/autocomplete/entry"],(function(e,t,n){window;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function _default(e){(function handleReplacements({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 handlePublish({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 handleDDMForm({cpDefinitionId:e,namespace:t}){const n=document.getElementById("".concat(t,"fm"));let a=[];function saveInstance(){const a=Liferay.component("ProductOptions".concat(e,"DDMForm")),o=document.getElementById("".concat(t,"ddmFormValues"));if(a){const e=a.getImmediateFields().map((e=>{const t={key:e.get("fieldName")},n=e.getValue();return t.value=Array.isArray(n)?n:[n],t}));o.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,o={key:n,value:e.payload.value};a.some((e=>e.key===n))?a=a.reduce(((e,t)=>e.concat(t.key===n?o:t)),[]):a.push(o);document.getElementById("".concat(t,"ddmFormValues")).value=JSON.stringify(a)}}))})),n.addEventListener("submit",saveInstance)}(e)};var a=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(n("commerce-frontend-js/components/autocomplete/entry"))}));
//# sourceMappingURL=InstanceDetails.js.map