<?php $user_id = $this->session->user_id; $group = $this->ion_auth->get_users_groups($user_id)->row(); ?>

<nav class="navbar navbar-expand navbar-light bg-navbar topbar mb-4 static-top">
  <button id="sidebarToggleTop" class="btn btn-link rounded-circle mr-3">
    <i class="fa fa-bars"></i>
  </button>
  <ul class="navbar-nav ml-auto">
    <li class="nav-item dropdown no-arrow">
      <a class="nav-link dropdown-toggle" href="#" id="searchDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <i class="fas fa-search fa-fw"></i>
      </a>
      <div class="dropdown-menu dropdown-menu-right p-3 shadow animated--grow-in" aria-labelledby="searchDropdown">
        <form class="navbar-search">
          <div class="input-group">
            <input type="text" class="form-control bg-light border-1 small" placeholder="Pesquisar..." aria-label="Search" aria-describedby="basic-addon2" style="border-color: #3f51b5;">
            <div class="input-group-append">
              <button class="btn btn-primary" type="button">
                <i class="fas fa-search fa-sm"></i>
              </button>
            </div>
          </div>
        </form>
      </div>
    </li>

    <li class="nav-item dropdown no-arrow mx-1">
      <a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <i class="fas fa-bell fa-fw"></i>
        <span class="badge badge-danger badge-counter"><?php echo $unread_alerts; ?></span>
      </a>
      <div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="alertsDropdown">
        <h6 class="dropdown-header">
          Alertas
        </h6>
        <?php if (isset($alerts)): ?>
          <?php $i = 0; ?>
          <?php foreach ($alerts as $alert) : ?>
            <?php if ($i <= 3): ?>
              <?php $chapter_name = $this->core_model->get_by_id('chapters', array('id' => $alert->chapter_id)); ?>
              <div class="customer-message align-items-center">
                <a class="font-weight-bold">
                  <div class="text-truncate message-title"><?php echo $alert->message; ?></div>
                  <div class="small text-gray-600 message-time font-weight-bold"><?php echo $chapter_name->title; ?></div>
                </a>
              </div>
            <?php endif; ?>
            <?php $i++; ?>
          <?php endforeach; ?>
          <div class="card-footer text-center">
            <a class="m-0 small text-white bg-info p-2 badge badge-dander card-link" href="<?php echo base_url('restricted/notification/alerts/' . $group->name); ?>">Ver todos <i class="fas fa-chevron-right"></i></a>
          </div>
        <?php else : ?>
          <div class="customer-message align-items-center">
            <a class="font-weight-bold">
              <div class="text-truncate message-title">Nenhum alerta foi encontrado.</div>
            </a>
          </div>
        <?php endif; ?>
      </div>
    </li>

    <!-- Messages  -->
    <li class="nav-item dropdown no-arrow mx-1">
      <a class="nav-link dropdown-toggle" href="#" id="messagesDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <i class="fas fa-envelope fa-fw"></i>
        <span class="badge badge-info badge-counter"><?php echo $unread_messages; ?></span>
      </a>
      <div class="dropdown-list dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="messagesDropdown">
        <h6 class="dropdown-header">
          Mensagens
        </h6>
        <?php if (isset($messages)): ?>
          <?php $i = 0; ?>
          <?php foreach ($messages as $message): ?>
            <?php if ($i <= 3) : ?>
              <?php $chapter_name = $this->core_model->get_by_id('chapters', array('id' => $message->chapter_id)); ?>
              <div class="customer-message align-items-center">
                <a class="font-weight-bold">
                  <div class="text-truncate message-title"><?php echo $message->message; ?></div>
                  <div class="small text-gray-600 message-time font-weight-bold"><?php echo $chapter_name->title; ?></div>
                </a>
              </div>
            <?php endif; ?>
            <?php $i++; ?>
          <?php endforeach; ?>
          <div class="card-footer text-center">
            <a class="m-0 small text-white bg-info p-2 badge card-link" href="<?php echo base_url('restricted/notification/messages/' . $group->name); ?>">Ver todas <i class="fas fa-chevron-right"></i></a>
            </div>
        <?php else : ?>
          <div class="customer-message align-items-center">
            <a class="font-weight-bold" href="#">
              <div class="text-truncate message-title">Nenhuma mensagem foi encontrada.</div>
            </a>
          </div>
        <?php endif; ?>
      </div>
    </li>
    <!-- /Messages  -->

    <div class="topbar-divider d-none d-sm-block"></div>
    <li class="nav-item dropdown no-arrow">
      <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <img class="img-profile rounded-circle" src="<?php echo base_url('public/assets/restricted/img/boy.png'); ?>" style="max-width: 60px">
        
        <?php $user_id = $this->session->user_id; $user = $this->core_model->get_by_id('users', array('id' => $user_id)); ?>

        <span class="ml-2 d-none d-lg-inline text-white small"><?php echo $user->first_name;?></span>
      </a>
      <div class="dropdown-menu dropdown-menu-right shadow animated--grow-in" aria-labelledby="userDropdown">
        <a class="dropdown-item" href="#">
          <i class="fas fa-user fa-sm fa-fw mr-2 text-gray-400"></i>
          Perfil
        </a>
        <a class="dropdown-item" href="#">
          <i class="fas fa-cogs fa-sm fa-fw mr-2 text-gray-400"></i>
          Configurações
        </a>
        <a class="dropdown-item" href="#">
          <i class="fas fa-list fa-sm fa-fw mr-2 text-gray-400"></i>
          Log
        </a>
        <div class="dropdown-divider"></div>
        <a class="dropdown-item" href="javascript:void(0);" data-toggle="modal" data-target="#logoutModal">
          <i class="fas fa-sign-out-alt fa-sm fa-fw mr-2 text-gray-400"></i>
          Sair
        </a>
      </div>
    </li>
  </ul>
</nav>