<%# Leave colleagues have named the signed-in user to cover for them. Shown on every dashboard. %>
<% const asks = locals.coverRequests || []; if (asks.length) { %>
<section class="cover-requests" id="cover-requests" aria-label="Cover requests">
	<div class="cover-requests-head">
		
		<div><h2>Cover requests</h2><p>Colleagues have asked you to cover their duties while they're on leave.</p></div>
		<span class="cover-requests-count"><%= asks.length %> to answer</span>
	</div>
	<ul class="cover-request-list">
	<% asks.forEach(({ request, applicant }) => { const details = request.details || {}; const days = Number(details.days_requested || 0); %>
		<li class="cover-request">
			<span class="cover-request-avatar" aria-hidden="true"><%= initials(applicant?.full_name || '?') %></span>
			<div class="cover-request-main">
				<strong><%= applicant?.full_name || 'A colleague' %></strong>
				<small><%= applicant ? positionLabel(applicant.position_level) : '' %><%= applicant?.department ? ` · ${applicant.department}` : '' %></small>
				<p><span class="cover-request-type"><%= String(details.leave_type || 'leave').charAt(0).toUpperCase() + String(details.leave_type || 'leave').slice(1) %> leave</span> <%= details.start_date === details.end_date ? fmtDay(details.start_date) : `${fmtDay(details.start_date)} – ${fmtDay(details.end_date)}` %> · <%= days %> working day<%= days === 1 ? '' : 's' %></p>
			</div>
			<div class="cover-request-actions">
				<form method="post" action="/leave/<%= request.id %>/cover"><input type="hidden" name="decision" value="accepted"><button class="button small success" type="submit">&#10003; Accept</button></form>
				<details class="cover-decline">
					<summary class="button small outline">Decline</summary>
					<form method="post" action="/leave/<%= request.id %>/cover" class="cover-decline-form">
						<input type="hidden" name="decision" value="declined">
						<label>Reason (optional)<input name="note" maxlength="300" placeholder="e.g. I'm on a site visit that week"></label>
						<button class="button small danger" type="submit">Decline to cover</button>
					</form>
				</details>
			</div>
		</li>
	<% }) %>
	</ul>
</section>
<% } %>
