{% extends  'base.html.twig' %}

{% block body %}
	{{ block('nav', 'internal/libs/nav.html.twig') }}

	<main class="main-content position-relative max-height-vh-100 h-100 border-radius-lg ">
		{{ block('topnav', 'internal/libs/top-nav.html.twig') }}

		<div class="container-fluid py-2">
			<div class="row">
				<div class="col-12">
					<div class="card my-4">
						<div class="card-header p-0 position-relative mt-n4 mx-3 z-index-2">
							<div class="d-flex justify-content-between bg-gradient-dark shadow-dark border-radius-lg pt-4 pb-3 ps-3 p-2">
								<div>
									<h6 class="text-white text-capitalize ps-3">Travel Report</h6>
								</div>
								<div>
									<form action='{{ path('app_map_itinerary') }}' method='post' id='map-form' style='display:inline;'>
										<input type='hidden' name='caseId' id='caseId'/>
										<input type='hidden' name='caseStartDate' id='startDate'/>
                                        <input type='hidden' name='caseEndDate' id='endDate'/>
										<button type='button' class='btn bg-gradient-info btn-block mb-3' id='map-itinerary'>Map Itinerary</button>
									</form>
								</div>
							</div>
						</div>
						<div class="card-body px-0 pb-2">
							<div class=''>
								Filters:
								<select id='case-filter'>
									<option value=''>-- Select --</option>

									{% for c in cases %}
										<option value='{{ c.id }}'>{{ c.caseName }}</option>
									{% endfor %}
								</select>
								<input type='date' id='start-date-filter'/>
								<input type='date' id='end-date-filter'/>
							</div>

							<div class="table-responsive p-0">
								<table class="table align-items-center mb-0">
									<thead>
										<tr>
											<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Date</th>
											<th class='text-uppercase text-secondary text-xxs font-weight-bolder opacity-7'>Case</th>
											<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Origin</th>
											<th class='text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7'>Destination</th>
											<th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Duration</th>
											<th class='test-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7'>Distance</th>
											<th class="text-secondary opacity-7"></th>
										</tr>
									</thead>
									<tbody id='itineraryList'>
										{% for i in itineraries %}
											<tr>
												<td>{{ i.date|date('F j, Y', company_timezone) }}</td>
												<td>{{ i.memberCase.caseName }}</td>
												<td>{{ i.originLocation.name }}</td>
												<td>{{ i.destLocation.name }}</td>
												<td>{{ i.duration|date("%h:%i'%s''") }}</td>
												<td>{{ i.distance }}</td>
												<td></td>
											</tr>
										{% endfor %}
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</main>
{% endblock %}

{% block page_js %}
	<script type='module'>
		import $ from "{{ asset('vendor/jquery/jquery.index.js') }}";
import {filterItineraryByCase} from '{{ asset("js/app/filter.js") }}';
import {openMap} from '{{ asset("js/app/itinerary.js") }}';
window.$ = $;

$(function () {
document.getElementById('case-filter').addEventListener('change', filterItineraryByCase);
document.getElementById('start-date-filter').addEventListener('change', filterItineraryByCase);
document.getElementById('end-date-filter').addEventListener('change', filterItineraryByCase);
document.getElementById('map-itinerary').addEventListener('click', openMap);
});
	</script>
{% endblock %}
