<?= $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">Manage Enquiries</h1>
    <a href="<?= base_url('admin/enquiries/export') ?>" class="btn btn-success">Export to CSV</a>
</div>

<div class="card shadow mb-4">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-bordered" width="100%" cellspacing="0">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Type</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($enquiries as $enquiry): ?>
                    <tr class="<?= $enquiry['status'] == 'new' ? 'table-warning' : '' ?>">
                        <td><?= date('d M Y', strtotime($enquiry['created_at'])) ?></td>
                        <td><?= ucfirst($enquiry['type']) ?></td>
                        <td><?= $enquiry['name'] ?></td>
                        <td><?= $enquiry['email'] ?></td>
                        <td>
                            <?php if ($enquiry['status'] == 'new'): ?>
                                <span class="badge bg-danger">New</span>
                            <?php elseif ($enquiry['status'] == 'read'): ?>
                                <span class="badge bg-info">Read</span>
                            <?php else: ?>
                                <span class="badge bg-success">Replied</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <a href="<?= base_url('admin/enquiries/view/' . $enquiry['id']) ?>" class="btn btn-sm btn-primary">View</a>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?= $this->endSection() ?>
