<script>
$(document).ready(function() {
	$('#manual-sync').on('click', function(e) {
		$('.ajax-loader').show();
		$.ajax({
			type: "POST",
			url: "{{ route('collection-statistics-sync') }}",
			data: $('#search-form').serializeObject(),
			success: function(response) {
				if (response.status == 'success') {
					$('#success p').text('Report updated successfully.');
					$('#success').show();
					window.dataTable.draw();
				} else {
					$('#success').hide();
					$('#error p').text('Failed to refresh report data. Please try later.');
					$('#error').show();
				}
				$('.ajax-loader').hide();
			}
		})
	});
});
</script>
