<?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>Title</th>
            <th>Category</th>
            <th>Date Added</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $videos = $con->getRows('videos', array('order_by' => 'created_at desc'));
        if (!empty($videos)) {
            foreach ($videos as $video) {
                $date = date('M d, Y', strtotime($video['created_at']));
                ?>
                <tr>
                    <td><?= $video['title'] ?></td>
                    <td><?= $video['category'] ?></td>
                    <td><?= $date ?></td>
                    <td>
                        <div class="btn-toolbar mb-2 mb-md-0">
                            <div class="btn-group mr-2">
                                <a href="?video_id=<?=$video["id"]?>&action=update" class="btn btn-sm btn-outline-primary"><i class="icon icon-edit"></i> Edit</a>
                                <button class="btn btn-sm btn-outline-danger btn_delete" data-id3="<?php echo $video["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>
