<?php include("views/components/head.php") ?>

<main class="modification">
    <div class="formulaire">
        <h1>Modifier le plat</h1>

        <?php if (isset($_GET["infos_requises"])) : ?>
            <p class="msg erreur">
                <span class="material-icons">
                    error
                </span>
                Toutes les informations sont requises
            </p>
        <?php endif; ?>


        <form action="plats-actualiser" method="POST" enctype="multipart/form-data">
            <input type="hidden" name="id" value="<?= $_GET["id"] ?>">
            <label>Nom:
                <input type="text" name="nom" value="<?= $plat->nom ?>">
            </label>
            <label>Description:
                <textarea name="description"><?= $plat->description ?></textarea>
            </label>
            <label>Prix:
                <input type="text" name="prix" value="<?= $plat->prix ?>">
            </label>
            <div class="option">
                <label>
                    Catégorie:
                    <select class="form-select" name="categorie_id">
                        <?php foreach ($categories as $categorie) : ?>
                            <option value="<?= $categorie->id ?>" <?php if ($categorie->id == $plat->categorie_id) echo "selected" ?>>
                                <?= $categorie->nom ?>
                            </option>
                        <?php endforeach; ?>
                    </select>
                </label>
            </div>
            <div class="selection">
                <h1>Selectionnez les tags:</h1>
                <div>
                    <?php foreach ($tags as $tag) : ?>
                        <label class="container"><?= $tag->nom ?>
                            <input type="checkbox" name="tags[]" value="<?= $tag->id ?>" <?php foreach ($tagsParPlat as $tagParPlat){ if ($tagParPlat->tag_id == $tag->id) echo "checked"; }  ?>>
                            <span class="checkmark"></span>
                        </label>
                    <?php endforeach; ?>
                </div>
            </div>
            <div class="upload">
                <div class="upload">

                    <?php if (!empty($plat->image)) : ?>
                        <img src="<?= $plat->image ?>">
                    <?php endif; ?>

                    <input type="file" name="media">
                </div>
                <input type="submit" value="modifier le plat">
        </form>
    </div>
</main>
<?php include("views/components/foot.php") ?>