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

<body id="conteneur-admin">
    <?php include("views/components/utilisateurs/section_employe.php") ?>
    <div class="conteneur-admin plat">

        <?php if (isset($_GET["echec_modification"])) : ?>
            <p class="alert alert-danger alert-dismissible fade show mt-3">
                <span class="material-icons">
                    error
                </span>
                Échec lors de la modification du plat.. Réessayer plustard!
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </p>
        <?php endif; ?>

        <?php if (isset($_GET["infos_requises"])) : ?>
            <p class="alert alert-warning alert-dismissible fade show mt-3">
                <span class="material-icons">
                    warning
                </span>
                Tous les champs sont obligatoires, sauf l'image!
                <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
            </p>
        <?php endif; ?>

        <h3 id="modifier-ajouter">Modifier un plat</h3>
        <section>
            <form action="admin-menu-changer" method="POST" class="un-employe-plat" enctype="multipart/form-data">
                <input type="hidden" name="id" value="<?= $_GET["id"] ?>">
                <label>
                    <p>Nom</p>
                    <input type="text" name="nom" autofocus value="<?= $plat->nom ?>">
                </label>
                <label>
                    <p>Description</p>
                    <input type="text" name="description" value="<?= $plat->description ?>">
                </label>
                <label>
                    <p>Prix ($)</p>
                    <input type="number" name="prix"" value="<?= $plat->prix ?>">
                </label>
                <div class="plat-select">
                    <label>
                        <p>Catégorie</p>
                        <select name="categorie">
                            <?php foreach ($categories as $categorie) : ?>
                                <option value="<?= $categorie->id ?>" <?= $categorie->id == $plat->categorie_id ? "selected" : "" ?>>
                                    <?= $categorie->nom ?></option>
                            <?php endforeach; ?>
                        </select>
                    </label>
                    <label>
                        <p>Tags</p>
                        <select name="tags[]" class="menu_tags" multiple >
                            <?php foreach ($tags as $tag) : ?>
                                <option value="<?= $tag->id ?>" 
                                    <?php foreach ($menu_tags as $menu_tag) : ?>
                                        <?= $menu_tag->tag_id == $tag->id ? "selected" : "" ?>
                                    <?php endforeach;?>>
                                <?= $tag->nom ?></option>
                            <?php endforeach; ?>
                        </select>
                    </label>
                </div>
                <label>
                    <p>Image</p>
                    <input type="file" name="image">
                </label>
                <input type="submit" value="Modifier" class="menu-bouton bouton-modifier-ajouter">
            </form>
        </section>
    </div>
    <?php include("views/components/foot_js.php") ?>