<?php $title = 'Form Submissions: ' . htmlspecialchars($form->title); ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold">Submissions: <?= htmlspecialchars($form->title) ?></h1>
    <a href="<?= $baseUrl ?>/forms" class="glass-btn"><i class="fas fa-arrow-left mr-1"></i>Back</a>
</div>
<div class="glass-table">
    <table class="table">
        <thead><tr><th>#</th><th>Submitted By</th><th>Date</th><th>Data</th></tr></thead>
        <tbody>
            <?php if (!empty($submissions)): ?>
                <?php foreach ($submissions as $i => $sub): ?>
                <tr>
                    <td><?= $i + 1 ?></td>
                    <td><?= htmlspecialchars($sub->user_name ?? $sub->user_email ?? 'Guest') ?></td>
                    <td><?= date('M d, Y H:i', strtotime($sub->submitted_at)) ?></td>
                    <td>
                        <?php $data = json_decode($sub->data, true); ?>
                        <?php if ($data): ?>
                            <?php foreach ($data as $key => $val): ?>
                            <small><strong><?= htmlspecialchars($key) ?>:</strong> <?= htmlspecialchars(is_array($val) ? implode(', ', $val) : $val) ?></small><br>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr><td colspan="4" class="text-center" style="color: rgba(255,255,255,0.5);">No submissions yet</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>
