{% extends 'backoffice/base.html' %}

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

{% block metaseo %} 

        <meta name="robots" content="index, follow, ">
        <meta name="title" content="">

        <meta name="description"
        content="">

        <meta property="og:title" content="" />

        <meta name="keywords" content=''>
        
{% endblock %}

{% block content %}

<script>
    document.getElementById('menu-users').classList.add('is-active')
    </script>
    <section class="section is-title-bar" >

        <div class="level">
          <div class="level-left">
            <div class="level-item">
              <ul >
                <li style="font-size: 15px !important; ">AZ</li>
                <li style="font-size: 15px !important; ">Utilisateurs</li>
              </ul>
            </div>
          </div>
          <div class="level-right">
            <div class="level-item">
              <button onclick="openPopup('user-modal')" class="button is-info is-dark is-small">Ajouter un Utilisateur</button>
            </div>
            
          </div>
        </div>

    </section>

    <div class="container" style="min-height: 85vh;">

        <div class="card m-3 has-table">
            <header class="card-header">
              <p class="card-header-title">
                <span class="icon"><i class="mdi mdi-account-multiple"></i></span>
                Utilisateurs
              </p>
              <a href="#" class="card-header-icon">
                <span class="icon"><i class="mdi mdi-reload"></i></span>
              </a>
            </header>
            <div class="card-content">

              {% if count < 1 %}
                <p class="subtitle is-5 my-4 has-text-centered">Vous n'avez aucun utilisateur à gérer.</p>
                
              {% else %}
              <div class="b-table has-pagination">
                <div class="table-wrapper has-mobile-cards">
                  <table class="table is-fullwidth is-striped is-hoverable is-fullwidth">
                    <thead>
                    <tr>
                      <th class="is-checkbox-cell">
                        {% comment %} <label class="b-checkbox checkbox">
                          <input type="checkbox" value="false">
                          <span class="check"></span>
                        </label> {% endcomment %}
                      </th>
                      <th></th>
                      <th>Email</th>
                      <th>Prénom Nom</th>
                      <th>Téléphone</th>
                      <th>Type</th>
                      <th>Créé le</th>
                      <th></th>
                    </tr>
                    </thead>
                    <tbody>

                      {% for c in users %}

                      <tr>
                        <td class="is-checkbox-cell">
                          <label class="b-checkbox checkbox">
                            <input type="checkbox" value="false">
                            <span class="check"></span>
                          </label>
                        </td>
                        <td class="is-image-cell is-user-avatar">
                          {% if c.image  %}
                          <img style="width: 30px;height:30px" src="{{c.image.url}}"
                              alt=" ">
                          {% else %}
                          <img style="width: 30px;height:30px" src="https://api.dicebear.com/9.x/initials/svg?seed={{c.user.first_name}} {{c.user.last_name}}"
                              alt="{{c.user.first_name}} {{c.user.last_name}}">
                          {% endif %}
                        </td>
                        <td data-label="Email">{{c.user.username}}</td>
                        <td data-label="Prénom et nom">{{c.user.first_name}} {{c.user.last_name}}</td>
                        
                        <td data-label="Téléphone">{{c.phone}}</td>
                        <td data-label="Type">{{c.type}}</td>
                        

                        
                        {% comment %} <td data-label="Status" class="is-status-cell">
                          <span class="tag is-success">Active</span>
                        
                        {% comment %} <td data-label="Progress" class="is-progress-cell">
                          <progress max="100" class="progress is-small is-info" value="79">79</progress>
                        </td> {% endcomment %}
                        
                        <td class="is-actions-cell">
                          <div class="buttons is-right">
                            {% comment %} <button class="button is-small is-info is-light " type="button">
                              <span class="icon"><i class="mdi mdi-pencil-box"></i></span>
                            </button> {% endcomment %}
                            <button onclick="deleteUser(`{% url 'app:deleteUser' %}?userId={{c.id}}`)" class="button is-small is-danger is-light jb-modal" data-target="sample-modal" type="button">
                              <span class="icon is-medium"><i class="mdi mdi-trash-can"></i></span>
                            </button>
                          </div>
                        </td>
                      </tr>
                      
                      {% endfor %}
                    
                    
                    
                    

                    </tbody>
                  </table>
                </div>
                
                {% comment %} pagination {% endcomment %}

                {% if nbpage > 1 %}

                    <div class="notification">
                      <div class="level">
                        <div class="level-left">
                          <div class="level-item">
                            <div class="buttons has-addons">

                              {% if customers.has_previous %}
                                  <button onclick="goTo('?page={{ customers.previous_page_number }}')" type="button" class="button ">{{ customers.previous_page_number }}</button>
                              {% endif %}

                              <button type="button" class="button is-active">{{customers.number}}</button>

                              {% if customers.has_next %}
                                  <button onclick="goTo('?page={{ customers.next_page_number }}')" type="button" class="button">{{ customers.next_page_number }}</button>
                              {% endif %}
                            </div>
                          </div>
                        </div>
                        <div class="level-right">
                          <div class="level-item">
                            <small>Page {{customers.number}} sur {{nbpage}}</small>
                          </div>
                        </div>
                      </div>
                    </div>

                  {% endif %}

              </div>
              {% endif %}
            </div>
          </div>


    </div>


    {% include "partials/users/user-form.html" %}



    <script>

      function deleteUser(path) {
        Swal.fire({
          title: " Confirmation",
          text: " Voulez vous vraiment confirmer? ",
          
          showCancelButton: true,
          confirmButtonColor: "#3e8ed0",
          cancelButtonColor: "#d33",
          confirmButtonText: "Confirm",
          cancelButtonText: "Annuler",
          // preConfirm: (response) => {

          //     if (!response) {
          //         Swal.showValidationMessage("Tapez delete pour confirmer");
          //     }
          // },
      }).then((result) => {
          if (result.isConfirmed) {
              goTo(path)

          } else {


          }
      });
      }
    </script> 
{% endblock content %}