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

<?= $this->section('title') ?>Registro de Pagos<?= $this->endSection() ?>

<?= $this->section('content') ?>
<section class="panel-card">
    <div class="panel-header">
        <div>
            <span class="panel-eyebrow">Finanzas</span>
            <h2>Pagos</h2>
            <p>Consulta pagos, referencias y estados de las reservas del cine.</p>
        </div>
    </div>

    <form method="GET" action="<?= base_url('admin/pagos') ?>" class="search-panel">
        <div class="search-box">
            <input type="text" name="q" placeholder="Buscar por cliente, referencia o método" value="<?= esc($q) ?>">
            <button type="submit" class="btn btn-secondary">Buscar</button>
        </div>
    </form>

    <?php if (empty($pagos)): ?>
        <div class="empty-state">No se encontraron registros de pagos.</div>
    <?php else: ?>
        <div class="table-wrapper">
            <table>
                <thead>
                    <tr>
                        <th>Operación</th>
                        <th>Reserva ID</th>
                        <th>Cliente</th>
                        <th>Monto Pagado</th>
                        <th>Monto Reserva</th>
                        <th>Método</th>
                        <th>Referencia</th>
                        <th>Fecha y Hora</th>
                        <th>Estado</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($pagos as $pago): ?>
                        <tr>
                            <td><strong>#<?= $pago->id_pago ?></strong></td>
                            <td>#<?= $pago->id_reserva ?></td>
                            <td><?= esc($pago->cliente_nombres) ?> <?= esc($pago->cliente_apellidos) ?></td>
                            <td class="payment-amount">S/. <?= number_format($pago->monto, 2) ?></td>
                            <td>S/. <?= number_format($pago->reserva_total, 2) ?></td>
                            <td><span class="status-pill active"><?= esc(ucfirst($pago->metodo)) ?></span></td>
                            <td><code><?= esc($pago->referencia ?: 'N/A') ?></code></td>
                            <td><?= esc($pago->fecha_pago) ?></td>
                            <td>
                                <span class="status-pill <?= $pago->estado === 'aprobado' ? 'active' : ($pago->estado === 'pendiente' ? 'inactive' : 'inactive') ?>">
                                    <?= esc(ucfirst($pago->estado)) ?>
                                </span>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>

        <div class="pager-wrap">
            <?= $pager->links() ?>
        </div>
    <?php endif; ?>
</section>
<?= $this->endSection() ?>
