<?= $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 Kemiringan Lereng</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; ?>

                <div class="table-responsive">

                    <table class="table table-bordered">
                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Nilai Min</th>
                                <th>Nilai Max</th>
                                <th>Kategori</th>
                                <th>Skor</th>
                                <th>Warna Peta</th>
                                <th width="150">Aksi</th>
                            </tr>
                        </thead>

                        <tbody>

                            <?php $no = 1;
                            foreach ($kemiringan as $row): ?>

                                <tr>
                                    <td><?= $no++ ?></td>
                                    <td><?= $row['nilai_min'] ?></td>
                                    <td><?= $row['nilai_max'] ?></td>
                                    <td>
                                        <span class="badge badge-info">
                                            <?= $row['kategori'] ?>
                                        </span>
                                    </td>
                                    <td><?= $row['skor'] ?></td>
                                    <td>
                                        <span style="display:inline-block;width:25px;height:25px; background:<?= $row['warna_peta'] ?>;border-radius:4px;border:1px solid #000">
                                        </span>
                                    </td>
                                    <td>

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

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

                                    </td>
                                </tr>

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

                                            <form action="<?= base_url('admin/kemiringan/update/' . $row['id_lereng']) ?>" method="post">

                                                <div class="modal-header">
                                                    <h5>Edit Kemiringan Lereng</h5>
                                                </div>

                                                <div class="modal-body">

                                                    <label>Nilai Min</label>
                                                    <input type="number" step="0.01" name="nilai_min"
                                                        value="<?= $row['nilai_min'] ?>"
                                                        class="form-control mb-2">

                                                    <label>Nilai Max</label>
                                                    <input type="number" step="0.01" name="nilai_max"
                                                        value="<?= $row['nilai_max'] ?>"
                                                        class="form-control mb-2">

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

                                                    <label>Skor</label>
                                                    <input type="number" name="skor"
                                                        value="<?= $row['skor'] ?>"
                                                        class="form-control mb-2">

                                                    <label>Warna Peta</label>
                                                    <input type="color" name="warna_peta"
                                                        value="<?= $row['warna_peta'] ?>"
                                                        class="form-control mb-2">

                                                </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_lereng'] ?>">
                                    <div class="modal-dialog">
                                        <div class="modal-content">

                                            <div class="modal-body text-center">

                                                <h5>Hapus data ini?</h5>

                                                <p><b><?= $row['kategori'] ?></b></p>

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

                                            </div>

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

                            <?php endforeach; ?>

                        </tbody>

                    </table>

                </div>

            </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/kemiringan/store') ?>" method="post">

                <div class="modal-header">
                    <h5>Tambah Kemiringan Lereng</h5>
                </div>

                <div class="modal-body">

                    <label>Nilai Min</label>
                    <input type="number" step="0.01" name="nilai_min" class="form-control mb-2" required>

                    <label>Nilai Max</label>
                    <input type="number" step="0.01" name="nilai_max" class="form-control mb-2" required>

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

                    <label>Skor</label>
                    <input type="number" name="skor" class="form-control mb-2" required>

                    <label>Warna Peta</label>
                    <input type="color" name="warna_peta" class="form-control mb-2" required>

                </div>

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

            </form>

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

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