AUI.add("liferay-inline-editor-base",(e=>{const t=e.Lang,a=t.isNumber,s=t.isString,i="bodyContent",o="alert alert-danger",c="alert alert-success";function InlineEditorBase(){const e=this;e.publish("saveFailure",{defaultFn:e._defSaveFailureFn}),e.publish("saveSuccess",{defaultFn:e._defSaveSuccessFn})}InlineEditorBase.ATTRS={autoSaveTimeout:{getter:"_getAutoSaveTimeout",validator:a,value:3e3},closeNoticeTimeout:{getter:"_getCloseNoticeTimeout",validator:a,value:8e3},editor:{validator:t.isObject},editorName:{validator:s},editorPrefix:{validator:s,value:"#cke_"},editorSuffix:{validator:s,value:"_original"},namespace:{validator:s},saveURL:{validator:s},toolbarTopOffset:{validator:a,value:30}},InlineEditorBase.prototype={_attachCloseListener(){const t=this.getEditNotice();t.footerNode.on("click",e.bind("hide",t))},_closeNoticeFn(){this.getEditNotice().hide()},_defSaveFailureFn(){const e=this;e.resetDirty();const t=e.getEditNotice();e._editNoticeNode.replaceClass(c,o),t.set(i,Liferay.Language.get("the-draft-was-not-saved-successfully")),t.show(),e.closeNotice()},_defSaveSuccessFn(e){const a=this;a.resetDirty();const s=a.getEditNotice();a._editNoticeNode.replaceClass(o,c);let r=Liferay.Language.get("the-draft-was-saved-successfully-at-x");e&&(r=Liferay.Language.get("the-draft-was-autosaved-successfully-at-x")),r=t.sub(r,[(new Date).toLocaleTimeString()]),s.set(i,r),s.show(),a.closeNotice()},_saveFn(e){const t=this;t.isContentDirty()&&t.save(e)},closeNotice(a){const s=this;let i=s._closeNoticeTask;i||(i=e.debounce(s._closeNoticeFn,s.get("closeNoticeTimeout"),s),s._closeNoticeTask=i),t.isNumber(a)?i.delay(a):i()},destructor(){const e=this;e.getEditNotice().destroy(),e._closeNoticeTask&&e._closeNoticeTask.cancel(),e._saveTask&&e._saveTask.cancel()},getEditNotice(){const t=this;let a=t._editNotice;if(!a){const s=e.one(t.get("editorPrefix")+t.get("editorName")),i=e.Node.create('<div class="alert alert-success lfr-editable-notice"><span class="lfr-editable-notice-text yui3-widget-bd"></span><a class="lfr-editable-notice-close ml-3 yui3-widget-ft" href="javascript:void(0);" tabindex="0"></a></div>');a=new e.OverlayBase({contentBox:i,footerContent:Liferay.Language.get("close"),visible:!1,zIndex:s.getStyle("zIndex")+2}).render(),t._editNoticeNode=i,t._editNotice=a,t._attachCloseListener()}return a},save(e){const t=this,a={content:t.get("editor").getData()},s=Liferay.Util.ns(t.get("namespace"),a);Liferay.Util.fetch(t.get("saveURL"),{body:Liferay.Util.objectToFormData(s),method:"POST"}).then((e=>e.json())).then((a=>{a?t.fire("saveSuccess",e):t.fire("saveFailure")})).catch((()=>t.fire("saveFailure")))},startSaveTask(){const t=this;let a=t._saveTask;return a&&a.cancel(),a=e.later(t.get("autoSaveTimeout"),t,t._saveFn,[!0],!0),t._saveTask=a,a},stopSaveTask(){const e=this._saveTask;return e&&e.cancel(),e}},Liferay.InlineEditorBase=InlineEditorBase}),"",{requires:["aui-base","aui-overlay-base-deprecated"]});
//# sourceMappingURL=inline_editor_base.js.map