<?php
    if (isset($_GET['delete'])){
        $use->delete($_GET['delete']);
        echo "<script>location='./?page=articles'</script>";
    }
?>
<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-transparent">
                <div class="row align-items-center">
                    <div class="col">
                        <h6 class="text-uppercase text-muted ls-1 mb-1">List Articles | <a class="btn btn-primary"
                                                                                           href="./?page=article-new">New</a>
                        </h6>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <table class="table table-striped" id="myTable">
                    <thead>
                    <tr>
                        <th width="50">#</th>
                        <th>Title</th>
                        <th>Image</th>
                        <th>Total View</th>
                        <th>Action</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($use->getAllArticles() as $article): ?>
                        <tr>
                            <td>#</td>
                            <td><?= $article['title'] ?></td>
                            <td width="150">
                                <img style="width: 80px; height: 80px; object-fit: cover"
                                     src="../images/thumb/<?= $article['image'] ?>" alt="">
                            </td>
                            <td width="50"><?= $article['views'] ?></td>
                            <td width="150">
                                <a href="./?page=articles&delete=<?= $article['id'] ?>" class="btn btn-danger btn-sm">Delete</a>
                                <a href="../article.php?url=<?= urldecode($article['url']) ?>" target="_blank" class="btn btn-success btn-sm">View</a>
                                <a href="./?page=articles-edit&id=<?= $article['id'] ?>" class="btn btn-info btn-sm">Edit</a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>