{% extends "frontend/base.html" %}
{% block "content" %}

{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-danger" role="alert">
    {{ field.name }}: {{ error }}
  </div>
{% endfor %}
{% endfor %}
{% endif %}
                    <div class="card shadow mb-4">
                        <div class="card-header py-3">
                            <h6 class="m-0 font-weight-bold text-primary">Edit {{ object.title }}</h6>
                        </div>
                        <div class="card-body">
                            <form action="" method="POST" enctype="multipart/form-data">
                            {% csrf_token %}
                            <div class="table-responsive">
                                <table>
                                    <tr><th><label for="id_timestamp">Timestamp:</label></th><td><input type="text" name="timestamp" value="{% if object.timestamp %}{{ object.timestamp | date:"Y-m-d H:i" }}{% else %}{% now "Y-m-d H:i" %}{% endif %}" required id="id_timestamp"><input type="hidden" name="initial-timestamp" value="2020-12-26 19:24:14" id="initial-id_timestamp"></td></tr>
                                    <tr><th><label for="id_type">Type:</label></th><td><select name="type" required="" id="id_type">
                                        {% for value, text in form.type.field.choices %}
                                        <option value="{{ value }}" {% if object.type == value %}selected{% endif %}>{{ text }}</option>
                                        {% endfor %}
                                      
                                      </select></td></tr>
                                    <tr><th><label for="id_title">Title:</label></th><td><input value="{{ object.title }}" type="text" name="title" maxlength="64" id="id_title"></td></tr>

                                    <tr><th><label for="id_content">Text:</label></th><td><textarea name="content" cols="40" rows="10" id="id_content">{{ object.content }}</textarea></td></tr>

                                    <tr><th><label for="id_mood">Mood:</label></th><td><select name="mood" class="dtb" required id="id_mood">
                                        <option value="" {% if not object.mood %}selected{% endif %}>---------</option>
    
                                        {% for mood in request.user.mood_set.all|dictsort:"value" %}
                                        <option data-icon="{{ mood.icon }}" value="{{ mood.id }}" {% if object.mood == mood %}selected{% endif %}>{{ mood }}</option>
                                        {% endfor %}
    
                                        </select></td></tr>


                                    <tr><th><label for="id_lucid">Lucid:</label></th><td><input type="checkbox" {% if object.lucid %}checked{% endif %} name="lucid"> <i class="fas fa-exclamation"></i> Lucid Dream?<br></td></tr>
                                    <tr><th><label for="id_lucid">Wet:</label></th><td><input type="checkbox" {% if object.wet %}checked{% endif %} name="wet"> <i class="fas fa-tint"></i> Wet Dream?<br></td></tr>

                                    <tr><th><label for="activities">Themes:</label></th><td>
                                        {% for theme in request.user.theme_set.all %} 
                                            <input type="checkbox" {% if theme in object.theme_set %}checked{% endif %} value="{{ theme.id }}" name="themes"> <i class="{{ theme.icon }}" style="color:{{ theme.color }};"></i> {{ theme }}<br>
                                        {% endfor %}
                                    </td></tr>

                                    <tr><th><label for="id_uploads">Uploads:</label></th><td><input type="file" name="uploads" id="id_uploads" multiple="multiple"></td></tr>
                                </table>
                            </div>
                            <button style="margin-top: 20px;" class="form-control btn-primary" type="submit">Save</button>
                            </form>
                        </div>
                    </div>

{% endblock %}