Liferay.Loader.define("layout-taglib@16.0.1/render_layout_structure/js/InfoItemActionHandler",["module","exports","require","frontend-js-web"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function InfoItemActionHandler({executeInfoItemActionURL:e}){const t=new URL(window.location.href);if(t.searchParams.has("toastData")){try{openResultToast(JSON.parse(t.searchParams.get("toastData")))}catch(e){}t.searchParams.delete("toastData"),history.replaceState(null,document.head.title,t.href)}const r=document.querySelectorAll('[data-lfr-editable-type="action"]'),onClick=t=>{!function triggerAction(e,t){const{lfrClassNameId:r,lfrClassPk:n,lfrFieldId:o,lfrOnErrorInteraction:i,lfrOnErrorPageUrl:c,lfrOnErrorReload:l,lfrOnErrorText:d,lfrOnSuccessInteraction:u,lfrOnSuccessPageUrl:f,lfrOnSuccessReload:g,lfrOnSuccessText:p}=e.dataset;if(!o)return;const m=function getLoadingIndicator(){const e=document.createElement("span");return e.classList.add("d-inline-block","loading-animation","loading-animation-light","loading-animation-sm","ml-2","my-0"),e}();e.classList.add("disabled"),e.setAttribute("disabled",""),e.appendChild(m),Liferay.Util.fetch(new URL(t),{body:(0,a.objectToFormData)({classNameId:r,classPK:n,fieldId:o}),method:"POST"}).then((e=>e.json())).then((({error:t})=>{e.classList.remove("disabled"),e.removeAttribute("disabled"),e.removeChild(m),t?handleResult(i,l,d||t,s.error,c):handleResult(u,g,p,s.success,f)})).catch((()=>{e.classList.remove("disabled"),e.removeAttribute("disabled"),e.removeChild(m),openResultToast(s.error)}))}(t.target,e)};return r.forEach((e=>{e.addEventListener("click",onClick)})),{dispose(){r.forEach((e=>{e.removeEventListener("click",onClick)}))}}};var a=r("frontend-js-web");function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}const e="notification",n="page",o="url",s={error:{message:Liferay.Language.get("an-unexpected-error-occurred"),title:Liferay.Language.get("error"),type:"danger"},success:{message:Liferay.Language.get("your-request-completed-successfully"),title:Liferay.Language.get("success"),type:"success"}};function handleResult(t,r,s,i,c){if(t===e)if(r){const e=new URL(window.location.href),t=_objectSpread(_objectSpread({},i),{},{message:s||i.message});e.searchParams.set("toastData",JSON.stringify(t)),(0,a.navigate)(e)}else openResultToast(i,s);else[n,o].includes(t)?(0,a.navigate)(c):r&&window.location.reload()}function openResultToast({message:e,title:t,type:r},n){(0,a.openToast)({message:n||e,title:t,type:r})}}}));
//# sourceMappingURL=InfoItemActionHandler.js.map