<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/** INQUIRY DETAIL — Expects: $inq, $service. */
$q = $inq;
?>
<div class="page-head">
	<div><h2><?= html_escape($q['name']) ?></h2><p><?= html_escape(ucfirst($q['type'])) ?> inquiry · <?= nice_date($q['created_at'], 'd M Y, H:i') ?></p></div>
	<a href="<?= base_url('admin/inquiries') ?>" class="btn btn-ghost">← Back</a>
</div>

<div class="grid grid-2-1">
	<div>
		<div class="card">
			<div class="card-head"><h3>Message</h3></div>
			<div class="card-body">
				<?php if ($q['subject']): ?><h4 style="margin-bottom:10px;"><?= html_escape($q['subject']) ?></h4><?php endif; ?>
				<p style="white-space:pre-line;"><?= html_escape($q['message']) ?></p>
				<?php if ($q['brief_file']): ?>
					<p style="margin-top:14px;">
						<a href="<?= upload_url($q['brief_file']) ?>" target="_blank" class="btn btn-ghost btn-sm">
							<?= bloom_icon('inbox', 14) ?> Download Attached Brief
						</a>
					</p>
				<?php endif; ?>
			</div>
		</div>

		<div class="card">
			<div class="card-head"><h3>Contact &amp; Project</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($q['email']) ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Phone</label><div><?= html_escape($q['phone'] ?: '—') ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Company</label><div><?= html_escape($q['company'] ?: '—') ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Service</label><div><?= html_escape($service ? $service['title'] : '—') ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Budget</label><div><?= html_escape($q['budget_range'] ?: '—') ?></div></div>
					<div><label class="muted" style="font-size:.78rem;">Timeline</label><div><?= html_escape($q['timeline'] ?: '—') ?></div></div>
				</div>
			</div>
		</div>
	</div>

	<div>
		<div class="card">
			<div class="card-head"><h3>Manage</h3></div>
			<div class="card-body">
				<div style="margin-bottom:14px;">Status: <?= status_pill($q['status']) ?></div>
				<form action="<?= base_url('admin/inquiries/status/'.$q['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('new'=>'New','reviewed'=>'Reviewed','converted'=>'Converted','closed'=>'Closed') as $k=>$v): ?>
								<option value="<?= $k ?>" <?= $q['status'] === $k ? 'selected' : '' ?>><?= $v ?></option>
							<?php endforeach; ?>
						</select>
					</div>
					<div class="fld"><label>Internal Notes</label>
						<textarea name="admin_notes"><?= html_escape($q['admin_notes']) ?></textarea></div>
					<button type="submit" class="btn btn-primary btn-block"><?= bloom_icon('check', 16) ?> Save</button>
				</form>
			</div>
		</div>
		<div class="card">
			<div class="card-body">
				<a href="mailto:<?= html_escape($q['email']) ?>" class="btn btn-ghost btn-block" style="margin-bottom:10px;">
					<?= bloom_icon('mail', 16) ?> Reply by Email
				</a>
				<a href="<?= base_url('admin/inquiries/delete/'.$q['id']) ?>" class="btn btn-danger btn-block"
				   data-confirm="Delete this inquiry?"><?= bloom_icon('trash', 16) ?> Delete</a>
			</div>
		</div>
	</div>
</div>
