Liferay.Loader.define("journal-web@5.0.151/js/article/Template",["module","exports","require","frontend-js-web"],(function(e,t,a){window;Object.defineProperty(t,"__esModule",{value:!0}),t.default=function _default({availableLocales:e,currentURL:t,ddmTemplateId:a,editDDMTemplateURL:l,namespace:d,previewArticleContentTemplateURL:c,selectDDMTemplateURL:m}){const i=[],namespaceId=e=>"".concat(d).concat(e),changeDDMTemplate=l=>{l&&l.ddmtemplateid===Number(a)||(0,n.openConfirmModal)({message:Liferay.Language.get("editing-the-current-template-deletes-all-unsaved-content"),onConfirm:a=>{if(a){const a=l&&l.ddmtemplateid||-1,d=(0,n.addParams)("".concat(namespaceId("ddmTemplateId"),"=").concat(a),t),c=document.getElementById(namespaceId("fm1"));c&&((0,n.setFormValues)(c,{availableLocales:e,ddmTemplateId:a,ddmTemplateKey:l&&l.ddmtemplatekey||"",ddmTemplateName:l&&l.name||""}),c.action=d,c.submit())}}})},o=document.getElementById(namespaceId("previewWithTemplate"));if(o){const previewWithTemplateButtonClick=()=>{const e=new URL(c);e.searchParams.append(namespaceId("ddmTemplateId"),a),e.searchParams.append(namespaceId("languageId"),function getCurrentLanguage(e){const t=Liferay.component("".concat(e,"titleMapAsXML"));if(t)return t.getSelectedLanguageId();return themeDisplay.getLanguageId()}(d)),(0,n.openSelectionModal)({iframeBodyCssClass:"",onSelect:e=>changeDDMTemplate(e),selectEventName:namespaceId("preview"),title:Liferay.Language.get("title"),url:e.href})};o.addEventListener("click",previewWithTemplateButtonClick),i.push({detach:()=>{o.removeEventListener("click",previewWithTemplateButtonClick)}})}const r=document.getElementById(namespaceId("clearDDMTemplate"));if(r){const clearDDMTemplateButtonClick=()=>{changeDDMTemplate(null)};r.addEventListener("click",clearDDMTemplateButtonClick),i.push({detach:()=>{r.removeEventListener("click",clearDDMTemplateButtonClick)}})}const s=document.getElementById(namespaceId("editDDMTemplate"));s&&(s.addEventListener("click",(()=>{(0,n.openConfirmModal)({message:Liferay.Language.get("editing-the-current-template-deletes-all-unsaved-content"),onConfirm:e=>e&&(0,n.navigate)(l)})})),i.push({detach:()=>{s.removeEventListener("click",s)}}));const p=document.getElementById(namespaceId("selectDDMTemplate"));p&&(p.addEventListener("click",(()=>{(0,n.openSelectionModal)({onSelect:e=>changeDDMTemplate(JSON.parse(e.value)),selectEventName:"selectDDMTemplate",title:Liferay.Language.get("templates"),url:m})})),i.push({detach:()=>{p.removeEventListener("click",p)}}));return{dispose:()=>{i.forEach((e=>e.detach()))}}};var n=a("frontend-js-web")}));
//# sourceMappingURL=Template.js.map