<?php
session_start();
include_once('../../config/class.php');
$con = new DB;
?>

<table id="order-listing" class="table table-striped table-bordered table-sm">
    <thead>
        <tr>
            <th>Image</th>
            <th>Title</th>
            <th>Category</th>
            <th>Status</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $galleries = $con->getRows('gallery', array('order_by' => 'date_posted desc'));
        if (!empty($galleries)) {
            foreach ($galleries as $gallery) {
                $status = $gallery['status'] == 1 ? '<span class="badge badge-success">Active</span>' : '<span class="badge badge-danger">Inactive</span>';
                ?>
                <tr>
                    <td><img src="../../../assets/uploads/gallery/<?= $gallery['image'] ?>" width="80" height="60" style="object-fit: cover; border-radius: 4px;"> </td>
                    <td><?= $gallery['title'] ?></td>
                    <td><?= $gallery['category'] ?></td>
                    <td><?= $status ?></td>
                    <td>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <div class="btn-group mr-2">
                                <a href="?gallery_id=<?=$gallery["gallery_id"]?>&action=update" class="btn btn-sm btn-outline-primary"><i class="icon icon-edit"></i> Edit</a>
                                <?php if($gallery['status'] == 1){ ?>
                                <button class="btn btn-sm btn-outline-warning btn_hide" data-id="<?php echo $gallery["gallery_id"]; ?>"><i class="icon icon-eye-off"></i> Hide</button>
                                <?php } else { ?>
                                <button class="btn btn-sm btn-outline-info btn_show" data-id="<?php echo $gallery["gallery_id"]; ?>"><i class="icon icon-eye"></i> Show</button>
                                <?php } ?>
                                <button class="btn btn-sm btn-outline-danger btn_delete" data-id3="<?php echo $gallery["gallery_id"]; ?>"><i class="icon icon-trash"></i> Delete</button>
                            </div>
                        </div>
                    </td>
                </tr>
        <?php        }
        }
        ?>
    </tbody>
</table>

<script>
    (function($) {
        'use strict';
        $(function() {
            $('#order-listing').DataTable({
                "aLengthMenu": [
                    [5, 10, 15, -1],
                    [5, 10, 15, "All"]
                ],
                "iDisplayLength": 10
            });
        });
    })(jQuery);
</script>
