
<nav class="navbar navbar-top navbar-expand navbar-dashboard navbar-dark ps-0 pe-2 pb-0">
              <div class="container-fluid px-0">
                <div class="d-flex justify-content-between w-100" id="navbarSupportedContent">
                  <div class="d-flex align-items-center">
                    <!-- Search form -->
                    <form class="navbar-search form-inline" id="navbar-search-main">
                        <div class="input-group input-group-merge search-bar">
                            <span class="input-group-text" id="topbar-addon">
                                <svg class="icon icon-xs" x-description="Heroicon name: solid/search" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                                    <path fill-rule="evenodd" d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z" clip-rule="evenodd"></path>
                                </svg>
                            </span>
                            {% if request.path == '/settings' %}
                                <input 
                                    type="text" 
                                    class="form-control disabled" 
                                    id="topbarInputIconLeft" 
                                    placeholder="Chercher un profil" 
                                    aria-label="Search" 
                                    aria-describedby="topbar-addon" 
                                    disabled>
                            {% else %}
                                <input 
                                    type="text" 
                                    class="form-control" 
                                    id="topbarInputIconLeft" 
                                    placeholder="Chercher un profil" 
                                    aria-label="Search" 
                                    aria-describedby="topbar-addon">
                            {% endif %}
                        </div>
                    </form>
                    <!-- / Search form -->
                  </div>
                  <!-- Navbar links -->
                  <ul class="navbar-nav align-items-center">
                    <li class="nav-item dropdown">
                      <a class="nav-link text-dark notification-bell unread">
                        <svg class="icon icon-sm text-gray-900" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 2a6 6 0 00-6 6v3.586l-.707.707A1 1 0 004 14h12a1 1 0 00.707-1.707L16 11.586V8a6 6 0 00-6-6zM10 18a3 3 0 01-3-3h6a3 3 0 01-3 3z"></path></svg>
                      </a>
                      <div class="dropdown-menu dropdown-menu-lg dropdown-menu-center mt-2 py-0">
                        <div class="list-group list-group-flush">
                          <a href="#" class="text-center text-primary fw-bold border-bottom border-light py-3">Notifications</a>
                          <a href="#" class="list-group-item list-group-item-action border-bottom">
                            <div class="row align-items-center">
                                <div class="col-auto">
                                  <!-- Avatar -->
                                  <img alt="Image placeholder" src="{{ config.ASSETS_ROOT }}/img/team/profile-picture-1.jpg" class="avatar-md rounded">
                                </div>
                                <div class="col ps-0 ms-2">
                                  <div class="d-flex justify-content-between align-items-center">
                                      <div>
                                        <h4 class="h6 mb-0 text-small">Jose Leos</h4>
                                      </div>
                                      <div class="text-end">
                                        <small class="text-danger">a few moments ago</small>
                                      </div>
                                  </div>
                                  <p class="font-small mt-1 mb-0">Added you to an event "Project stand-up" tomorrow at 12:30 AM.</p>
                                </div>
                            </div>
                          </a>
                          <a href="#" class="list-group-item list-group-item-action border-bottom">
                            <div class="row align-items-center">
                                <div class="col-auto">
                                  <!-- Avatar -->
                                  <img alt="Image placeholder" src="{{ config.ASSETS_ROOT }}/img/team/profile-picture-2.jpg" class="avatar-md rounded">
                                </div>
                                <div class="col ps-0 ms-2">
                                  <div class="d-flex justify-content-between align-items-center">
                                      <div>
                                        <h4 class="h6 mb-0 text-small">Neil Sims</h4>
                                      </div>
                                      <div class="text-end">
                                        <small class="text-danger">2 hrs ago</small>
                                      </div>
                                  </div>
                                  <p class="font-small mt-1 mb-0">You've been assigned a task for "Awesome new project".</p>
                                </div>
                            </div>
                          </a>
                          <a href="#" class="list-group-item list-group-item-action border-bottom">
                            <div class="row align-items-center">
                                <div class="col-auto">
                                  <!-- Avatar -->
                                  <img alt="Image placeholder" src="{{ config.ASSETS_ROOT }}/img/team/profile-picture-1.jpg" class="avatar-md rounded">
                                </div>
                                <div class="col ps-0 m-2">
                                  <div class="d-flex justify-content-between align-items-center">
                                      <div>
                                        <h4 class="h6 mb-0 text-small">Roberta Casas</h4>
                                      </div>
                                      <div class="text-end">
                                        <small>5 hrs ago</small>
                                      </div>
                                  </div>
                                  <p class="font-small mt-1 mb-0">Tagged you in a document called "Financial plans",</p>
                                </div>
                            </div>
                          </a>
                          <a href="#" class="list-group-item list-group-item-action border-bottom">
                            <div class="row align-items-center">
                                <div class="col-auto">
                                  <!-- Avatar -->
                                  <img alt="Image placeholder" src="{{ config.ASSETS_ROOT }}/img/team/profile-picture-4.jpg" class="avatar-md rounded">
                                </div>
                                <div class="col ps-0 ms-2">
                                  <div class="d-flex justify-content-between align-items-center">
                                      <div>
                                        <h4 class="h6 mb-0 text-small">Joseph Garth</h4>
                                      </div>
                                      <div class="text-end">
                                        <small>1 d ago</small>
                                      </div>
                                  </div>
                                  <p class="font-small mt-1 mb-0">New message: "Hey, what's up? All set for the presentation?"</p>
                                </div>
                            </div>
                          </a>
                          <a href="#" class="list-group-item list-group-item-action border-bottom">
                            <div class="row align-items-center">
                                <div class="col-auto">
                                  <!-- Avatar -->
                                  <img alt="Image placeholder" src="{{ config.ASSETS_ROOT }}/img/team/profile-picture-5.jpg" class="avatar-md rounded">
                                </div>
                                <div class="col ps-0 ms-2">
                                  <div class="d-flex justify-content-between align-items-center">
                                      <div>
                                        <h4 class="h6 mb-0 text-small">Bonnie Green</h4>
                                      </div>
                                      <div class="text-end">
                                        <small>2 hrs ago</small>
                                      </div>
                                  </div>
                                  <p class="font-small mt-1 mb-0">New message: "We need to improve the UI/UX for the landing page."</p>
                                </div>
                            </div>
                          </a>
                          <a href="#" class="dropdown-item text-center fw-bold rounded-bottom py-3">
                            <svg class="icon icon-xxs text-gray-400 me-1" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 12a2 2 0 100-4 2 2 0 000 4z"></path><path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"></path></svg>
                            View all
                          </a>
                        </div>
                      </div>
                    </li>
                    <li class="nav-item dropdown ms-lg-3">
                      <a class="nav-link dropdown-toggle pt-1 px-0" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        <div class="media d-flex align-items-center">
                          <img class="avatar rounded-circle" alt="Image placeholder" src="{{ config.ASSETS_ROOT }}/img/team/profile-picture-{{ current_user.username }}.jpg">
                          <div class="media-body ms-2 text-dark align-items-center d-none d-lg-block">
                            <span class="mb-0 font-small fw-bold text-gray-900">
                                <strong>{{ current_user.username }}</strong> 
                            </span>
                          </div>
                        </div>
                      </a>
                      <div class="dropdown-menu dashboard-dropdown dropdown-menu-end mt-2 py-1">
                        <a class="dropdown-item d-flex align-items-center" href="/settings">
                          <svg class="dropdown-icon text-gray-400 me-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-6-3a2 2 0 11-4 0 2 2 0 014 0zm-2 4a5 5 0 00-4.546 2.916A5.986 5.986 0 0010 16a5.986 5.986 0 004.546-2.084A5 5 0 0010 11z" clip-rule="evenodd"></path></svg>
                          Mon Profil
                        </a>
                        <a class="dropdown-item d-flex align-items-center" href="/settings">
                          <svg class="dropdown-icon text-gray-400 me-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M11.49 3.17c-.38-1.56-2.6-1.56-2.98 0a1.532 1.532 0 01-2.286.948c-1.372-.836-2.942.734-2.106 2.106.54.886.061 2.042-.947 2.287-1.561.379-1.561 2.6 0 2.978a1.532 1.532 0 01.947 2.287c-.836 1.372.734 2.942 2.106 2.106a1.532 1.532 0 012.287.947c.379 1.561 2.6 1.561 2.978 0a1.533 1.533 0 012.287-.947c1.372.836 2.942-.734 2.106-2.106a1.533 1.533 0 01.947-2.287c1.561-.379 1.561-2.6 0-2.978a1.532 1.532 0 01-.947-2.287c.836-1.372-.734-2.942-2.106-2.106a1.532 1.532 0 01-2.287-.947zM10 13a3 3 0 100-6 3 3 0 000 6z" clip-rule="evenodd"></path></svg>
                          Paramétrage
                        </a>
                        <a class="dropdown-item d-flex align-items-center" href="/help" target="_blank">
                          <svg class="dropdown-icon text-gray-400 me-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-2 0c0 .993-.241 1.929-.668 2.754l-1.524-1.525a3.997 3.997 0 00.078-2.183l1.562-1.562C15.802 8.249 16 9.1 16 10zm-5.165 3.913l1.58 1.58A5.98 5.98 0 0110 16a5.976 5.976 0 01-2.516-.552l1.562-1.562a4.006 4.006 0 001.789.027zm-4.677-2.796a4.002 4.002 0 01-.041-2.08l-.08.08-1.53-1.533A5.98 5.98 0 004 10c0 .954.223 1.856.619 2.657l1.54-1.54zm1.088-6.45A5.974 5.974 0 0110 4c.954 0 1.856.223 2.657.619l-1.54 1.54a4.002 4.002 0 00-2.346.033L7.246 4.668zM12 10a2 2 0 11-4 0 2 2 0 014 0z" clip-rule="evenodd"></path></svg>
                          Support
                        </a>
                        <div role="separator" class="dropdown-divider my-1"></div>
                        <a class="dropdown-item d-flex align-items-center" href="{{ url_for('authentication_blueprint.logout') }}">
                          <svg class="dropdown-icon text-danger me-2" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"></path>
                          </svg>                
                          Se déconnecter
                        </a>
                      </div>
                    </li>
                  </ul>
                </div>
              </div>
            </nav>
            
    <style>
        .disabled {
            cursor: not-allowed;      
        }
    </style>

    <script>
        document.getElementById('topbarInputIconLeft').addEventListener('input', async function (event) {
            const query = event.target.value.trim();
    
            try {
                const response = await fetch('/search-profile', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ query })
                });
    
                const result = await response.json();
    
                if (response.ok) {
                    const profileContainer = document.getElementById('profile-results');
                    const infoProfileContainer = document.getElementById('info-profile-results');
                    profileContainer.innerHTML = ''; 
                    infoProfileContainer.innerHTML = ''; 
                    
                    result.profiles.forEach(profile => {
                        const profileCard = `
                            <div class="col-12 col-sm-6 col-xl-4 mb-4">
                                <div class="card border-0 shadow">
                                    <div class="card-body">
                                        <div class="row d-block d-xl-flex align-items-center">
                                            <!-- Image de profil -->
                                            <div class="col-12 col-xl-5 text-xl-center mb-3 mb-xl-0 d-flex align-items-center justify-content-xl-center">
                                                <img src="{{ config.ASSETS_ROOT }}/img/team/${profile.insta_username}.jpg" 
                                                    class="avatar-m rounded-circle" 
                                                    alt="Photo de ${profile.insta_username}">
                                            </div>
    
                                            <!-- Informations de profil -->
                                            <div class="col-12 col-xl-7 px-xl-0">
                                                <div class="d-none d-sm-block">
                                                    <h2 class="h5 text-gray-900 mb-1">${profile.insta_username}</h2>
                                                    <div class="d-flex align-items-center mb-3">
                                                        <div class="me-4">
                                                            <h3 class="fw-extrabold mb-0">${profile.followers_count}</h3>
                                                            <p class="text-gray-500 mb-0">Abonnés</p>
                                                        </div>
                                                    </div>
                                                    <div class="small d-flex mt-1">
                                                        <button class="btn btn-secondary d-inline-flex align-items-center justify-content-center mb-3 w-100" onclick="run_bot('${profile.insta_username}')">
                                                            Lancer le bot
                                                        </button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        `;
                        const infoProfileCard = `
                                    <tr>
                                        <th class="text-gray-900" scope="row">
                                            ${profile.insta_username}
                                        </th>
                                        <td class="fw-bolder text-gray-500">
                                            ${profile.posts_count}
                                        </td>
                                        <td class="fw-bolder text-gray-500">
                                            ${profile.followers_count}
                                        </td>
                                        <td class="fw-bolder text-gray-500">
                                            ${profile.following_count}
                                        </td>
                                    </tr>
                                    `;
                        
                        profileContainer.innerHTML += profileCard;
                        infoProfileContainer.innerHTML += infoProfileCard; 
                    });
                } else {
                    document.getElementById('profile-results').innerHTML = `<p class="text-muted">Aucun profil correspondant.</p>`;
                    document.getElementById('info-profile-results').innerHTML = `
                                    <tr>
                                        <th class="fw-bolder text-gray-900" scope="row">
                                            Aucun résultat trouvé.
                                        </th>
                                    </tr>`;
            }
            } catch (error) {
                console.error('Erreur lors de la recherche :', error);
            }
        });
</script>

