<?php
include("connection.php");
include("header.php");
?>

<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">

            <!-- Page Title -->
            <div class="row">
                <div class="col-12">
                    <div class="page-title-box d-sm-flex align-items-center justify-content-between">
                        <h4 class="mb-sm-0 font-size-18">View Partner Logos</h4>
                    </div>
                </div>
            </div>

            <!-- Table Section -->
            <div class="row">
                <div class="col-lg-12">
                    <div class="card">
                        <div class="card-body">

                            <!-- Search & Add -->
                            <div class="row mb-2">
                                <div class="col-sm-6 mt-3">
                                    <div class="search-box me-2 d-inline-block">
                                        <div class="position-relative">
                                            <input type="text" class="form-control" id="searchInput"
                                                onkeyup="searchTable()" placeholder="Search...">
                                            <i class="bx bx-search-alt search-icon"></i>
                                        </div>
                                    </div>
                                </div>

                                <div class="col-sm-6 mt-3">
                                    <div class="text-sm-end">
                                        <a href="addpartner.php">
                                            <button type="button"
                                                class="btn btn-success btn-rounded waves-effect waves-light mb-2">
                                                <i class="mdi mdi-plus me-1"></i> Add Partner Logo
                                            </button>
                                        </a>
                                    </div>
                                </div>
                            </div>

                            <!-- Table -->
                            <div class="table-responsive">
                                <table
                                    class="table align-middle table-nowrap table-hover dt-responsive nowrap w-100">
                                    <thead class="table-light">
                                        <tr>
                                            <th>S.No</th>
                                            <th>Logo</th>
                                            <th>Status</th>
                                            <th style="width:200px;">Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        $i = 0;
                                        $query = "SELECT * FROM partner_logo ORDER BY id DESC";
                                        $result = mysqli_query($con, $query);

                                        while ($row = mysqli_fetch_assoc($result)) {
                                            $i++;
                                        ?>
                                            <tr>
                                                <td><?= $i; ?></td>

                                                <td>
                                                    <img src="assets/images/partner_logo/<?= htmlspecialchars($row['logo']); ?>"
                                                        width="120" alt="Partner Logo">
                                                </td>

                                                <td>
                                                    <?php if ($row['status'] == 1) { ?>
                                                        <span class="badge bg-success">Active</span>
                                                    <?php } else { ?>
                                                        <span class="badge bg-danger">Inactive</span>
                                                    <?php } ?>
                                                </td>

                                                <td>
                                                    <a href="editpartner.php?id=<?= $row['id']; ?>">
                                                        <button class="btn btn-primary btn-rounded mb-1">
                                                            <i class="far fa-edit"></i> Edit
                                                        </button>
                                                    </a>

                                                    <a href="deletepartner.php?id=<?= $row['id']; ?>"
                                                        onclick="return confirm('Are you sure you want to delete this logo?')">
                                                        <button class="btn btn-danger btn-rounded mb-1">
                                                            <i class="fas fa-trash"></i> Delete
                                                        </button>
                                                    </a>
                                                </td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                            <!-- End Table -->

                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>

<?php include("footer.php"); ?>
</div>
