<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** APPLICATION DETAIL — Expects: $app. */
$a = $app;
?>
<div class="page-head">
	<div><h2><?= html_escape($a['name']) ?></h2><p>Talent application · received <?= nice_date($a['created_at'], 'd M Y') ?></p></div>
	<a href="<?= base_url('admin/applications') ?>" class="btn btn-ghost">← Back</a>
</div>

<div class="grid grid-2-1">
	<div>
		<div class="card">
			<div class="card-head"><h3>Applicant Details</h3></div>
			<div class="card-body">
				<div class="form-grid cols-2">
					<div><label class="muted" style="font-size:.78rem;">Email</label><div><?= html_escape($a['email']) ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Phone</label><div><?= html_escape($a['phone']) ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Category</label><div><?= html_escape(ucwords(str_replace('_',' ',$a['category']))) ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Location</label><div><?= html_escape($a['location']) ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Instagram</label><div><?= html_escape($a['instagram'] ?: '—') ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Followers</label><div><?= html_escape($a['followers'] ?: '—') ?></div></div>
				</div>
				<?php if ($a['portfolio_url']): ?>
					<div style="margin-top:16px;">
						<label class="muted" style="font-size:.78rem;">Portfolio Link</label>
						<div><a href="<?= html_escape($a['portfolio_url']) ?>" target="_blank" style="color:var(--plum);"><?= html_escape($a['portfolio_url']) ?></a></div>
					</div>
				<?php endif; ?>
				<?php if ($a['bio']): ?>
					<div style="margin-top:16px;">
						<label class="muted" style="font-size:.78rem;">Bio / Message</label>
						<p style="margin-top:4px;"><?= nl2br(html_escape($a['bio'])) ?></p>
					</div>
				<?php endif; ?>
			</div>
		</div>

		<?php if ($a['photo']): ?>
		<div class="card">
			<div class="card-head"><h3>Submitted Photo</h3></div>
			<div class="card-body"><img src="<?= upload_url($a['photo']) ?>" style="max-width:320px;border-radius:11px;"></div>
		</div>
		<?php endif; ?>
	</div>

	<div>
		<div class="card">
			<div class="card-head"><h3>Review</h3></div>
			<div class="card-body">
				<div style="margin-bottom:14px;">Current status: <?= status_pill($a['status']) ?></div>
				<form action="<?= base_url('admin/applications/status/'.$a['id']) ?>" method="post">
					<?= form_hidden($this->security->get_csrf_token_name(), $this->security->get_csrf_hash()) ?>
					<div class="fld"><label>Update Status</label>
						<select name="status">
							<?php foreach (array('pending'=>'Pending','shortlisted'=>'Shortlisted','approved'=>'Approved','rejected'=>'Rejected') as $k=>$v): ?>
								<option value="<?= $k ?>" <?= $a['status'] === $k ? 'selected' : '' ?>><?= $v ?></option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="fld"><label>Internal Notes</label>
						<textarea name="admin_notes"><?= html_escape($a['admin_notes']) ?></textarea></div>
					<button type="submit" class="btn btn-primary btn-block"><?= bloom_icon('check', 16) ?> Save Review</button>
				</form>
			</div>
		</div>

		<div class="card">
			<div class="card-head"><h3>Actions</h3></div>
			<div class="card-body">
				<a href="<?= base_url('admin/applications/promote/'.$a['id']) ?>" class="btn btn-primary btn-block"
				   data-confirm="Add this applicant to the talent roster as a draft profile?" style="margin-bottom:10px;">
					<?= bloom_icon('star', 16) ?> Promote to Talent Roster
				</a>
				<a href="<?= base_url('admin/applications/delete/'.$a['id']) ?>" class="btn btn-danger btn-block"
				   data-confirm="Permanently delete this application?">
					<?= bloom_icon('trash', 16) ?> Delete Application
				</a>
			</div>
		</div>
	</div>
</div>
