AUI.add("liferay-staging",(()=>{const a={init(a){const i=this,e=a.namespace;i.markAsReadyForPublicationURL=a.markAsReadyForPublicationURL,i.layoutRevisionStatusURL=a.layoutRevisionStatusURL,i._namespace=e,i.viewHistoryURL=a.viewHistoryURL,Liferay.publish({fireOnce:!0}),Liferay.after("initStagingBar",(()=>{const a=document.body;if(a.classList.contains("has-staging-bar")){document.querySelector(".staging-bar-level-3-message")?a.classList.add("staging-ready-level-3"):a.classList.add("staging-ready")}})),Liferay.fire("initStagingBar",a)}};Liferay.StagingBar=a}),"",{requires:["aui-io-plugin-deprecated","aui-modal"]});

AUI.add("liferay-staging-branch",(a=>{const i=a.Lang,n=Liferay.StagingBar;a.mix(n,{_getBranchDialog(){const i=this;let n=i._branchDialog;if(!n){const t=i._namespace;n=Liferay.Util.Window.getWindow({dialog:{bodyContent:a.one("#"+t+"addBranch").show()},title:'Branch'}),i._branchDialog=n}return n},addBranch(a){const n=this._getBranchDialog();i.isValue(a)&&n.set("title",a),n.show()}})}),"",{requires:["liferay-staging"]});

AUI.add("liferay-staging-version",(e=>{const t=Liferay.StagingBar,a={redo:"redo_layout_revision",undo:"undo_layout_revision"},n={redo:'Are\x20you\x20sure\x20you\x20want\x20to\x20redo\x20your\x20last\x20changes\x3f',undo:'Are\x20you\x20sure\x20you\x20want\x20to\x20undo\x20your\x20last\x20changes\x3f'};e.mix(t,{_cleanup(){const t=this;t._eventHandles&&e.Array.invoke(t._eventHandles,"detach")},_onInit(){const t=this;t._cleanup();const a=t._namespace,n=[Liferay.on(a+"redo",t._onRevisionChange,t,"redo"),Liferay.on(a+"submit",t._onSubmit,t),Liferay.on(a+"undo",t._onRevisionChange,t,"undo"),Liferay.on(a+"viewHistory",t._onViewHistory,t)],o=e.one("#"+a+"layoutRevisionDetails"),i=e.one("#"+a+"layoutRevisionStatus");o&&n.push(Liferay.after("updatedLayout",(()=>{Liferay.Util.fetch(t.markAsReadyForPublicationURL).then((e=>e.text())).then((t=>{o.plug(e.Plugin.ParseContent),o.setContent(t),Liferay.fire("updatedStatus")})).catch((()=>{o.setContent('There\x20was\x20an\x20unexpected\x20error\x2e\x20Please\x20refresh\x20the\x20current\x20page\x2e')}))}))),i&&Liferay.after("updatedStatus",(()=>{Liferay.Util.fetch(t.layoutRevisionStatusURL).then((e=>e.text())).then((t=>{i.plug(e.Plugin.ParseContent),i.setContent(t)})).catch((()=>{i.setContent('There\x20was\x20an\x20unexpected\x20error\x2e\x20Please\x20refresh\x20the\x20current\x20page\x2e')}))})),t._eventHandles=n},_onRevisionChange(e,t){const o=this,i=a[t],r=n[t];Liferay.Util.openConfirmModal({message:r,onConfirm:t=>{t&&o._updateRevision(i,e.layoutRevisionId,e.layoutSetBranchId)}})},_onSubmit(t){const a=this._namespace,n=e.one("#"+a+"layoutRevisionDetails"),o=n.one(".layout-revision-info");o&&o.addClass("loading");const i=e.one("#"+a+"submitLink");i&&i.html('Loading'+"..."),Liferay.Util.fetch(t.publishURL).then((()=>{t.incomplete?location.href=t.currentURL:Liferay.fire("updatedLayout")})).catch((()=>{n.addClass("alert alert-danger"),n.setContent('There\x20was\x20an\x20unexpected\x20error\x2e\x20Please\x20refresh\x20the\x20current\x20page\x2e')}))},_onViewHistory(){Liferay.Util.openWindow({dialog:{after:{destroy(){window.location.reload()}},destroyOnHide:!0},title:'History',uri:t.viewHistoryURL})},_updateRevision(e,t,a){const n={cmd:e,layoutRevisionId:t,layoutSetBranchId:a,p_auth:Liferay.authToken,p_l_id:themeDisplay.getPlid(),p_v_l_s_g_id:themeDisplay.getSiteGroupId()};Liferay.Util.fetch(themeDisplay.getPathMain()+"/portal/update_layout",{body:Liferay.Util.objectToFormData(n),method:"POST"}).then((()=>{window.location.reload()})).catch((()=>{Liferay.Util.openToast({message:'There\x20was\x20an\x20unexpected\x20error\x2e\x20Please\x20refresh\x20the\x20current\x20page\x2e',toastProps:{autoClose:1e4},type:"warning"})}))},destructor(){this._cleanup()}}),Liferay.on("initStagingBar",t._onInit,t)}),"",{requires:["aui-button","liferay-staging"]});

