 


<div id="page-wrapper">
  <div id="page-inner">
    <div class="row g-4">

        <!-- Add / Edit Form -->
        <div class="col-md-8">
           <?php
if (session_status() == PHP_SESSION_NONE) session_start();
if (!empty($_SESSION['message'])): ?>
    <div class="custom-alert" id="customAlert">
        <?= $_SESSION['message'] ?>
        <span class="close-btn" onclick="closeAlert()">&times;</span>
    </div>
<?php 
    unset($_SESSION['message']); // Clear message after displaying
endif;
?>


            <div class="card">
                <div class="card-header"><?= isset($_GET['edit']) ? 'Edit Testimonial' : 'Add Testimonial' ?></div>
                <div class="card-body">
                    <?php
                    $editData = null;
                    if (isset($_GET['edit'])) {
                        foreach ($testimonials as $t) {
                            if ($t['id'] == $_GET['edit']) {
                                $editData = $t;
                                break;
                            }
                        }
                    }
                    ?>
                    <form method="post" enctype="multipart/form-data">
                        <input type="hidden" name="id" value="<?= $editData['id'] ?? '' ?>">
                        <input type="hidden" name="old_image" value="<?= $editData['image'] ?? '' ?>">

                        <div class="mb-3">
                            <input type="text" name="title" class="form-control" required placeholder="Title" value="<?= $editData['title'] ?? '' ?>">
                        </div>

                        <div class="mb-3">
                            <label>Short Description:</label>
                            <textarea name="short_description" class="form-control" rows="3"><?= $editData['short_description'] ?? '' ?></textarea>
                        </div> 
                        <div class="mb-3">
                            <label>Upload Image:</label>
                            <input type="file" name="image" class="form-control" accept=".png,.jpg,.jpeg">
                            <?php if(!empty($editData['image'])): ?>
                                <img src="../assets/images/testimonials/<?= $editData['image'] ?>" width="80" class="mt-2">
                            <?php endif; ?>
                        </div>

                        <button type="submit" name="<?= isset($editData) ? 'edit' : 'add' ?>" class="btn btn-primary w-100">
                            <?= isset($editData) ? 'Update Testimonial' : 'Add Testimonial' ?>
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <!-- Testimonial List -->
        <div class="col-md-4">
            <div class="card">
                <div class="card-header">Testimonial List</div>
                <div class="card-body">
                    <table class="table table-bordered table-striped">
                        <thead class="table-dark">
                            <tr>
                                <th>#</th>
                                <th>Title</th>
                                <th>Image</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                        <?php foreach($testimonials as $index => $t): ?>
                            <tr>
                                <td><?= $index + 1 ?></td>
                                <td><?= $t['title'] ?></td>
                                <td>  <img src="../assets/images/testimonials/<?= $t['image'] ?>" width="50">
 
                                </td>
                                <td>
                                    <a href="?edit=<?= $t['id'] ?>" class="btn btn-sm btn-warning">  <i class="fas fa-edit"></i></a>
                                    <a href="?delete=<?= $t['id'] ?>" class="btn btn-sm btn-danger" onclick="return confirm('Delete this Testimonial?')"> <i class="fas fa-trash-alt"></i></a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>

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