<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
	<title>AIL-Framework</title>
	<link rel="icon" href="{{ url_for('static', filename='image/ail-icon.png')}}">
	<!-- Core CSS -->
	<link href="{{ url_for('static', filename='css/bootstrap4.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/font-awesome.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/daterangepicker.min.css') }}" rel="stylesheet">
	<link href="{{ url_for('static', filename='css/dataTables.bootstrap.min.css') }}" rel="stylesheet">

	<!-- JS -->
 	<script src="{{ url_for('static', filename='js/jquery.js')}}"></script>
	<script src="{{ url_for('static', filename='js/jquery.dataTables.min.js')}}"></script>
 	<script src="{{ url_for('static', filename='js/popper.min.js')}}"></script>
 	<script src="{{ url_for('static', filename='js/bootstrap4.min.js')}}"></script>
	<script src="{{ url_for('static', filename='js/dataTables.bootstrap.min.js')}}"></script>
 	<script language="javascript" src="{{ url_for('static', filename='js/moment.min.js') }}"></script>
 	<script language="javascript" src="{{ url_for('static', filename='js/jquery.daterangepicker.min.js') }}"></script>

</head>
<body>

	{% include 'nav_bar.html' %}

	<div class="container-fluid">
		<div class="row">

			{% include 'crawler/menu_sidebar.html' %}

			<div class="col-12 col-lg-10" id="core_content">

				<div class="row">
					<div class="col-12 col-xl-6">

						{% for date in date_range %}
							{% if domains_by_day[date]%}
							<div class="card text-center mt-1 mb-3">
								<div class="card-header bg-dark text-white">
									<div class="row">
										<div class="col-6">
											<h3 style="text-align:center;">{{'{}/{}/{}'.format(date[0:4], date[4:6], date[6:8])}}</h3>
										</div>
										<div class="col-6">
											<a href="{{ url_for('hiddenServices.show_domains_by_daterange') }}?service_type={{type}}&domains_up=True&date_from={{date}}&date_to={{date}}" class="badge badge-success">{{ stats_by_date[date]['domain_up'] }}</a> UP
        							<a href="{{ url_for('hiddenServices.show_domains_by_daterange') }}?service_type={{type}}&domains_down=True&date_from={{date}}&date_to={{date}}" class="badge badge-danger ml-md-3">{{ stats_by_date[date]['domain_down'] }}</a> DOWN
										</div>
									</div>
								</div>
								<div class="card-body px-1">

									<table id="table_{{date}}" class="table table-striped table-bordered">
									  <thead class="bg-dark text-white">
									    <tr>
									      <th>Domain</th>
									      <th>First Seen</th>
												<th>Last Check</th>
									      <th>Status</th>
									    </tr>
									  </thead>
								    <tbody>
											{% for domain in domains_by_day[date] %}
									      <tr>
									        <td>
														<a target="_blank" href="{{ url_for('hiddenServices.show_domain') }}?domain={{ domain }}">{{ domain }}</a>
														<div>
															{% for tag in domain_metadata[domain]['tags'] %}
															<a href="{{ url_for('Tags.Tags_page') }}?date_from={{date}}&date_to={{date}}&ltags={{ tag }}">
																<span class="badge badge-{{ bootstrap_label[loop.index0 % 5] }} pull-left">{{ tag }} <i>{{ domain_metadata[domain]['tags'][tag] }}</i></span>
															</a>
															{%  endfor %}
														</div>
													</td>
									        <td>{{'{}/{}/{}'.format(domain_metadata[domain]['first_seen'][0:4], domain_metadata[domain]['first_seen'][4:6], domain_metadata[domain]['first_seen'][6:8])}}</td>
													<td>{{'{}/{}/{}'.format(domain_metadata[domain]['last_check'][0:4], domain_metadata[domain]['last_check'][4:6], domain_metadata[domain]['last_check'][6:8])}}</td>
									        <td><div style="color:{{domain_metadata[domain]['status_color']}}; display:inline-block">
																<i class="fas {{domain_metadata[domain]['status_icon']}}"></i>
																{{domain_metadata[domain]['status_text']}}
															</div>
													</td>
									      </tr>
											{% endfor %}
								    </tbody>
								  </table>

								</div>
							</div>
						{% endif %}
					{% endfor %}

					</div>
					<div class="col-12 col-xl-6">
						{% include 'crawler/show_domains_by_daterange.html' %}
					</div>
				</div>

			</div>
		</div>
	</div>

</body>

<script>
$(document).ready(function(){
	$("#page-Crawler").addClass("active");

	$('#date-range-from').dateRangePicker({
			separator : ' to ',
			getValue: function(){
					if ($('#date-range-from-input').val() && $('#date-range-to-input').val() )
							return $('#date-range-from-input').val() + ' to ' + $('#date-range-to-input').val();
					else
							return '';
					},
					setValue: function(s,s1,s2){
							$('#date-range-from-input').val(s1);
							$('#date-range-to-input').val(s2);
					}
	});
	$('#date-range-to').dateRangePicker({
			separator : ' to ',
			getValue: function(){
					if ($('#date-range-from-input').val() && $('#date-range-to-input').val() )
							return $('#date-range-from-input').val() + ' to ' + $('#date-range-to-input').val();
					else
							return '';
			},
			setValue: function(s,s1,s2){
					$('#date-range-from-input').val(s1);
					$('#date-range-to-input').val(s2);
			}
	});

		{% for date in date_range %}
			$('#table_{{date}}').DataTable({
				"aLengthMenu": [[5, 15, 30, -1], [5, 15, 30, "All"]],
				"iDisplayLength": 15,
				"order": [[ 0, "asc" ]]
			});
		{% endfor %}

});


function toggle_sidebar(){
	if($('#nav_menu').is(':visible')){
		$('#nav_menu').hide();
		$('#side_menu').removeClass('border-right')
		$('#side_menu').removeClass('col-lg-2')
		$('#core_content').removeClass('col-lg-10')
	}else{
		$('#nav_menu').show();
		$('#side_menu').addClass('border-right')
		$('#side_menu').addClass('col-lg-2')
		$('#core_content').addClass('col-lg-10')
	}
}
</script>

</html>
