class h{constructor(){this.tableHandlers={},this.tableId="",this.dataTable={},this.initializedTables={},this.init(),this.observer={}}init(){this.setUpTableHandler(),this.bindEventHandlers()}bindEventHandlers(){jQuery(window).on("elementor/frontend/init",this.handleElementorWidgetInit.bind(this)),jQuery(window).on("load",()=>{jQuery(".graphina-jquery-data-table").each((a,l)=>{this.initializeTables(jQuery(l))})}),jQuery(document.body).off("click",".graphina-filter-div-button"),jQuery(document.body).on("click",".graphina-filter-div-button",this.debounce(this.handleChartFilterTable.bind(this),300))}debounce(a,l){let e;return function(...t){const r=this;clearTimeout(e),e=setTimeout(()=>a.apply(r,t),l)}}handleChartFilterTable(a){const l=a.currentTarget,e=jQuery(l).data("element_id"),t=jQuery(`.graphina-jquery-data-table[data-element_id="${e}"]`);t.length>0&&this.setupTable(t,[])}handleElementorWidgetInit(){elementorFrontend.hooks.addAction("frontend/element_ready/data_table_lite.default",a=>{console.log("Initializing jQuery Data Table...");const l=a.find(".graphina-jquery-data-table");l.length>0&&this.initializeTables(l)})}initializeTables(a){const l=a.data("chart_type");this.tableHandlers[l]&&this.tableHandlers[l](a)}setUpTableHandler(){this.tableHandlers={data_table_lite:a=>this.observeTableElement(a,"data_table_lite")}}observeTableElement(a,l){const e=a.data("element_id");if(elementorFrontend.isEditMode()){this.setupTable(a,l);return}this.initializedTables[e]||(gcfe_public_localize.view_port==="off"?(this.observer[e]||(this.observer[e]=new IntersectionObserver(t=>{t.forEach(r=>{r.isIntersecting&&(this.setupTable(jQuery(r.target),l),this.observer[e].unobserve(r.target))})},{threshold:.1})),this.observer[e].observe(a[0])):this.setupTable(a,l))}getDynamicData(a,l,e,t){let r=jQuery(`[data-element_id="${e}"]`).closest("[data-elementor-id]").data("elementor-id");return new Promise((o,s)=>{jQuery.ajax({url:gcfe_public_localize.ajaxurl,type:"POST",dataType:"json",data:{action:"get_jquery_datatable_data",nonce:gcfe_public_localize.table_nonce,chartType:"data_table_lite",post_id:r,element_id:e,series_count:0,settings:JSON.stringify(a),selected_field:t},success:i=>{jQuery("#data_table_lite_loading_"+e).hide(),jQuery("#data_table_lite_no_data_"+e).hide(),o(i)},error:i=>{jQuery("#data_table_lite_loading_"+e).hide(),jQuery("#data_table_lite_no_data_"+e).hide(),console.error("AJAX Error:",i),s(new Error("AJAX request failed."))}})})}sanitizeTableOptions(a){const l=e=>{if(typeof e=="string")return e.replace(/<[^>]*>/g,"").replace(/javascript:/gi,"");if(Array.isArray(e))return e.map(l);if(typeof e=="object"&&e!==null){const t={};for(const r in e)t[r]=l(e[r]);return t}return e};return l(a)}async setupTable(a,l){const e=a.data("element_id");this.tableId=e,this.initializedTables[e]=!0;let t=this.sanitizeTableOptions(a.data("chart_data"));const r=this.sanitizeTableOptions(a.data("extra_data")),o=this.sanitizeTableOptions(a.data("settings")),s=".data_table_lite_"+e;if(r.hide_column_header&&(t.headerCallback=function(i,c,n,d,b){jQuery(i).hide()}),t.fnInitComplete=()=>{jQuery(".dataTables_scrollBody").css({overflow:"hidden",border:"0"}),jQuery(`#data_table_lite_${e} thead th`).addClass("all graphina-datatable-columns"),jQuery(`#data_table_lite_${e} tbody td`).addClass("graphina-datatable-tbody-td");const i=jQuery(".dataTables_scrollFoot");i.css("overflow","auto"),i.on("scroll",function(){jQuery(".dataTables_scrollBody").scrollLeft(jQuery(this).scrollLeft())})},t.rowCallback=function(i,c,n){n%2===0?jQuery(i).addClass("odd"):jQuery(i).addClass("even")},this.dataTable[e]&&(this.dataTable[e].clear().destroy(),jQuery(s).empty()),r.is_dynamic_table){let i=[];const c=jQuery(`#graphina_chart_filter_${e}`).data("total_filter");for(let d=0;d<c;d++)i[d]=jQuery(`#graphina-start-date_${d}${e}`).val()??jQuery(`#graphina-drop_down_filter_${d}${e}`).val();const n=await this.getDynamicData(o,r,e,i);n.data.body.length!==0&&n.data.header.length!==0?(t.data=n.data.body,t.columns=n.data.header,jQuery("#data_table_lite_loading_"+e).hide()):jQuery("#data_table_lite_loading_"+e).show()}else t.columns.length>0&&jQuery("#data_table_lite_loading_"+e).hide();r.table_footer&&t.columns&&t.columns.length>0&&jQuery(s).append("<tfoot><tr>"+t.columns.map(i=>`<th class="${r.header_class}">${typeof i=="object"&&i.title?i.title:i}</th>`).join("")+"</tr></tfoot>"),this.dataTable[e]=jQuery(s).DataTable(t),r.table_data_direct&&(this.dataTable[e].destroy(),jQuery(s).empty(),r.table_footer&&t.columns&&t.columns.length>0&&jQuery(s).append("<tfoot><tr>"+t.columns.map(i=>`<th class="${r.header_class}">${typeof i=="object"&&i.title?i.title:i}</th>`).join("")+"</tr></tfoot>"),this.dataTable[e]=jQuery(s).DataTable(t))}}window.graphinaDataTable=new h;
//# sourceMappingURL=data_table.js.map
