var TB_Import;((t,e,i,o,r)=>{"use strict";TB_Import={el:null,init(t){const e=t.dataset.type;e&&("file"===e?this.t():this.i(t))},t(){t.Spinner.showLoader("spinhide"),t.Helper.loadJsZip(),i("input",{type:"file",accept:".zip,.txt,.json"}).tfOn("change",(t=>{t.currentTarget.remove(),this.fileImport(t.currentTarget.files[0])}),{passive:!0,once:!0}).click()},fileImport:e=>new Promise((async(i,a)=>{const s=await t.LiteLightBox.confirm({msg:"dialog_import_page_post",buttons:{no:"replace_builder",yes:"append_builder"}});if(s)try{t.Spinner.showLoader();const n=(e,o)=>{try{const r={custom_css:(e=JSON.parse(e)).custom_css};delete e.custom_css,o?r.used_gs=JSON.parse(o):e.used_gs&&(r.used_gs=e.used_gs,delete e.used_gs),e.builder_data&&(e=e.builder_data),r.builder_data=e,t.Builder.get().reLoad(r,"no"!==s).then(i).catch(a)}catch(t){throw t}};if("text/plain"===e.type||"application/json"===e.type){(new FileReader).tfOn("loadend",(function(e){try{if(this.readyState!==FileReader.DONE)throw"";n(e.target.result)}catch(e){t.Spinner.showLoader("error"),TF_Notification.showHide("error",r.importBuilderNotExist),a(e)}}),{passive:!0,once:!0}).readAsText(e)}else{if("application/x-zip-compressed"!==e.type&&"application/zip"!==e.type)throw Error(r.importWrongFormat);{await t.Helper.loadJsZip();const i=new JSZip,a=await i.loadAsync(e),s=a.files;if(!s)throw Error(r.zipFileEmpty);{const t="builder_data_export.txt",e="builder_gs_data_export.txt";if(s[t]===o)throw Error(r.importBuilderNotExist);{const i=[];i.push(a.file(s[t].name).async("text")),s[e]!==o&&i.push(a.file(s[e].name).async("text"));const r=await Promise.all(i);n(r[0],r[1])}}}}}catch(e){t.Spinner.showLoader("error"),e.message&&TF_Notification.showHide("error",e.message),a(e)}else i()})),async i(a){try{(t.isFrontend?window.top:window).Themify.loadCss(e.builder_url+"css/editor/components/import"),await t.LightBox.save(),t.Spinner.showLoader(),t.LightBox.el.classList.add("tb_import_post_lightbox");let s=async(e=1,i="")=>{try{return await t.LocalFetch({action:"builder_import",page:e,s:i},"html")}catch(e){throw t.Spinner.showLoader("error"),e}},n=await s(),c=a.closest("ul").getBoundingClientRect();t.LightBox.setStandAlone(c.left,c.top),await t.Spinner.showLoader("done");let p=(await t.LightBox.open({loadMethod:"html",contructor:!1,save:!1,data:n})).querySelector("#tb_lightbox_container"),l=async(e,i)=>{t.Spinner.showLoader();const o=await s(e,i);p.tfClass("tb_import_result")[0].replaceWith(o),t.Spinner.showLoader("spinhide")},_=e=>{e.preventDefault();const i=e.target?.closest("a");if(i?.dataset.id){const e={msg:"dialog_import_page_post",buttons:{no:"replace_builder",yes:"append_builder"}},a={action:"builder_import_submit",data:[i.dataset.id]};Object.keys(a.data).length>0?t.LiteLightBox.confirm(e).then((e=>{e&&(t.Spinner.showLoader(),t.LocalFetch(a).then((i=>{i.builder_data!==o?t.Builder.get().reLoad(i,"no"!==e):(t.Spinner.showLoader("error"),TF_Notification.showHide("error",r.postBuilderNotExist))})).catch((()=>{t.Spinner.showLoader("error")})))})):TF_Notification.showHide("error",r.importSelectPost)}else i?.classList.contains("page-numbers")&&l(i.textContent,h.value)},d=i("div",{class:"tb_import_search_wrap"}),h=i("input",{placeholder:r.search});h.tfOn("keyup",(t=>{l(1,t.currentTarget.value)}),{passive:!0}),d.appendChild(h),p.tfOn(e.click,_).prepend(d),e.on("themify_builder_lightbox_close",(t=>{p.tfOff(e.click,_),t.classList.remove("tb_import_post_lightbox"),p=t=l=s=_=h=null}),!0)}catch(e){throw t.Spinner.showLoader("error"),e}}}})(tb_app,Themify,tb_createElement,void 0,themifyBuilder.i18n.label);