<script>
$(document).ready(function() {
	$("#search-form input[type=text]").on('keyup', function(e) {
		$("#search-form").submit();
	});

    getWidgetData(30);
	$('#widget_filter').change(function (e) {
		getWidgetData($(this).val());
	});
});

function getWidgetData (widgetFilterValue) {
	$.ajax({
		type: "GET",
		url: "{{ route('retrieval-statistics.widget-data') }}",
		data: { widget_filter: widgetFilterValue },
		dataType: 'JSON',
		success: function (result) {
			$("#terminations").html(result.terminationsCount);
			$("#assets_assigned").html(result.assetsAssignedCount);
			$("#assets_returned").html(result.assetsReturnedCount);
			$("#assets_unrecoverable").html(result.assetsUnrecoverableCount);
			$("#assets_pending").html(result.assetsPendingCount);
			$("#Average_return_time").html(result.averageReturnTime);
		}
	});
}
</script>