<?= $this->extend('admin/layout') ?>

<?= $this->section('content') ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="h3 text-gray-800">View Enquiry</h1>
    <a href="<?= base_url('admin/enquiries') ?>" class="btn btn-secondary">Back</a>
</div>

<div class="card shadow mb-4">
    <div class="card-body">
        <table class="table table-bordered">
            <tr>
                <th width="200">Date Received</th>
                <td><?= date('d M Y, h:i A', strtotime($enquiry['created_at'])) ?></td>
            </tr>
            <tr>
                <th>Type</th>
                <td><?= ucfirst($enquiry['type']) ?></td>
            </tr>
            <?php if (!empty($product)): ?>
            <tr>
                <th>Product Reference</th>
                <td>
                    <a href="<?= base_url('product/' . $product['slug']) ?>" target="_blank" class="fw-bold text-decoration-none" style="color: #10B981;">
                        <?= esc($product['name']) ?> <i class="bi bi-box-arrow-up-right ms-1" style="font-size: 0.8rem;"></i>
                    </a>
                </td>
            </tr>
            <?php elseif (!empty($enquiry['product_id'])): ?>
            <tr>
                <th>Product ID Reference</th>
                <td><?= esc($enquiry['product_id']) ?> <span class="text-muted">(Product not found/deleted)</span></td>
            </tr>
            <?php endif; ?>
            <tr>
                <th>Name</th>
                <td><?= $enquiry['name'] ?></td>
            </tr>
            <tr>
                <th>Email</th>
                <td><a href="mailto:<?= $enquiry['email'] ?>"><?= $enquiry['email'] ?></a></td>
            </tr>
            <tr>
                <th>Phone</th>
                <td><a href="tel:<?= $enquiry['phone'] ?>"><?= $enquiry['phone'] ?></a></td>
            </tr>
            <tr>
                <th>Message</th>
                <td><?= nl2br(esc($enquiry['message'])) ?></td>
            </tr>
            <tr>
                <th>Current Status</th>
                <td>
                    <strong><?= ucfirst($enquiry['status']) ?></strong>
                </td>
            </tr>
        </table>
        
        <div class="mt-4">
            <h5>Update Status</h5>
            <a href="<?= base_url('admin/enquiries/status/' . $enquiry['id'] . '/read') ?>" class="btn btn-info">Mark as Read</a>
            <a href="<?= base_url('admin/enquiries/status/' . $enquiry['id'] . '/replied') ?>" class="btn btn-success">Mark as Replied</a>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
