{% extends "layout.jinja2" %}

{% block content %}
<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="topic">Topic</label>
            <input class="form-control" name="topic" type="text" value="{{entry.topic}}" required>
        </div>

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

        <div class="mb-3">
            <label class="form-label required-field" for="topic_language">Language</label>
            <select class="form-control" id="language" name="topic_language" value="{{ entry.topic_language }}">
                <option value="en" 
                {% if entry.topic_language == "en" %} selected {% endif %}>en</option>
                <option value="fr" 
                {% if entry.topic_language == "fr" %} selected {% endif %}>fr</option>
                <option value="vn"
                {% if entry.topic_language == "vi" %} selected {% endif %}>vi</option>
            </select>
       </div>

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

        <div class="mb-3">
            <a class="btn btn-light" href="{{ request.route_url('topics') }}">
                <span class="ti ti-chevron-left"></span> Retour</a>
            <button class="btn btn-primary" type="submit" name="form.submitted">
                <span class="ti ti-check"></span> Enregistrer</button>
            {% if entry.topic != '0' %}
                <button class="btn btn-danger" type="button" data-bs-toggle="modal" data-bs-target="#confirmDelete">
                <span class="ti ti-x"></span> Supprimer</button>
            {% endif %}
        </div>

    </form>

    <h3>Liste des Tags</h3>
	<p><a href="{{ request.route_url('tag_edit', topic=entry.topic, id='0') }}"  class="btn btn-success" role="button">
		<span class="ti ti-plus"></span> Nouveau</a>
	</p>

    <table id="users_list" class="table table-striped table-bordered table-sm">
        <thead>
            <tr>
                <th>Tag</th>
                <th>Nom du tag</th>
            </tr>
        </thead>
        <tbody class="table-group-divider">
        {% for entry in tags %}
            <tr>
                <td>{{ entry.tag }}</td>
                <td>
                    <a href="{{ request.route_url('tag_edit', topic=entry.topic, id=entry.id) }}">
                        {{ entry.tag_name }}
                    </a>
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    <!-- Modal : Confirmation SUPRESSION  -->
    <div id="confirmDelete" class="modal" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Supprimer le Topic</h4>
                </div>
                <div class="modal-body">
                    <!-- The form is placed inside the body of modal -->
                        <p>Etes-vous certain(e) de vouloir supprimer le Topic <b>{{ entry.topic_name }}</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>
</div>

{% endblock %}
