<?php
    $article = $use->getArticleById($_GET['id']);
?>
<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">Update Article</h6>
                    </div>
                </div>
            </div>
            <div class="card-body">
                <form action="" method="post" enctype="multipart/form-data">
                    <div class="form-group mb-3">
                        <label for="">Title</label>
                        <input type="text" name="title" value="<?= $article['title'] ?>" required class="form-control">
                    </div>
                    <div class="form-group mb-3">
                        <label for="">Image</label>
                        <input type="file" name="file" class="form-control">
                        <img style="width: 80px; height: 80px; object-fit: cover"
                             src="../images/thumb/<?= $article['image'] ?>" alt="">
                    </div>
                    <div class="form-group mb-3">
                        <label for="">Content</label>
                        <textarea id="textEditor" name="content" required class="form-control"><?= $article['content'] ?></textarea>
                    </div>
                    <button type="submit" name="submit" class="btn btn-success">Update</button>
                </form>
                <?php
                if (isset($_POST['submit'])){
                    $use->update($_POST['title'],$_POST['content'],$_FILES['file'],$_GET['id']);
                    echo "<script>location='./?page=articles'</script>";
                }
                ?>
            </div>
        </div>
    </div>
</div>