<?= $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 Jenis Tanah</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>
                        <tr>
                            <th>No</th>
                            <th>Jenis Tanah</th>
                            <th>Skor</th>
                            <th>Warna</th>
                            <th width="150">Aksi</th>
                        </tr>
                    </thead>

                    <tbody>
                        <?php $no = 1;
                        foreach ($jenis_tanah as $row): ?>
                            <tr>
                                <td><?= $no++ ?></td>
                                <td><?= $row['jenis_tanah'] ?></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_tanah'] ?>">
                                        Edit
                                    </button>

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

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

                                        <form action="<?= base_url('admin/jenis-tanah/update/' . $row['id_tanah']) ?>" method="post">

                                            <div class="modal-header">
                                                <h5>Edit Jenis Tanah</h5>
                                            </div>

                                            <div class="modal-body">

                                                <label>Jenis Tanah</label>
                                                <input type="text"
                                                    name="jenis_tanah"
                                                    value="<?= $row['jenis_tanah'] ?>"
                                                    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"
                                                    required>
                                            </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_tanah'] ?>">
                                <div class="modal-dialog">
                                    <div class="modal-content">

                                        <div class="modal-body text-center">
                                            <h5>Hapus data ini?</h5>
                                            <a href="<?= base_url('admin/jenis-tanah/delete/' . $row['id_tanah']) ?>"
                                                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/jenis-tanah/store') ?>" method="post">

                <div class="modal-header">
                    <h5>Tambah Jenis Tanah</h5>
                </div>

                <div class="modal-body">

                    <label>Jenis Tanah</label>
                    <input type="text" name="jenis_tanah" 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"
                        value="#4CAF50"
                        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') ?>