<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** INQUIRIES LIST — Expects: $inquiries, $counts, $cur_type, $cur_status, $cur_search. */
$statuses = array('new'=>'New','reviewed'=>'Reviewed','converted'=>'Converted','closed'=>'Closed');
?>
<div class="page-head">
	<div><h2>Inquiries</h2><p>Contact messages and brand collaboration leads.</p></div>
	<a href="<?= base_url('admin/inquiries/subscribers') ?>" class="btn btn-ghost"><?= bloom_icon('mail', 16) ?> Newsletter Subscribers</a>
</div>

<div class="filter-row">
	<div class="tabs">
		<a href="<?= base_url('admin/inquiries') ?>" class="tab <?= ! $cur_status ? 'active' : '' ?>">All</a>
		<?php foreach ($statuses as $k=>$v): ?>
			<a href="<?= base_url('admin/inquiries?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 inquiries…">
	</form>
</div>

<div class="card"><div class="card-body flush">
	<?php if ($inquiries): ?>
		<div class="table-wrap">
			<table class="data">
				<thead><tr><th>From</th><th>Type</th><th>Subject</th><th>Status</th><th>Received</th></tr></thead>
				<tbody>
				<?php foreach ($inquiries as $q): ?>
					<tr onclick="location.href='<?= base_url('admin/inquiries/view/'.$q['id']) ?>'" style="cursor:pointer;<?= $q['status']==='new' ? 'font-weight:600;' : '' ?>">
						<td><div class="row-title"><?= html_escape($q['name']) ?></div><div class="row-sub"><?= html_escape($q['email']) ?></div></td>
						<td><span class="pill <?= $q['type']==='brand' ? 'pill-amber' : 'pill-grey' ?>"><?= html_escape(ucfirst($q['type'])) ?></span></td>
						<td><?= html_escape(excerpt($q['subject'] ?: $q['message'], 9)) ?></td>
						<td><?= status_pill($q['status']) ?></td>
						<td class="muted"><?= nice_date($q['created_at']) ?></td>
					</tr>
				<?php endforeach; ?>
				</tbody>
			</table>
		</div>
	<?php else: ?>
		<div class="empty"><?= bloom_icon('mail', 44) ?><p>No inquiries found.</p></div>
	<?php endif; ?>
</div></div>
