((t,e,r)=>{"use strict";t.Library=class{static#t=new Map;static#e;constructor(e){this.el=e,this.constructor.#e?this.init():t.LocalFetch({action:"tb_get_library_items",part:"all"}).then((t=>{this.constructor.#e=t,this.init()})).catch((e=>{t.Spinner.showLoader("error"),this.el.innerHTML="<h3>Failed to load Library Items.</h3>"}))}init(){this.el.tfOn(Themify.click,(t=>{this.remove(t)}),{passive:!0}).appendChild(this.constructor.create(this.constructor.#e)),this.el.tfClass("tf_loader")[0]?.remove(),Themify.triggerEvent(this.el.previousElementSibling.tfClass("current")[0],Themify.click)}remove(r){if(r.target.closest(".remove_item_btn")){r.stopPropagation();let i=r.target.closest(".library_item"),s=i.dataset.type;t.LiteLightBox.confirm({msg:themifyBuilder.i18n.label[s+"LibraryDeleteConfirm"]}).then((o=>{if("yes"===o){const o=""+i.dataset.slug,a={action:"tb_remove_library_item",id:o};t.Spinner.showLoader(),t.LocalFetch(a,"text").then((i=>{if(!i)throw"";t.Spinner.showLoader("done");for(let e=[t.MainPanel.el,t.SmallPanel.el],i=e.length-1;i>-1;--i){let t=e[i].querySelector(".tb_item_"+s+'[data-slug="'+o+'"]'),a=e[i].querySelector(".library_tab .current");t&&(t.remove(),a&&Themify.triggerEvent(a,r.type))}if("part"===s){const t=e.tfClass("themify_builder_content-"+o),r=ThemifyConstructor.layoutPart.data;for(let e=t.length-1;e>-1;--e){let r=t[e].closest(".active_module");r?r.remove():t[e].remove()}for(let t=r.length-1;t>-1;--t)if(""+r[t].id===o){ThemifyConstructor.layoutPart.data.splice(t,1);break}}})).catch((e=>{t.Spinner.showLoader("error")}))}}))}}static create(t){const i=e.createDocumentFragment();i.appendChild(r("span","tb_no_content tf_hide","No library content found."));for(let e=0;e<t.length;++e){let s=t[e].post_type,o=s.includes("_rows",5)?"row":s.includes("_module",5)?"module":"part",a=r("",{class:"library_item tf_rel tf_box tb_item_"+o,draggable:!0,"data-type":o,"data-slug":t[e].id},t[e].post_title||"");a.appendChild(r("button",{type:"button",class:"add_module_btn remove_item_btn tb_disable_sorting tf_close"})),i.appendChild(a)}return i}static async get(e,r){const i=this.#t.get(e);return i||(t.Spinner.showLoader(),t.LocalFetch({action:"tb_get_library_item",type:r,id:e}).then((i=>{if("success"!==i.status)throw"";return i.content.gs&&(t.GS.styles={...t.GS.styles,...i.content.gs},delete i.content.gs),"part"!==r&&t.Helper.clearElementId([i.content]),this.#t.set(e,i.content),t.Spinner.showLoader("done"),i.content})).catch((()=>{t.Spinner.showLoader("error")})))}}})(tb_app,document,tb_createElement);