<?= $this->extend('layout/default') ?>

<?= $this->section('content') ?>
<div class="container pt-5 pb-5">
    <div class="card shadow border-0">
        <div class="card-header bg-success text-white d-flex justify-content-between align-items-center">
            <h4 class="mb-0"><i class="fa fa-comments"></i> Moderasi Komentar</h4>
        </div>
        <div class="card-body">
            <?php if (session()->getFlashdata('success')) : ?>
                <div class="alert alert-success"><?= session()->getFlashdata('success') ?></div>
            <?php endif; ?>

            <div class="table-responsive">
                <table class="table table-hover border">
                    <thead class="bg-light">
                        <tr>
                            <th>Waktu</th>
                            <th>Pengirim</th>
                            <th>Berita</th>
                            <th>Isi Komentar</th>
                            <th>Status</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($komentar as $k) : ?>
                        <tr>
                            <td><small><?= date('d/m/Y H:i', strtotime($k['created_at'])) ?></small></td>
                            <td>
                                <strong><?= esc($k['nama']) ?></strong><br>
                                <small class="text-muted"><?= esc($k['email']) ?></small>
                            </td>
                            <td><small><?= esc($k['judul_berita']) ?></small></td>
                            <td><p style="max-width: 300px; font-size: 14px;"><?= esc($k['isi_komentar']) ?></p></td>
                            <td>
                                <?php if ($k['status'] == 'pending') : ?>
                                    <span class="badge bg-warning text-dark px-3">Menunggu</span>
                                <?php else : ?>
                                    <span class="badge bg-success px-3">Terbit</span>
                                <?php endif; ?>
                            </td>
                            <td>
                                <div class="btn-group">
                                    <?php if ($k['status'] == 'pending') : ?>
                                        <a href="<?= base_url('admin/komentar/setujui/' . $k['id_komentar']) ?>" class="btn btn-sm btn-success" title="Setujui">
                                            <i class="fa fa-check"></i> Izinkan
                                        </a>
                                    <?php endif; ?>
                                    <a href="<?= base_url('admin/komentar/hapus/' . $k['id_komentar']) ?>" class="btn btn-sm btn-danger" onclick="return confirm('Hapus komentar ini?')" title="Hapus">
                                        <i class="fa fa-trash"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<?= $this->endSection() ?>