{% extends 'base.html' %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
<div class="container-fluid">
    <div class="row">
        <div class="col">
            <div class="container-fluid shadow-sm p-2 mb-5 bg-white rounded">
                <h5 class="card-header">Account</h5>
                    <div class="card-body"> 
                        <div class="media">
                            <img class="rounded-circle account-img" src="{{ image_file }}" style="margin-right: 20px;" alt="" width="125" height="125">
                            <div class="media-body">
                                <h2 class="account-heading">{{ current_user.username }}</h2>
                                <p class="text-secondary">{{ current_user.email }}</p>
                            </div>
                        </div>
                        <div class="content-section card-body">
                            <form method="POST" action="" enctype="multipart/form-data">
                                {{ form.hidden_tag() }}
                                <fieldset class="form-group">
                                    <legend class="border-bottom mb-4">Account Info</legend>
                                    <div class="form-group">
                                        {{ form.username.label(class="form-control-label") }}
                    
                                        {% if form.username.errors %}
                                            {{ form.username(class="form-control is-invalid") }}
                                            <div class="invalid-feedback">
                                                {% for error in form.username.errors %}
                                                <span>{{ error }}</span>
                                                {% endfor %}
                                            </div>
                                        {% else %}
                                            {{ form.username(class="form-control form-control") }}
                                        {% endif %}               
                                    </div>
                    
                                    <div class="form-group">
                                        {{ form.email.label(class="form-control-label") }}
                                        
                                        {% if form.email.errors %}
                                        {{ form.email(class="form-control is-invalid") }}
                                        <div class="invalid-feedback">
                                            {% for error in form.email.errors %}
                                            <span>{{ error }}</span>
                                            {% endfor %}
                                        </div>
                                    {% else %}
                                        {{ form.email(class="form-control form-control") }}
                                    {% endif %}  
                                    </div>
                                    <div class="form-group">
                                        {{ form.picture.label() }}
                                        {{ form.picture(class="form-control-file") }}
                                        {% if form.picture.errors %}
                                            {% for error in form.picture.errors %}
                                                <span class="text-danger">{{ error }}</span></br>
                                            {% endfor %}
                                        {% endif %}
                                    </div>
                                </fieldset>
                                <div class="form-group">
                                    {{ form.submit(class="btn btn-outline-info") }}
                                </div>
                            </form>
                        </div>
                        <div class="content-section card-body">
                            <form method="POST" action="" enctype="multipart/form-data">
                                {{ form.hidden_tag() }}
                                <fieldset class="form-group">
                                    <legend class="border-bottom mb-4">Danger Zone</legend>
                                        <div class="card border-danger">
                                            <div class="card-body">
                                                <div class="row">
                                                    <div class="col">
                                                        <a class="font-weight-bold">Delete your account</a></br>
                                                        <a>Once you deleted your account, there is no going back.</a>
                                                    </div>
                                                    <div class="col col-md-4 text-center">
                                                        <button type="button" class="btn btn-danger float-right" data-toggle="modal" data-target="#deletionModal" style="margin-top: 5px;">Delete Account</button>

                                                        <!-- Modal -->
                                                        <div class="modal fade" id="deletionModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                                                                <div class="modal-dialog" role="document">
                                                                  <div class="modal-content">
                                                                    <div class="modal-header">
                                                                      <h5 class="modal-title" id="exampleModalLabel">Are you sure?</h5>
                                                                      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                                        <span aria-hidden="true">&times;</span>
                                                                      </button>
                                                                    </div>
                                                                    <div class="modal-body">
                                                                        <div class="alert alert-warning" role="alert">
                                                                                <h5 class="alert-heading"><i class="fa fa-warning"></i> Warning!</h5>
                                                                            Please read carefully!
                                                                        </div>
                                                                        <div>
                                                                            <p>
                                                                                This action <strong>deletes your account</strong> completely!
                                                                                All information will be irrevocably deleted from the database. 
                                                                                Restoring the data is no longer possible after this action has been completed.
                                                                            </p>
                                                                        </div>
                                                                        <div class="form-group">
                                                                            <p>Type in your email adress to confirm.</p>    
                                                                            {{ deletion_form.confirmation(class="form-control form-control") }}
                                                                        </div>
                                                                    </div>
                                                                    <div class="modal-footer">
                                                                        <div class="form-group">
                                                                                {{ deletion_form.submit(class="btn btn-outline-danger btn-block") }}
                                                                        </div>
                                                                    </div>
                                                                  </div>
                                                                </div>
                                                              </div>
                                                        <!-- Modal end -->

                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                            </form>
                        </div>
                    </div>
            </div>
        </div>
        <div class="col">
            <div class="container-fluid shadow-sm p-2 mb-5 bg-white rounded">
                <h5 class="card-header">Additional account informations</h5>
                    <div class="card-body">
                        <ul class="list-group">
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                              Login count:
                              <span class="badge badge-primary badge-pill">{{ current_user.login_count }}</span>
                            </li>
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                              Last login:
                              <span class="badge badge-primary badge-pill">{{ current_user.last_login.strftime("%d.%m.%Y, %H:%M:%S") }} UTC </span>
                            </li>
                            <li class="list-group-item d-flex justify-content-between align-items-center">
                              Last IP:
                              <span class="badge badge-primary badge-pill">{{ current_user.last_ip }}</span>
                            </li>
                          </ul>
                    </div>
            </div>
        </div>
    </div>
</div>



{% endblock %}