jQuery(document).ready((function($){$("#wf-sn-el-subtabs a").on("click",(function(e){e.preventDefault(),$("#wf-sn-el-subtabs a").removeClass("nav-tab-active"),$(".wf-sn-el-subtab").hide(),$(this).addClass("nav-tab-active");var t=$(this).attr("href");$(t).show()})),eventstable=jQuery("#sn-el-datatable").DataTable({processing:!0,serverSide:!0,ajax:{url:ajaxurl,type:"POST",data:function(e){e.action="get_events_data",e.nonce=datatables_object.nonce,e.action_filter=jQuery("#sn-el-action-filter").val()},error:function(e,t,a){var n="<strong>Error loading data:</strong><br>Status: "+e.status+" ("+e.statusText+")<br>Error: "+t+"<br>Code: "+a+"<br>Response: "+e.responseText;jQuery("#datatable-error").html(n).show()}},columns:[{data:"timestamp",title:"Time"},{data:"action",title:"Action"},{data:"user_id",title:"User"},{data:"description",title:"Event"},{data:"details",title:"Details",orderable:!1}],order:[[0,"desc"]],columnDefs:[{targets:4,data:null,defaultContent:"<button>Detail</button>"}]}),jQuery.post(ajaxurl,{action:"get_events_actions",nonce:datatables_object.nonce},(function(e){if(e.success&&e.data.actions){var t=jQuery("#sn-el-action-filter");t.empty(),t.append('<option value="">All Actions</option>'),e.data.actions.forEach((function(e){t.append('<option value="'+e+'">'+e+"</option>")}))}})),jQuery("#sn-el-action-filter").on("change",(function(){eventstable.ajax.reload()})),jQuery("#sn-el-reset-filter").on("click",(function(){jQuery("#sn-el-action-filter").val(""),eventstable.ajax.reload()})),$("#sn-el-datatable tbody").on("click","button",(function(e){e.preventDefault();var t=$(this).closest("tr"),a=eventstable.row(t);if(a.child.isShown())a.child.hide(),t.removeClass("shown"),$(this).removeClass("open");else{var n=t.find(".details-content").html();a.child(n).show(),t.addClass("shown"),$(this).addClass("open")}})),$("#sn-el-truncate").on("click",(function(e){if(e.preventDefault(),confirm("Are you sure you want to delete all log entries?")){var t={action:"sn_el_truncate_log",_ajax_nonce:wf_sn_el.nonce};$.post(ajaxurl,t,(function(e){e?(alert("All log entries have been deleted."),window.location.reload()):alert("Bad AJAX response. Please reload the page.")}))}}))}));