<?= $this->include('admin/layout/header') ?>
<?= $this->include('admin/layout/navbar') ?>
<?= $this->include('admin/layout/topbar') ?>

<div class="pcoded-main-container">
    <div class="pcoded-content">

        <div class="card">

            <div class="card-header">
                <h5>Data Strategi Mitigasi</h5>

                <button class="btn btn-primary float-right"
                    data-toggle="modal"
                    data-target="#modalTambah">
                    Tambah Data
                </button>
            </div>

            <div class="card-body">

                <?php if (session()->getFlashdata('success')) : ?>
                    <div class="alert alert-success">
                        <?= session()->getFlashdata('success') ?>
                    </div>
                <?php endif; ?>

                
                <table class="table table-bordered">
                    <thead class="thead-light">
                        <tr class="text-center">
                            <th width="60">No</th>
                            <th width="140">Jenis</th>
                            <th width="220">Judul</th>
                            <th>Deskripsi</th>
                            <th>Rekomendasi</th>
                            <th width="150">Aksi</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php $no = 1;
                        foreach ($strategi as $row): ?>
                            <tr>
                                <td><?= $no++ ?></td>
                                <td><?= $row['jenis'] ?></td>
                                <td><?= $row['judul'] ?></td>
                                <td width="280">
    <?= character_limiter(strip_tags($row['deskripsi']), 40) ?>
</td>

<td width="280">
    <?= character_limiter(strip_tags($row['rekomendasi']), 40) ?>
</td>

                                <td>
                                    <button class="btn btn-warning btn-sm"
                                        data-toggle="modal"
                                        data-target="#edit<?= $row['id_mitigasi'] ?>">
                                        Edit
                                    </button>

                                    <button class="btn btn-danger btn-sm"
                                        data-toggle="modal"
                                        data-target="#hapus<?= $row['id_mitigasi'] ?>">
                                        Hapus
                                    </button>
                                </td>
                            </tr>

                            <!-- EDIT MODAL -->
                            <div class="modal fade" id="edit<?= $row['id_mitigasi'] ?>">
                                <div class="modal-dialog">
                                    <div class="modal-content">

                                        <form action="<?= base_url('admin/strategi-mitigasi/update/' . $row['id_mitigasi']) ?>" method="post">

                                            <div class="modal-header">
                                                <h5>Edit Strategi Mitigasi</h5>
                                            </div>

                                            <div class="modal-body">

                                                <label>Jenis</label>
                                                <select name="jenis" class="form-control mb-2">
                                                    <option value="struktural" <?= $row['jenis'] == 'struktural' ? 'selected' : '' ?>>Struktural</option>
                                                    <option value="non_struktural" <?= $row['jenis'] == 'non_struktural' ? 'selected' : '' ?>>Non Struktural</option>
                                                </select>

                                                <label>Judul</label>
                                                <input type="text"
                                                    name="judul"
                                                    value="<?= $row['judul'] ?>"
                                                    class="form-control mb-2">

                                                <label>Deskripsi</label>
                                                <textarea name="deskripsi" class="form-control mb-2"><?= $row['deskripsi'] ?></textarea>

                                                <label>Rekomendasi</label>
                                                <textarea name="rekomendasi" class="form-control mb-2"><?= $row['rekomendasi'] ?></textarea>

                                            </div>

                                            <div class="modal-footer">
                                                <button class="btn btn-success">Update</button>
                                            </div>

                                        </form>

                                    </div>
                                </div>
                            </div>

                            <!-- HAPUS MODAL -->
                            <div class="modal fade" id="hapus<?= $row['id_mitigasi'] ?>">
                                <div class="modal-dialog">
                                    <div class="modal-content">

                                        <div class="modal-body text-center">
                                            <h5>Hapus data ini?</h5>

                                            <a href="<?= base_url('admin/strategi-mitigasi/delete/' . $row['id_mitigasi']) ?>"
                                                class="btn btn-danger">
                                                Ya Hapus
                                            </a>
                                        </div>

                                    </div>
                                </div>
                            </div>

                        <?php endforeach; ?>
                    </tbody>
                </table>

            </div>
        </div>

    </div>
</div>

<!-- TAMBAH MODAL -->
<div class="modal fade" id="modalTambah">
    <div class="modal-dialog">
        <div class="modal-content">

            <form action="<?= base_url('admin/strategi-mitigasi/store') ?>" method="post">

                <div class="modal-header">
                    <h5>Tambah Strategi Mitigasi</h5>
                </div>

                <div class="modal-body">

                    <label>Jenis</label>
                    <select name="jenis" class="form-control mb-2">
                        <option value="struktural">Struktural</option>
                        <option value="non_struktural">Non Struktural</option>
                    </select>

                    <label>Judul</label>
                    <input type="text" name="judul" class="form-control mb-2" required>

                    <label>Deskripsi</label>
                    <textarea name="deskripsi" class="form-control mb-2"></textarea>

                    <label>Rekomendasi</label>
                    <textarea name="rekomendasi" class="form-control mb-2"></textarea>

                </div>

                <div class="modal-footer">
                    <button class="btn btn-primary">Simpan</button>
                </div>

            </form>

        </div>
    </div>
</div>

<?= $this->include('admin/layout/footer') ?>