{% 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">Referral List</h6>
								</div>
								{% if is_granted('ROLE_ADMIN') or is_granted('ROLE_CASE_MANAGER') %}
								<div>
									<button type="button" class="btn btn-block btn-light mb-3" onclick="window.open('{{ path('app_case_add_referral', {id: case.id}) }}', '_self')">Add Referral</button>
								</div>
								{% endif %}
							</div>
						</div>
						<div class="card-body px-0 pb-2">
							<div>
								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">Referral ID</th>
											<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Service</th>
											<th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Hours Rem</th>
											<th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">End Date</th>
											<th class="text-secondary opacity-7"></th>
										</tr>
									</thead>
									<tbody>
										{% for r in openReferrals %}
											{% set dateEndWarning = '' %}
											{% if date('+14 days') >= r.endDate %}
												{% set dateEndWarning = 'bg-gradient-danger text-white' %}
											{% elseif date('+28 days') >= r.endDate %}
												{% set dateEndWarning = 'bg-gradient-faded-warning' %}
											{% endif %}
											<tr>
												<td>
													<h6 class='mb-0 text-small'>{{ r.referralId }}</h6>
												</td>
												<td>
													<p class='text-xs font-weight-bold mb-0'>{{ r.serviceCode.value }}</p>
												</td>
												<td class='text-center {% if r.getHoursRemaining() < 40 %}bg-gradient-danger text-white{% endif %}'>
													<p class='text-xs font-weight-bold mb-0'>{{ r.hours }} / {{ r.getHoursRemaining() }}</p>
												</td>
												<td class='text-center {{ dateEndWarning }}'>
													<p class='text-xs font-weight-bold mb-0'>{{ r.endDate|date("M j, Y") }}</p>
												</td>
												<td class='text-center'>
													<a href='{{ path('app_case_edit_referral', {caseId: case.id, referralId: r.id}) }}' class='' title='Edit Referral' data-toggle='tooltip'>
														<i class="material-symbols-rounded opacity-5">edit</i>
													</a>
													<a href='/index.php/list-notes/{{ r.id }}' class='' title='List Notes' data-toggle='tooltip'>
														<i class='material-symbols-rounded opacity-5'>edit_note</i>
													</a>
													<a href='#' class='' title='Close Referral' data-toggle='tooltip'>
														<i class='material-symbols-rounded opacity-5'>close</i>
													</a>
												</td>
											</tr>
										</td>
									</tbody>
								</tr>
							{% endfor %}
						</tbody>
					</table>
				</div>
			</div>
			<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">Closed Referrals</h6>
								</div>
							</div>
						</div>
						<div class="card-body px-0 pb-2">
							<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">Referral ID</th>
											<th class="text-uppercase text-secondary text-xxs font-weight-bolder opacity-7 ps-2">Service</th>
											<th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Discharge Reason</th>
											<th class="text-center text-uppercase text-secondary text-xxs font-weight-bolder opacity-7">Discharge Date</th>
											<th class="text-secondary opacity-7"></th>
										</tr>
									</thead>
									<tbody>
										{% for r in closedReferrals %}
											<tr>
												<td>
													<h6 class='mb-0 text-small'>{{ r.referralId }}</h6>
												</td>
												<td>
													<p class='text-xs font-weight-bold mb-0'>{{ r.serviceCode.value }}</p>
												</td>
												<td>
													<p class='text-xs font-weight-bold mb-0'>{{ r.dischargeReason.value }}</p>
												</td>
												<td>
													<p class='text-xs font-weight-bold mb-0'>{{ r.dischargeDate|date("F j, Y", company_timezone) }}</p>
												</td>
												<td class='align-right'></td>
											</tr>
										</td>
									</tbody>
								</tr>
							{% endfor %}
						</tbody>
					</table>
				</div>
			</div>

		</div>
	</main>
{% endblock %}
