@php
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Route;
@endphp

<!--  Brand demo (display only for navbar-full and hide on below xl) -->
@if (isset($navbarFull))
<div class="navbar-brand app-brand demo d-none d-xl-flex py-0 me-6">
  <a href="{{ url('/') }}" class="app-brand-link gap-2">
    <span class="app-brand-logo demo">@include('_partials.macros')</span>
  </a>

  <!-- Display menu close icon only for horizontal-menu with navbar-full -->
  @if (isset($menuHorizontal))
  <a href="javascript:void(0);" class="layout-menu-toggle menu-link text-large ms-auto d-xl-none">
    <i class="icon-base bx bx-chevron-left d-flex align-items-center justify-content-center"></i>
  </a>
  @endif
</div>
@endif

<!-- ! Not required for layout-without-menu -->
@if (!isset($navbarHideToggle))
<div
class="layout-menu-toggle navbar-nav align-items-xl-center me-4 me-xl-0{{ isset($menuHorizontal) ? ' d-xl-none ' : '' }} {{ isset($contentNavbar) ? ' d-xl-none ' : '' }}">
<a class="nav-item nav-link px-0 me-xl-6" href="javascript:void(0)">
  <i class="icon-base bx bx-menu icon-md"></i>
</a>
</div>
@endif

<div class="navbar-nav-right d-flex align-items-center justify-content-between" id="navbar-collapse">  <!-- justify-content-end -->

  @if (!isset($menuHorizontal))
  @yield('pageTitle')
  {{-- <h4 class="mb-0">
  </h4> --}}
  @endif

  <ul class="navbar-nav flex-row align-items-center ms-md-auto">
    @if (isset($menuHorizontal))
    <!-- Search -->
    <li class="nav-item navbar-search-wrapper me-2 me-xl-0">
      <a class="nav-item nav-link search-toggler px-0" href="javascript:void(0);">
        <span class="d-inline-block text-body-secondary fw-normal" id="autocomplete"></span>
      </a>
    </li>
    <!-- /Search -->
    @endif

    <!-- Language -->

    <!--/ Language -->



    <!-- Quick links  -->
    {{-- <li class="nav-item dropdown-shortcuts navbar-dropdown dropdown me-2 me-xl-0">
      <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown"
      data-bs-auto-close="outside" aria-expanded="false">
      <i class="icon-base bx bx-grid-alt icon-md"></i>
    </a>
    <div class="dropdown-menu dropdown-menu-end p-0">
      <div class="dropdown-menu-header border-bottom">
        <div class="dropdown-header d-flex align-items-center py-3">
          <h6 class="mb-0 me-auto">Shortcuts</h6>
          <a href="javascript:void(0)" class="dropdown-shortcuts-add py-2" data-bs-toggle="tooltip"
          data-bs-placement="top" title="Add shortcuts"><i class="icon-base bx bx-plus-circle text-heading"></i></a>
        </div>
      </div>
      <div class="dropdown-shortcuts-list scrollable-container">
        <div class="row row-bordered overflow-visible g-0">
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-calendar icon-26px text-heading"></i>
            </span>
            <a href="{{ url('app/calendar') }}" class="stretched-link">Calendar</a>
            <small>Appointments</small>
          </div>
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-food-menu icon-26px text-heading"></i>
            </span>
            <a href="{{ url('app/invoice/list') }}" class="stretched-link">Invoice App</a>
            <small>Manage Accounts</small>
          </div>
        </div>
        <div class="row row-bordered overflow-visible g-0">
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-user icon-26px text-heading"></i>
            </span>
            <a href="{{ url('app/user/list') }}" class="stretched-link">User App</a>
            <small>Manage Users</small>
          </div>
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-check-shield icon-26px text-heading"></i>
            </span>
            <a href="{{ url('app/access-roles') }}" class="stretched-link">Role Management</a>
            <small>Permission</small>
          </div>
        </div>
        <div class="row row-bordered overflow-visible g-0">
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-pie-chart-alt-2 icon-26px text-heading"></i>
            </span>
            <a href="{{ url('/') }}" class="stretched-link">Dashboard</a>
            <small>User Dashboard</small>
          </div>
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-cog icon-26px text-heading"></i>
            </span>
            <a href="{{ url('pages/account-settings-account') }}" class="stretched-link">Setting</a>
            <small>Account Settings</small>
          </div>
        </div>
        <div class="row row-bordered overflow-visible g-0">
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-help-circle icon-26px text-heading"></i>
            </span>
            <a href="{{ url('pages/faq') }}" class="stretched-link">FAQs</a>
            <small>FAQs & Articles</small>
          </div>
          <div class="dropdown-shortcuts-item col">
            <span class="dropdown-shortcuts-icon rounded-circle mb-3">
              <i class="icon-base bx bx-window-open icon-26px text-heading"></i>
            </span>
            <a href="{{ url('modal-examples') }}" class="stretched-link">Modals</a>
            <small>Useful Popups</small>
          </div>
        </div>
      </div>
    </div>
  </li> --}}
  <!-- Quick links -->

  <!-- Notification -->
  {{-- <li class="nav-item dropdown-notifications navbar-dropdown dropdown me-3 me-xl-2">
    <a class="nav-link dropdown-toggle hide-arrow" href="javascript:void(0);" data-bs-toggle="dropdown"
    data-bs-auto-close="outside" aria-expanded="false">
    <span class="position-relative">
      <i class="icon-base bx bx-bell icon-md"></i>
      <span class="badge rounded-pill bg-danger badge-dot badge-notifications border"></span>
    </span>
  </a>
  <ul class="dropdown-menu dropdown-menu-end p-0">
    <li class="dropdown-menu-header border-bottom">
      <div class="dropdown-header d-flex align-items-center py-3">
        <h6 class="mb-0 me-auto">Notification</h6>
        <div class="d-flex align-items-center h6 mb-0">
          <span class="badge bg-label-primary me-2">8 New</span>
          <a href="javascript:void(0)" class="dropdown-notifications-all p-2" data-bs-toggle="tooltip"
          data-bs-placement="top" title="Mark all as read"><i
          class="icon-base bx bx-envelope-open text-heading"></i></a>
        </div>
      </div>
    </li>
    <li class="dropdown-notifications-list scrollable-container">
      <ul class="list-group list-group-flush">
        <li class="list-group-item list-group-item-action dropdown-notifications-item">
          <div class="d-flex">
            <div class="flex-shrink-0 me-3">
              <div class="avatar">
                <img src="{{ asset('assets/img/avatars/1.png') }}" alt class="rounded-circle" />
              </div>
            </div>
            <div class="flex-grow-1">
              <h6 class="small mb-0">Congratulation Lettie 🎉</h6>
              <small class="mb-1 d-block text-body">Won the monthly best seller gold badge</small>
              <small class="text-body-secondary">1h ago</small>
            </div>
            <div class="flex-shrink-0 dropdown-notifications-actions">
              <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                class="badge badge-dot"></span></a>
                <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                  class="icon-base bx bx-x"></span></a>
                </div>
              </div>
            </li>
            <li class="list-group-item list-group-item-action dropdown-notifications-item">
              <div class="d-flex">
                <div class="flex-shrink-0 me-3">
                  <div class="avatar">
                    <span class="avatar-initial rounded-circle bg-label-danger">CF</span>
                  </div>
                </div>
                <div class="flex-grow-1">
                  <h6 class="small mb-0">Charles Franklin</h6>
                  <small class="mb-1 d-block text-body">Accepted your connection</small>
                  <small class="text-body-secondary">12hr ago</small>
                </div>
                <div class="flex-shrink-0 dropdown-notifications-actions">
                  <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                    class="badge badge-dot"></span></a>
                    <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                      class="icon-base bx bx-x"></span></a>
                    </div>
                  </div>
                </li>
                <li class="list-group-item list-group-item-action dropdown-notifications-item marked-as-read">
                  <div class="d-flex">
                    <div class="flex-shrink-0 me-3">
                      <div class="avatar">
                        <img src="{{ asset('assets/img/avatars/2.png') }}" alt class="rounded-circle" />
                      </div>
                    </div>
                    <div class="flex-grow-1">
                      <h6 class="small mb-0">New Message ✉️</h6>
                      <small class="mb-1 d-block text-body">You have new message from Natalie</small>
                      <small class="text-body-secondary">1h ago</small>
                    </div>
                    <div class="flex-shrink-0 dropdown-notifications-actions">
                      <a href="javascript:void(0)" class="dropdown-notifications-read">
                        <span class="badge badge-dot"></span>
                      </a>
                      <a href="javascript:void(0)" class="dropdown-notifications-archive">
                        <span class="icon-base bx bx-x"></span>
                      </a>
                    </div>
                  </div>
                </li>
                <li class="list-group-item list-group-item-action dropdown-notifications-item">
                  <div class="d-flex">
                    <div class="flex-shrink-0 me-3">
                      <div class="avatar">
                        <span class="avatar-initial rounded-circle bg-label-success">
                          <i class="icon-base bx bx-cart"></i>
                        </span>
                      </div>
                    </div>
                    <div class="flex-grow-1">
                      <h6 class="small mb-0">Whoo! You have new order 🛒</h6>
                      <small class="mb-1 d-block text-body">ACME Inc. made new order $1,154</small>
                      <small class="text-body-secondary">1 day ago</small>
                    </div>
                    <div class="flex-shrink-0 dropdown-notifications-actions">
                      <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                        class="badge badge-dot"></span></a>
                        <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                          class="icon-base bx bx-x"></span></a>
                        </div>
                      </div>
                    </li>
                    <li class="list-group-item list-group-item-action dropdown-notifications-item marked-as-read">
                      <div class="d-flex">
                        <div class="flex-shrink-0 me-3">
                          <div class="avatar">
                            <img src="{{ asset('assets/img/avatars/9.png') }}" alt class="rounded-circle" />
                          </div>
                        </div>
                        <div class="flex-grow-1">
                          <h6 class="small mb-0">Application has been approved 🚀</h6>
                          <small class="mb-1 d-block text-body">Your ABC project application has been approved.</small>
                          <small class="text-body-secondary">2 days ago</small>
                        </div>
                        <div class="flex-shrink-0 dropdown-notifications-actions">
                          <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                            class="badge badge-dot"></span></a>
                            <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                              class="icon-base bx bx-x"></span></a>
                            </div>
                          </div>
                        </li>
                        <li class="list-group-item list-group-item-action dropdown-notifications-item marked-as-read">
                          <div class="d-flex">
                            <div class="flex-shrink-0 me-3">
                              <div class="avatar">
                                <span class="avatar-initial rounded-circle bg-label-success"><i
                                  class="icon-base bx bx-pie-chart-alt"></i></span>
                                </div>
                              </div>
                              <div class="flex-grow-1">
                                <h6 class="small mb-0">Monthly report is generated</h6>
                                <small class="mb-1 d-block text-body">July monthly financial report is generated </small>
                                <small class="text-body-secondary">3 days ago</small>
                              </div>
                              <div class="flex-shrink-0 dropdown-notifications-actions">
                                <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                                  class="badge badge-dot"></span></a>
                                  <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                                    class="icon-base bx bx-x"></span></a>
                                  </div>
                                </div>
                              </li>
                              <li class="list-group-item list-group-item-action dropdown-notifications-item marked-as-read">
                                <div class="d-flex">
                                  <div class="flex-shrink-0 me-3">
                                    <div class="avatar">
                                      <img src="{{ asset('assets/img/avatars/5.png') }}" alt class="rounded-circle" />
                                    </div>
                                  </div>
                                  <div class="flex-grow-1">
                                    <h6 class="small mb-0">Send connection request</h6>
                                    <small class="mb-1 d-block text-body">Peter sent you connection request</small>
                                    <small class="text-body-secondary">4 days ago</small>
                                  </div>
                                  <div class="flex-shrink-0 dropdown-notifications-actions">
                                    <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                                      class="badge badge-dot"></span></a>
                                      <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                                        class="icon-base bx bx-x"></span></a>
                                      </div>
                                    </div>
                                  </li>
                                  <li class="list-group-item list-group-item-action dropdown-notifications-item">
                                    <div class="d-flex">
                                      <div class="flex-shrink-0 me-3">
                                        <div class="avatar">
                                          <img src="{{ asset('assets/img/avatars/6.png') }}" alt class="rounded-circle" />
                                        </div>
                                      </div>
                                      <div class="flex-grow-1">
                                        <h6 class="small mb-0">New message from Jane</h6>
                                        <small class="mb-1 d-block text-body">Your have new message from Jane</small>
                                        <small class="text-body-secondary">5 days ago</small>
                                      </div>
                                      <div class="flex-shrink-0 dropdown-notifications-actions">
                                        <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                                          class="badge badge-dot"></span></a>
                                          <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                                            class="icon-base bx bx-x"></span></a>
                                          </div>
                                        </div>
                                      </li>
                                      <li class="list-group-item list-group-item-action dropdown-notifications-item marked-as-read">
                                        <div class="d-flex">
                                          <div class="flex-shrink-0 me-3">
                                            <div class="avatar">
                                              <span class="avatar-initial rounded-circle bg-label-warning"><i
                                                class="icon-base bx bx-error"></i></span>
                                              </div>
                                            </div>
                                            <div class="flex-grow-1">
                                              <h6 class="small mb-0">CPU is running high</h6>
                                              <small class="mb-1 d-block text-body">CPU Utilization Percent is currently at 88.63%,</small>
                                              <small class="text-body-secondary">5 days ago</small>
                                            </div>
                                            <div class="flex-shrink-0 dropdown-notifications-actions">
                                              <a href="javascript:void(0)" class="dropdown-notifications-read"><span
                                                class="badge badge-dot"></span></a>
                                                <a href="javascript:void(0)" class="dropdown-notifications-archive"><span
                                                  class="icon-base bx bx-x"></span></a>
                                                </div>
                                              </div>
                                            </li>
                                          </ul>
                                        </li>
                                        <li class="border-top">
                                          <div class="d-grid p-4">
                                            <a class="btn btn-primary btn-sm d-flex" href="javascript:void(0);">
                                              <small class="align-middle">View all notifications</small>
                                            </a>
                                          </div>
                                        </li>
                                      </ul>
                                    </li> --}}
                                    <!--/ Notification -->

                                    <!-- Accedi a punto vendita se in Session -->
                                    @if(\Illuminate\Support\Facades\Cookie::has('binding_token'))
                                    <?php
                                    $binding_token = \Illuminate\Support\Facades\Cookie::get('binding_token');
                                    $puntoVendita = \App\Models\Dispositivo::findByBindingCookieToken($binding_token);
                                    ?>
                                    @if($puntoVendita)
                                    <a href="{{ route('punto-vendita.show', ['punto_vendita_id' => $puntoVendita->id]) }}" class="mx-5 btn text-bg-primary px-2 py-1">
                                      Torna a {{ $puntoVendita->nome }}
                                      <i class="bx bx-arrow-back rotate-180 float-end"></i>
                                    </a>
                                    @endif
                                    @endif
                                    <!-- END - Accedi a punto vendita se in Session -->

                                    <!-- Attività -->
                                    @if(session()->has('attivita_attuale') && session()->get('attivita_attuale') != null && session()->get('attivita_attuale') != 0)
                                    <li class="d-none d-lg-flex nav-item navbar-dropdown dropdown-user dropdown mx-12">
                                      <a class="nav-link dropdown-toggle hide-arrow p-0" href="javascript:void(0);" data-bs-toggle="dropdown">
                                        <small class=" ms-2">Stai gestendo</small>
                                        <i class="bx bx-aperture text-primary bx-md"></i> 
                                        <span class="fw-semibold text-primary text-uppercase"> 
                                          {{ \App\Models\Attivita::find(session()->get('attivita_attuale'))->nome }}
                                        </span>
                                      </a>
                                        @else
                                        <!-- Attività non selezionata -->
                                        @endif
                                      <ul class="dropdown-menu dropdown-menu-end">
                                        @foreach(Auth::user()->attivita as $attivita)
                                        <li>
                                          <form action="{{ route('attivita.select', ['attivita_id' => $attivita->id]) }}" method="POST">
                                            @csrf

                                            <button type="submit" class="dropdown-item">
                                              <span>{{ $attivita->nome }}</span>
                                              <i class="bx bx-arrow-back rotate-180 text-primary"></i>
                                            </button>
                                          </form>
                                        </li>
                                        @endforeach
                                      </ul>
                                    </li>
                                    <!--/ Attività -->
                                    <!-- User -->
                                    <li class="nav-item navbar-dropdown dropdown-user dropdown">
                                      <a class="nav-link dropdown-toggle hide-arrow p-0" href="javascript:void(0);" data-bs-toggle="dropdown">
                                        <div class="avatar avatar-online">
                                          <img src="{{ Auth::check() && Auth::user()->path_foto ? Auth::user()->getUrlFoto() : asset('assets/img/avatars/user_profile.png') }}" alt class="w-px-40 h-auto rounded-circle">
                                        </div>
                                      </a>
                                      <ul class="dropdown-menu dropdown-menu-end">
                                        <li>
                                          <a class="dropdown-item" href="{{ Route::has('profile.show') ? route('profile.show') : url('pages/profile-user') }}">
                                            <div class="d-flex">
                                              <div class="flex-shrink-0 me-3">
                                                <div class="avatar avatar-online">
                                                  <img src="{{ Auth::check() && Auth::user()->path_foto ? Auth::user()->getUrlFoto() : asset('assets/img/avatars/user_profile.png') }}" alt class="w-px-40 h-auto rounded-circle">
                                                </div>
                                              </div>
                                              <div class="flex-grow-1">
                                                <h6 class="mb-0">
                                                  @if (Auth::check())
                                                  {{ Auth::user()->full_name }}
                                                  @else
                                                  John Doe
                                                  @endif
                                                </h6>
                                                <small class="text-muted">Admin</small>
                                              </div>
                                            </div>
                                          </a>
                                        </li>
                                        <li>
                                          <div class="dropdown-divider my-1"></div>
                                        </li>
                                        <li>
                                          <a class="dropdown-item" href="{{ Route::has('profile.show') ? route('profile.show') : url('pages/profile-user') }}">
                                            <i class="bx bx-user bx-md me-3"></i><span>Profilo</span>
                                          </a>
                                        </li>
                                        <li>
                                          <div class="dropdown-divider my-1"></div>
                                        </li>
                                        @if (Auth::check())
                                        <li>
                                          <a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault(); document.getElementById('logout-form').submit();">
                                            <i class='bx bx-power-off bx-md me-3'></i><span>Logout</span>
                                          </a>
                                        </li>
                                        <form method="POST" id="logout-form" action="{{ route('logout') }}">
                                          @csrf
                                        </form>
                                        @else
                                        <li>
                                          <a class="dropdown-item" href="{{ Route::has('login') ? route('login') : url('auth/login-basic') }}">
                                            <i class='bx bx-log-in bx-md me-3'></i><span>Login</span>
                                          </a>
                                        </li>
                                        @endif
                                      </ul>
                                    </li>
                                    <!--/ User -->
                                  </ul>
                                </div>
