<?php
$title = "Iuran";
require __DIR__ . '/../layout/header.php';
require __DIR__ . '/../layout/sidebar.php';
?>

<div class="main">

    <div class="header">Iuran Member</div>

    <div class="card">
    <div class="card">

    <h3>Bayar Iuran</h3>

    <form action="/membership/iuran-upload" method="POST" enctype="multipart/form-data">

        <div class="grid">

            <div class="form-group">
                <label>Tanggal Bayar</label>
                <input type="date" name="tanggal_bayar" required>
            </div>

            <div class="form-group">
                <label>Jumlah</label>
                <input type="number" name="jumlah" required>
            </div>

            <div class="form-group" style="grid-column: span 2;">
                <label>Upload Bukti</label>
                <input type="file" name="bukti" required>
            </div>

        </div>

        <br>
        <button class="btn btn-primary">Upload & Bayar</button>

    </form>

</div>
        <table class="table">
            <thead>
                <tr>
                    <th>Bulan</th>
                    <th>Jumlah</th>
                    <th>Tanggal Bayar</th>
                    <th>Status</th>
                    <th>Bukti</th>
                </tr>
            </thead>
            <tbody>

                <?php if (!empty($data)): ?>
                    <?php foreach ($data as $row): ?>
                        <tr>
                            <td><?= $row['bulan'] ?> <?= $row['tahun'] ?></td>

                            <td>Rp <?= number_format($row['jumlah']) ?></td>

                            <td><?= $row['tanggal'] ?? '-' ?></td>

                            <td>
                                <span class="badge 
                                    <?= $row['status']=='Lunas' ? 'success' : 
                                       ($row['status']=='Menunggu Verifikasi' ? 'warning' : 'danger') ?>">
                                    <?= $row['status'] ?>
                                </span>
                            </td>

                            <td>
                                <?php if (!empty($row['bukti'])): ?>
                                    <a href="/membership/public/assets/uploads/<?= $row['bukti'] ?>" target="_blank">
                                        Lihat
                                    </a>
                                <?php else: ?>
                                    -
                                <?php endif; ?>
                            </td>

                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr>
                        <td colspan="5">Belum ada data iuran</td>
                    </tr>
                <?php endif; ?>

            </tbody>
        </table>

    </div>

</div>

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