<?php

include "../../config/koneksi.php";

$query = mysqli_query(
    $koneksi,
    "SELECT * FROM layanan ORDER BY id DESC"
);

?>

<!DOCTYPE html>
<html>

<head>
    <link rel="icon"
        type="image/png"
        href="/website-dispussip/assets/img/logo.PNG">
    <meta charset="UTF-8">
    <title>Kelola Layanan</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

    <style>
        body {
            background: #f4f6f9;
        }

        .card {
            border: none;
            border-radius: 15px;
        }

        .table th {
            background: #0d6efd;
            color: white;
            text-align: center;
        }

        .table td {
            vertical-align: middle;
        }

        img {
            width: 100px;
            height: 70px;
            object-fit: cover;
            border-radius: 8px;
        }

        .btn {
            border-radius: 8px;
        }
    </style>

</head>


<body>


    <div class="container py-4">


        <div class="card shadow">


            <div class="card-header bg-primary text-white d-flex justify-content-between">


                <h4>
                    Kelola Layanan
                </h4>


                <a href="tambah.php" class="btn btn-light btn-sm">
                    + Tambah Layanan
                </a>


            </div>



            <div class="card-body">


                <table class="table table-bordered table-hover">


                    <thead>

                        <tr>

                            <th>No</th>
                            <th>Gambar</th>
                            <th>Judul</th>
                            <th>Deskripsi</th>
                            <th>Aksi</th>

                        </tr>

                    </thead>


                    <tbody>


                        <?php

                        $no = 1;

                        while ($data = mysqli_fetch_assoc($query)) {

                        ?>


                            <tr>


                                <td class="text-center">
                                    <?= $no++; ?>
                                </td>



                                <td class="text-center">

                                    <?php if ($data['gambar'] != "") { ?>

                                        <img src="../../uploads/layanan/<?= $data['gambar']; ?>">

                                    <?php } else { ?>

                                        Tidak ada

                                    <?php } ?>

                                </td>




                                <td>

                                    <?= htmlspecialchars($data['judul']); ?>

                                </td>



                                <td>

                                    <?= substr(htmlspecialchars($data['deskripsi']), 0, 80); ?>...

                                </td>



                                <td class="text-center">


                                    <a href="edit.php?id=<?= $data['id']; ?>"
                                        class="btn btn-warning btn-sm">

                                        Edit

                                    </a>



                                    <a href="hapus.php?id=<?= $data['id']; ?>"
                                        onclick="return confirm('Hapus layanan?')"
                                        class="btn btn-danger btn-sm">

                                        Hapus

                                    </a>


                                </td>



                            </tr>


                        <?php } ?>


                    </tbody>


                </table>


            </div>


        </div>


    </div>


</body>

</html>