class l{constructor(){this.chartHandlers={},this.init(),this.observer={}}init(){this.bindElementorInit()}bindElementorInit(){let e=!1;const n=()=>{e||window.elementorFrontend&&window.elementorFrontend.elementsHandler&&(e=!0,window.elementorFrontend.hooks.addAction("frontend/element_ready/widget",t=>{const r=t.find(".graphina-tree-chart");r.length>0&&this.initializeTables(r)}))};window.elementorFrontend&&window.elementorFrontend.elementsHandler&&n(),jQuery(window).on("elementor/frontend/init",()=>{setTimeout(n,50)}),jQuery(document).ready(()=>{if(!e){const t=jQuery(".graphina-tree-chart");t.length>0&&t.each((r,a)=>{this.initializeTables(jQuery(a))})}})}handleElementorWidgetInit(){elementorFrontend.hooks.addAction("frontend/element_ready/widget",e=>{const n=e.find(".graphina-tree-chart");n.length>0&&this.initializeTables(n)})}initializeTables(e){this.observeTableElement(e,"tree")}observeTableElement(e,n){const t=e.data("element_id");gcfe_public_localize.view_port==="off"?(this.observer[t]||(this.observer[t]=new IntersectionObserver(r=>{r.forEach(a=>{a.isIntersecting&&(this.setupTree(jQuery(a.target),n),this.observer[t].unobserve(a.target))})},{threshold:.1})),this.observer[t].observe(e[0])):this.setupTree(e,n)}getDynamicTreeData(e,n,t){let r=jQuery(`[data-element_id="${t}"]`).closest("[data-elementor-id]").data("elementor-id");return new Promise((a,i)=>{jQuery.ajax({url:gcfe_public_localize.ajaxurl,type:"POST",dataType:"json",data:{action:"graphina_get_dynamic_tree_data",nonce:gcfe_public_localize.tree_nonce,chartType:"tree",post_id:r,element_id:t,series_count:0,settings:JSON.stringify(e)},success:o=>{a(o)},error:o=>{console.error("AJAX Error:",o),i(new Error("AJAX request failed."))}})})}addContentLists(e,n,t){const r=parent.document.querySelector(`[data-setting="${n.graphina_prefix}${t}_available_tree_columns"`);if(r){r.innerHTML="";try{r.value=e}catch(a){console.log(a)}}}async setupTree(e,n){const t=e.data("element_id"),r=e.data("chart_options");let a=e.data("chart_data");const i=e.data("extra_data"),o=e.data("settings");r.nodeTemplate=s=>{const d=i.tree_template;return new Function("content",`return \`${d}\`;`)(s)};try{if(i.chart_data_option===!0){const d=await this.getDynamicTreeData(o,i,t);this.addContentLists(d.chart_data.columns,i,n),a=d.chart_data.tree_data,jQuery(document).find(`.graphina-${t}-loader`).hide()}new ApexTree(e,r).render(a)}catch(s){console.log(s)}}}new l;
//# sourceMappingURL=tree.js.map
