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

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

<div class="ec-card   mb-4">
    <div class="ec-card-body">
        <form method="get" action="<?= e(base_path('admin/payments')) ?>" 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><?= e(trans('invoice_no')) ?></th>
                    <th><?= e(trans('submissions')) ?></th>
                    <th><?= e(trans('amount')) ?></th>
                    <th><?= e(trans('payment_status')) ?></th>
                    <th><?= e(trans('actions')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($rows as $row): ?>
                    <tr>
                        <td><?= e((string) ($row['invoice_no'] ?? '')) ?></td>
                        <td><?= e((string) ($row['submission_no'] ?? '')) ?></td>
                        <td><?= e((string) ($row['amount'] ?? '0')) ?> <?= e((string) ($row['currency'] ?? 'JOD')) ?></td>
                        <td><span class="badge ec-badge bg-primary"><?= e(trans((string) ($row['payment_status'] ?? 'draft'))) ?></span></td>
                        <td>
                            <?php if (($row['payment_status'] ?? '') !== 'paid'): ?>
                            <form method="post" action="<?= e(base_path('admin/payments/mark-paid')) ?>" class="d-flex gap-2">
                                <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                <input type="hidden" name="invoice_id" value="<?= e((string) $row['id']) ?>">
                                <input type="hidden" name="amount" value="<?= e((string) $row['amount']) ?>">
                                <button class="btn ec-btn btn-sm btn-outline-success rounded-3"><?= e(trans('paid')) ?></button>
                            </form>
                            <?php endif; ?>
                        </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'; ?>
