<?php require __DIR__ . '/../../layouts/header.php'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h1 class="page-title"><?= e(trans('registration_submissions')) ?></h1>
    <a href="<?= e(base_path('admin/registration-form')) ?>" class="btn ec-btn btn-outline-secondary rounded-3"><?= e(trans('back')) ?></a>
</div>

<div class="ec-card   mb-4">
    <div class="ec-card-body">
        <form method="get" action="<?= e(base_path('admin/registration-submissions')) ?>" class="row g-3">
            <div class="col-md-6">
                <label class="form-label"><?= e(trans('conference')) ?></label>
                <select name="conference_id" class="form-select rounded-3">
                    <option value="0">--</option>
                    <?php foreach ($conferences as $c): ?>
                        <option value="<?= e((string) $c['id']) ?>" <?= (int) $conference_id === (int) $c['id'] ? 'selected' : '' ?>>
                            <?= e(current_lang() === 'ar' ? (string) ($c['title_ar'] ?? '') : (string) ($c['title_en'] ?? '')) ?>
                        </option>
                    <?php endforeach; ?>
                </select>
            </div>
            <div class="col-md-2 d-flex align-items-end"><button class="btn ec-btn btn-primary rounded-3 w-100"><?= e(trans('search')) ?></button></div>
        </form>
    </div>
</div>

<?php if ($conference_id > 0): ?>
<div class="ec-card  ">
    <div class="table-responsive">
        <table class="table ec-table align-middle mb-0">
            <thead><tr><th>#</th><th><?= e(trans('full_name_en')) ?></th><th><?= e(trans('email')) ?></th><th><?= e(trans('status')) ?></th><th><?= e(trans('actions')) ?></th></tr></thead>
            <tbody>
                <?php foreach ($rows as $row): ?>
                    <tr>
                        <td><?= e((string) $row['id']) ?></td>
                        <td><?= e(current_lang() === 'ar' ? (string) (($row['full_name_ar'] ?? '') ?: ($row['full_name_en'] ?? '')) : (string) ($row['full_name_en'] ?? '')) ?></td>
                        <td><?= e((string) ($row['email'] ?? '')) ?></td>
                        <td><span class="badge ec-badge bg-primary"><?= e(trans((string) ($row['status'] ?? 'pending'))) ?></span></td>
                        <td>
                            <form method="post" action="<?= e(base_path('admin/registration-submissions/update')) ?>" class="d-flex gap-2">
                                <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                <input type="hidden" name="id" value="<?= e((string) $row['id']) ?>">
                                <input type="hidden" name="conference_id" value="<?= e((string) $conference_id) ?>">
                                <select name="status" class="form-select form-select-sm rounded-3">
                                    <?php foreach (['pending','approved','rejected'] as $s): ?>
                                        <option value="<?= e($s) ?>" <?= (($row['status'] ?? 'pending') === $s) ? 'selected' : '' ?>><?= e(trans($s)) ?></option>
                                    <?php endforeach; ?>
                                </select>
                                <button class="btn ec-btn btn-sm btn-outline-success rounded-3"><?= e(trans('save')) ?></button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($rows)): ?><tr><td colspan="5" class="text-center"><?= e(trans('no_data')) ?></td></tr><?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>

<?php require __DIR__ . '/../../layouts/footer.php'; ?>
