var TB_Revisions;((t,i)=>{"use strict";TB_Revisions={async init(i){const e=i.classList;if(e.contains("save_revision")||e.contains("load_revision"))try{await t.LightBox.save(),e.contains("save_revision")?await this.saveRevision():await this.loadRevision(i)}catch(i){throw t.Spinner.showLoader("spinhide"),i}},async loadRevision(e){const s=e.getBoundingClientRect(),a=await this.ajax({action:"tb_load_revision_lists"},"text");t.LightBox.el.classList.add("tb_revision_lightbox"),t.LightBox.setStandAlone(s.left,s.top),await t.Spinner.showLoader("done");const o=(await t.LightBox.open({contructor:!0,loadMethod:"html",save:!1,data:{revision:{html:a.trim()}}})).tfClass("tb_revision_lists")[0],r=t=>{const i=t.target.closest(".js-builder-restore-revision-btn,.js-builder-delete-revision-btn");i&&(t.preventDefault(),t.stopPropagation(),i.classList.contains("js-builder-restore-revision-btn")?this.restore(i.dataset.id):this.delete(i))};o?.tfOn(i.click,r),i.on("themify_builder_lightbox_close",(t=>{o?.tfOff(i.click,r),t.classList.remove("tb_revision_lightbox")}),!0)},ajax:(i,e)=>(t.Spinner.showLoader(),t.LocalFetch({sourceEditor:t.isFrontend?"frontend":"backend",...i},e)),async saveRevision(){t.Spinner.showLoader("spinhide");try{const i=await t.LiteLightBox.prompt("enterRevComment");if(!i||"yes"!==i[0])throw"canceled";await t.LightBox.save();const e=t.Builder.get(),s={action:"tb_save_revision",rev_comment:i[1]||"",data:JSON.stringify(e.toJSON(!0)),custom_css:e.customCss},a=themifyBuilder.i18n.label.revSaved.replaceAll("%rev_title%",s.rev_comment);try{const t=await this.ajax(s);if(!t.success)throw t.data}catch(t){try{s.data=new Blob([s.data],{type:"application/json"});if(!(await this.ajax(s)).success)throw t}catch(t){throw t}}await Promise.all([t.Spinner.showLoader("done"),TF_Notification.showHide("done",a.replaceAll("%post_title%",themifyBuilder.post_title),2500)])}catch(i){throw i&&"canceled"!==i&&(await t.Spinner.showLoader("error"),t.LiteLightBox.alert(i)),i}},async restore(i){const e=await t.LiteLightBox.confirm({msg:"confirmRestoreRev",buttons:{no:"save_no",yes:"save"}});if(e){"yes"===e&&await this.saveRevision();try{const e=await this.ajax({action:"tb_restore_revision_page",revid:i});if(!e.builder_data)throw e.data;t.LightBox.close(),t.Builder.get().reLoad(e)}catch(i){await t.Spinner.showLoader("error"),t.LiteLightBox.alert(i.message||i)}}},async delete(i){if("yes"===await t.LiteLightBox.confirm({msg:"confirmDeleteRev"})){t.Spinner.showLoader();try{const e=await this.ajax({action:"tb_delete_revision",revid:i.dataset.id});if(!e.success)throw e.data;await t.Spinner.showLoader("done"),i.closest("li").remove()}catch(i){await t.Spinner.showLoader("error"),t.LiteLightBox.alert(i.message||i)}}}}})(tb_app,Themify);