<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** APPLICATIONS LIST — Expects: $applications, $counts, $cur_status, $cur_search. */
$statuses = array('pending'=>'Pending','shortlisted'=>'Shortlisted','approved'=>'Approved','rejected'=>'Rejected');
?>
<div class="page-head">
	<div><h2>Talent Applications</h2><p>Review applications to join the talent network.</p></div>
</div>

<div class="filter-row">
	<div class="tabs">
		<a href="<?= base_url('admin/applications') ?>" class="tab <?= ! $cur_status ? 'active' : '' ?>">All</a>
		<?php foreach ($statuses as $k=>$v): ?>
			<a href="<?= base_url('admin/applications?status='.$k) ?>" class="tab <?= $cur_status === $k ? 'active' : '' ?>">
				<?= $v ?><span class="count"><?= isset($counts[$k]) ? '('.$counts[$k].')' : '' ?></span>
			</a>
		<?php endforeach; ?>
	</div>
	<form method="get" class="search">
		<?= bloom_icon('search', 17) ?>
		<input type="text" name="q" value="<?= html_escape($cur_search) ?>" placeholder="Search applicants…">
		<?php if ($cur_status): ?><input type="hidden" name="status" value="<?= html_escape($cur_status) ?>"><?php endif; ?>
	</form>
</div>

<div class="card"><div class="card-body flush">
	<?php if ($applications): ?>
		<div class="table-wrap">
			<table class="data">
				<thead><tr><th>Applicant</th><th>Category</th><th>Location</th><th>Status</th><th>Received</th><th class="text-right">Actions</th></tr></thead>
				<tbody>
				<?php foreach ($applications as $a): ?>
					<tr onclick="location.href='<?= base_url('admin/applications/view/'.$a['id']) ?>'" style="cursor:pointer;">
						<td><div class="row-title"><?= html_escape($a['name']) ?></div><div class="row-sub"><?= html_escape($a['email']) ?></div></td>
						<td><?= html_escape(ucwords(str_replace('_',' ',$a['category']))) ?></td>
						<td class="muted"><?= html_escape($a['location']) ?></td>
						<td><?= status_pill($a['status']) ?></td>
						<td class="muted"><?= nice_date($a['created_at']) ?></td>
						<td class="text-right"><span class="icon-btn"><?= bloom_icon('arrow', 16) ?></span></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	<?php else: ?>
		<div class="empty"><?= bloom_icon('inbox', 44) ?><p>No applications found.</p></div>
	<?php endif; ?>
</div></div>
