Liferay.Loader.define("journal-web@5.0.114/js/DataEngineLayoutBuilderHandler.es",["module","exports","require","frontend-js-web"],(function(e,t,n){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function DataEngineLayoutBuilderHandler({namespace:e}){const t=document.getElementById("".concat(e,"fm")),getDataLayoutBuilder=()=>Liferay.componentReady("".concat(e,"dataLayoutBuilder")),getInputLocalizedValues=t=>{const n=Liferay.component("".concat(e).concat(t)),a={};if(n){n.get("translatedLanguages").values().forEach((e=>{a[e]=n.getValue(e)}))}return a},saveDataEngineStructure=async()=>{const n=await getDataLayoutBuilder(),{dataDefinition:r,dataLayout:o}=n.current.state,{defaultLanguageId:i}=r,c=document.getElementById("".concat(e,"name")),d=getInputLocalizedValues("name"),u=getInputLocalizedValues("description");if(!c.value&&!d[i])return(0,a.openToast)({message:(0,a.sub)(Liferay.Language.get("please-enter-a-valid-title-for-the-default-language-x"),i.replace("_","-")),title:Liferay.Language.get("error"),type:"danger"}),void c.focus();(t=>{const n=Liferay.component("".concat(e,"name"));if(n){const a=document.getElementById("".concat(e,"languageId")).value;if(!n.get("translatedLanguages").has(a)&&a!==t){n.updateInput("");const t=Liferay.Form.get("".concat(e,"fm"));t&&t.removeRule("".concat(e,"name"),"required")}}})(i),(0,a.postForm)(t,{data:{dataDefinition:JSON.stringify(_objectSpread(_objectSpread({},r.serialize()),{},{description:u,name:d})),dataLayout:JSON.stringify(_objectSpread(_objectSpread({},o.serialize()),{},{description:u,name:d}))}})};t.addEventListener("submit",saveDataEngineStructure);const detectClickOutside=async({target:t})=>{if(isElementInnerSelector(t,".cke_dialog",".ddm-form-builder-wrapper",".input-localized-content",".lfr-icon-menu-open",".multi-panel-sidebar")){(await getDataLayoutBuilder()).current.dispatch({submitButtonId:"".concat(e,"submitButton"),type:"sidebar_field_blur"})}};return window.addEventListener("mousedown",detectClickOutside,!0),Liferay.after("inputLocalized:localeChanged",(async e=>{const t=e.item.getAttribute("data-value"),n=await getDataLayoutBuilder();n.current.dispatch({payload:{languageId:t},type:"language_add"}),n.current.dispatch({payload:{editingLanguageId:t},type:"language_change"})})),{dispose(){t.removeEventListener("submit",saveDataEngineStructure),window.removeEventListener("mousedown",detectClickOutside,!0)}}};var a=n("frontend-js-web");function ownKeys(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,a)}return n}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(n),!0).forEach((function(t){_defineProperty(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):ownKeys(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const isElementInnerSelector=(e,...t)=>!t.some((t=>e.closest(t)))}}));
//# sourceMappingURL=DataEngineLayoutBuilderHandler.es.js.map