Liferay.Loader.define("journal-web@5.0.144/js/DataEngineLayoutBuilderHandler.es",["module","exports","require","frontend-js-web","./modals/openStructureKeyChangesModal"],(function(e,t,a){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=function DataEngineLayoutBuilderHandler({namespace:e,originalStructureKey:t,showStructureKeyChangesWarning:a}){const o=document.getElementById("".concat(e,"fm")),clearNameInputIfNeeded=t=>{const a=Liferay.component("".concat(e,"name"));if(a){const n=document.getElementById("".concat(e,"languageId")).value;if(!a.get("translatedLanguages").has(n)&&n!==t){a.updateInput("");const t=Liferay.Form.get("".concat(e,"fm"));t&&t.removeRule("".concat(e,"name"),"required")}}},getDataLayoutBuilder=()=>Liferay.componentReady("".concat(e,"dataLayoutBuilder")),getInputLocalizedValues=t=>{const a=Liferay.component("".concat(e).concat(t)),n={};if(a){a.get("translatedLanguages").values().forEach((e=>{n[e]=a.getValue(e)}))}return n},saveDataEngineStructure=async()=>{const i=await getDataLayoutBuilder(),{dataDefinition:c,dataLayout:u}=i.current.state,{defaultLanguageId:d}=c,s=document.getElementById("".concat(e,"name")),l=getInputLocalizedValues("name"),p=getInputLocalizedValues("description");if(!s.value&&!l[d])return(0,n.openToast)({message:(0,n.sub)(Liferay.Language.get("please-enter-a-valid-title-for-the-default-language-x"),d.replaceAll("_","-")),title:Liferay.Language.get("error"),type:"danger"}),void s.focus();const f=document.getElementById("".concat(e,"structureKey"));a&&f.value!==t?(0,r.default)({onSave:()=>{clearNameInputIfNeeded(d),(0,n.postForm)(o,{data:{dataDefinition:JSON.stringify(_objectSpread(_objectSpread({},c.serialize()),{},{description:p,name:l})),dataLayout:JSON.stringify(_objectSpread(_objectSpread({},u.serialize()),{},{description:p,name:l}))}})}}):(clearNameInputIfNeeded(d),(0,n.postForm)(o,{data:{dataDefinition:JSON.stringify(_objectSpread(_objectSpread({},c.serialize()),{},{description:p,name:l})),dataLayout:JSON.stringify(_objectSpread(_objectSpread({},u.serialize()),{},{description:p,name:l}))}}))};o.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"),a=await getDataLayoutBuilder();a.current.dispatch({payload:{languageId:t},type:"language_add"}),a.current.dispatch({payload:{editingLanguageId:t},type:"language_change"})})),{dispose(){o.removeEventListener("submit",saveDataEngineStructure),window.removeEventListener("mousedown",detectClickOutside,!0)}}};var n=a("frontend-js-web"),r=function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}(a("./modals/openStructureKeyChangesModal"));function ownKeys(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(a),!0).forEach((function(t){_defineProperty(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):ownKeys(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function _defineProperty(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}const isElementInnerSelector=(e,...t)=>!t.some((t=>e.closest(t)))}}));
//# sourceMappingURL=DataEngineLayoutBuilderHandler.es.js.map