{% extends "layout.jinja2" %}

{% block content %}
<div class="row">
    <div class="card mb-0">
        <div class="card-body">

    <form action="{{ url }}" method="post" class="form needs-validation">

        <div class="mb-3">
            <label class="form-label required-field" for="title">Titre</label>
            <input class="form-control" name="title" type="text" value="{{entry.title}}" required>
        </div>

        <div class="mb-3">
            <label class="form-label required-field" for="content_type">Content type</label>
            <select class="form-control" id="content_type" name="content_type" value="{{ entry.content_type}}">
                <option value="text/html" 
                {% if entry.content_type == "text/html" %} selected {% endif %}>text/html</option>
                <option value="text/x-rst"
                {% if entry.content_type == "text/x-rst" %} selected {% endif %}>text/x-rst</option>
                <option value="text/markdown"
                {% if entry.content_type == "text/markdown" %} selected {% endif %}>text/markdown</option>
            </select>
       </div>

        <div class="mb-3">
            <label class="form-label required-field" for="description">Description</label>
            <textarea class="form-control monospace-font" id="description" name="description" rows="2" cols="35">{{ entry.description }}</textarea>
        </div>

        <div class="mb-3">
            <label class="form-label required-field" for="body">Corps du texte</label>
            <textarea class="form-control monospace-font" id="body" name="body" required rows="20" cols="35">{{ entry.body }}</textarea>
        </div>

        <div class="mb-3">
            <label class="form-label required-field" for="language">Langue</label>
            <select class="form-control" id="language" name="language" value="{{ entry.language}}">
                <option value="en" 
                {% if entry.language == "en" %} selected {% endif %}>english</option>
                <option value="fr"
                {% if entry.language == "fr" %} selected {% endif %}>français</option>
                <option value="vi"
                {% if entry.language == "vi" %} selected {% endif %}>vietnamien</option>
            </select>
       </div>

        <div class="mb-3">
            <label class="form-label required-field" for="tag">Tag</label>
            <select class="form-control" id="tag" name="tag" value="{{ entry.tag }}">
                {% for x in tags %}
                <option value="{{x.tag}}"
                {% if entry.tag == x.tag %} selected {% endif %}>{{x.tag_name}}</option>
                {% endfor %}
            </select>
        </div>

        <div class="mb-3">
            <label class="form-label required-field" for="author">Auteur</label>
            <input class="form-control" name="author" type="text" value="{{entry.author}}" required>
        </div>

        <div class="mb-3">
            <label class="form-label for="author">Source lien</label>
            <input class="form-control" name="source_link" type="text" value="{{entry.source_link}}">
        </div>

        <div class="mb-3">
            <label class="form-label for="author">Source titre</label>
            <input class="form-control" name="source_title" type="text" value="{{entry.source_title}}">
        </div>

        <div class="mb-3">
            <label class="form-label for="author">Contenu corrélé</label>
            <input class="form-control" name="related" type="text" value="{{entry.related}}">
        </div>

        <div class="mb-3">
            <label class="form-label required-field" for="status">Statut</label>
            <select class="form-control" id="status" name="status" value="{{ entry.status}}">
                <option value="brouillon" 
                {% if entry.status == "brouillon" %} selected {% endif %}>Brouillon</option>
                <option value="privé"
                {% if entry.status == "privé" %} selected {% endif %}>Privé</option>
                <option value="publié"
                {% if entry.status == "publié" %} selected {% endif %}>Publié</option>
            </select>
       </div>

        <div class="mb-3">
            <label class="form-label required-field" for="created">Créé le</label>
             <input class="form-control" name="created" type="text" value="{{entry.created}}" required>
        </div>

        <p>    
            Topic : <strong>{{ entry.topic_id }}</strong> - <strong>{{ entry.tag }}</strong><br>
            {% if blog_id != '0' %}
                Modifié le : <strong>{{ entry.edit_date }}</strong>
            {% endif %}
        </p>
        <br />
        <div class="mb-3">
            <a class="btn btn-light" href="{{ url_retour }}">Retour</a>
            <button class="btn btn-primary" type="submit" name="form.submitted">Enregistrer</button>
            {% if blog_id != '0' %}
                <button class="btn btn-danger" type="button" data-bs-toggle="modal" data-bs-target="#confirmDelete">Supprimer</button>
            {% endif %}
        </div>

        <p class="text-center">Apprendre la syntaxe de <a href="https://daringfireball.net/projects/markdown/syntax" 
            target="_blank">Markdown</a></li></p>

    </form>

    <!-- Modal : Confirmation SUPRESSION  -->
    <div id="confirmDelete" class="modal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Supprimer une page</h4>
                </div>
                <div class="modal-body">
                    <!-- The form is placed inside the body of modal -->
                        <p>Etes-vous certain(e) de vouloir supprimer <b><br>
                        {{ entry.title }}</b> ?</p>
                </div>
                <div class="modal-footer">
                    <form id="confirmForm" method="post">
                        <button type="submit" class="btn btn-danger" name="form.deleted">Supprimer</button>
                        <button type="button" class="btn btn-success" data-bs-dismiss="modal">Fermer</button>
                    </form>
                </div>
            </div>
        </div>
    </div>
        </div>
    </div>
</div>
{% endblock %}
