jQuery(document).ready((function(t){function a(){t.ajax({type:"POST",url:betterByDefaultActivityLogs.ajaxUrl,data:{action:"activity_logs_data",security:betterByDefaultActivityLogs.ajax_nonce},beforeSend:function(){t(document).find(".activity-logs-container").html('<div class="activity-logs-loader-three-main"><div class="activity-logs-loader-three"><span></span><span></span></div></div>')},success:function(a){1===a.success?(t(document).find(".activity-logs-container").html(a.content),t(document).find(".activity-logs-table").length>0&&(t(document).find(".activity-logs-table").DataTable({order:[[4,"desc"]],columnDefs:[{width:"20%",targets:0},{targets:4,type:"date",render:function(t,a,e){return console.log(t),t=t.replace("<br>"," "),new Date(t).toISOString()}}],dom:'lf<"toolbar">rtip',initComplete:function(){t("div.toolbar").html('\n                                    <select id="flush-log-range">\n                                        <option value="7">Retain Last 7 Days</option>\n                                        <option value="15">Retain Last 15 Days</option>\n                                        <option value="30">Retain Last 30 Days</option>\n                                        <option value="all">Flush All Logs</option>\n                                    </select>\n                                    <button type="button" id="activity-data-flush-btn" class="button button-primary">Flush Log</button>\n                                ')}}),t(document).find(".activity-logs-table").wrap('<div class="activity-logs-table-container" />'))):t(document).find(".activity-logs-container").html("<p>Error loading activity logs. Please try again.</p>")},error:function(a,e,o){console.error("Table data AJAX request failed:",e,o),t(document).find(".activity-logs-container").html("<p>An error occurred while loading the logs. Please try again later.</p>")}})}t(document).find(".activity-logs-container").length>0&&a(),t(document).on("click","button#activity-data-flush-btn",(function(){var e=t("#flush-log-range").val();!0===confirm("30"===e?"Please ensure that the last 30 days of data is retained, while all older log data is removed. Do you want to flush log data?":"7"===e?"Please ensure that the last 7 days of data is retained, while all older log data is removed. Do you want to flush log data?":"15"===e?"Please ensure that the last 15 days of data is retained, while all older log data is removed. Do you want to flush log data?":"All log data will be removed. Do you want to flush all log data?")&&t.ajax({type:"POST",url:betterByDefaultActivityLogs.ajaxUrl,data:{action:"activity_logs_data_flush",range:e,security:betterByDefaultActivityLogs.ajax_nonce},beforeSend:function(){t(document).find(".activity-logs-container").html('<div class="activity-logs-loader-three-main"><div class="activity-logs-loader-three"><span></span><span></span></div></div>')},success:function(t){1===t.success?a():2===t.success?("7"===e?alert("No logs older than the last 7 days were found."):"15"===e?alert("No logs older than the last 15 days were found."):"30"===e&&alert("No logs older than the last 30 days were found."),a()):alert("Error: Could not flush the logs.")},error:function(t,a,e){console.error("Flush log AJAX request failed:",a,e),alert("An error occurred while flushing the logs. Please try again.")}})}))}));