<div class="content-wrapper">
    <div class="content-header bg-link bg-link">
        <div class="container-fluid">
            <div class="row mb-2" mb-2>
                <div class="col-sm-6">
                    <h1 class="m-0 text-dark ">Kategori Berita</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item active"><a class="text-dark" href="">Home / </a></li>
                        <li class="breadcrumb-iten active"><a class="text-dark" href="">Kategori Berita </a></li>
                    </ol>
                </div>
            </div>
        </div>
    </div>

    <div class="card ml-3 mr-3">
        <div class="card-header bg-success">
            <h1>Table Kategori</h1>
        </div>

        <div class="card-body">
            <div class="table-responsive">

                <button data-toggle="modal" title=" Tambah Data" data-target="#tambah" class="btn btn-success mb-5"><i class="fa fa-plus"></i></button>

                <table class="table table-bordered" id='example1' style="text-align: center;">
                    <thead>
                        <tr>
                            <th>No</th>
                            <th>Kategori Nama</th>
                            <th>Aksi</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php

                        $dataadmin = $koneksi->query("SELECT * FROM tbl_kategori");

                        foreach ($dataadmin as $no => $pecah) :

                        ?>
                            <tr>
                                <td><?= ++$no ?></td>
                                <td><?= $pecah['kategori_nama'] ?></td>
                                <td>
                                    <a href="?page=pages/kategori/edit&idedit=<?= $pecah['kategori_id'] ?>" data-toggle="tooltip" title="Edit Kategori" class="btn btn-warning mr-2"><i class="fa fa-edit"></i></a>
                                    <a href="?page=pages/kategori/hapus&idhapus=<?= $pecah['kategori_id'] ?>" data-toggle="tooltip" title="Hapus Kategori" class="btn btn-danger"><i class="fa fa-trash"></i></a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>

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

<style>
    .page-item.active .page-link {
        background-color: green;
        border-color: green;
    }
</style>

<!-- Modal -->
<div class="modal fade" id="tambah" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header bg-success">
                <h5 class="modal-title" id="exampleModalLabel">Tambah</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form action="" method="POST" enctype="multipart/form-data">
                    <div class="form-group">
                        <label>Nama Kategori</label>
                        <input type="text" name="nama" class="form-control">
                    </div>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary" name="simpan">Simpan</button>
            </div>
            </form>


            <?php

            if (isset($_POST['simpan'])) {
                $nama = $_POST['nama'];
                $simpan = $koneksi->query("INSERT INTO tbl_kategori (kategori_nama) VALUES('$nama')");

                if ($simpan == TRUE) {
                    echo "<script>
             alert ('Data Berhasil Di Simpan')
             window.location= '?page=pages/kategori/view'
            </script>";
                } else {
                    echo "<script>
            alert ('Data Gagal Di Simpan')
            window.location= '?page=pages/kategori/view'
           </script>";
                }
            }



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