<?php $render('header', ['loggedUser'=>$loggedUser, 'title'=>$titlePage]); ?>
<?=$render('sidebar', [
  'loggedUser'=>$loggedUser, 
  'pageActive'=>$pageActive,
  'permissions'=>$permissions
]);?>

<!-- Content System -->
<div class="content-wrapper">
  <div class="pages">
    <h3>Vendedores</h3>
    <div class="users">
    <div class="bar-top">
      <a href="<?=$base;?>/addsalesman" class="btn btn-primary mr">Adicionar Vendedor</a>

      <div class="right">
        <!-- Busca por status -->
        <div class="right one">
          <form method="POST" action="<?= $base; ?>/salesman">
            <select class="form-control" name="filter[searchType]" id="option">
              <option value="clear">Limpar</option>
              <option value="1" <?= (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 1)?'selected':''; ?> >Ativo</option>
              <option value="2" <?= (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 2)?'selected':''; ?> >Inativo</option>
            </select>

            <div class="right two">
              <!--Blue select-->
              <select class="form-control" name="filter[opt]" id="opt">
                <option <?= ($arrayInfo['filter']['opt'] == 'name')?'selected':''; ?> value="name">Nome</option>
                <option <?= ($arrayInfo['filter']['opt'] == 'email')?'selected':''; ?> value="email">E-mail</option>
                <option <?= ($arrayInfo['filter']['opt'] == 'cpf')?'selected':''; ?> value="cpf">CPF</option>
                <option <?= ($arrayInfo['filter']['opt'] == 'cnpj')?'selected':''; ?> value="cnpj">CNPJ</option>
              </select>
              <input type="text" name="filter[tag]" class="form-control" value="<?= $arrayInfo['filter']['tag'] ?>" placeholder="Digite aqui..." id="busca">
            </div>

            <button type="submit" class="proccess">PROCESSAR</button>
          </form>
        </div>
        <!-- End Busca por status -->
      </div>
    </div>
      <!-- Message -->

      <?php if(!empty($error)): ?>
        <div class="alert <?=$error['alertType'];?>" role="alert">
          <?php echo $error['msg']; ?>
        </div>
      <?php endif; ?>

      <!-- /Message -->

      <table class="table table-hover" id="upStatus">
        <tbody>
          <tr>
            <th scope="col">Status</th>
            <th scope="col">Tipo</th>
            <th scope="col">Nome</th>
            <th scope="col">CPF/CNPJ</th>
            <th scope="col">Celular 01</th>
            <th scope="col">Celular 02</th>
            <th scope="col">E-mail</th>
            <th scope="col">Ações</th>
          </tr>
          <?php foreach($salesmanList as $salesman): ?>
            <tr>
              <td>
                <?= ($salesman['status'] == 1)?'Ativo':'Inativo'; ?>
              </td>
              <td><?= ($salesman['type'] == 1)?'PF':'PJ' ?></td>              
              <td><?= $salesman['name']; ?></td>
              <td> <?= ($salesman['type'] == 1)?$salesman['cpf']:$salesman['cnpj'];?> </td>
              <td><?= $salesman['first_phone']; ?></td>
              <td><?= $salesman['second_phone']; ?></td>
              <td><?= $salesman['email']; ?></td>
              <td>
                <a href="<?= $base; ?>/editsalesman&s=<?= $salesman['id']?>" class="btn btn-info mbt">Editar</a>
                <button data-button="<?= $salesman['id']?>" data-status="<?= $salesman['status']?>" class="btn btn-<?= ($salesman['status'] == 1)?'danger':'success';?> white"><?= ($salesman['status'] == 1)?'Inativar':'Ativar';?></button>
              </td>
            </tr>
          <?php endforeach; ?>
        </tbody>
      </table>

      <nav aria-label="...">
        <ul class="pagination pagination-sm">

          <?php if($arrayInfo['p'] > 1): ?>
            <li class="page-item"><a class="page-link" href="<?=$base;?>/salesman?p=<?= ($arrayInfo['p']-1); ?><?= $arrayInfo['op']; ?>"><</a></li>
          <?php endif; ?>

          <li class="page-item">
            <form method="GET" id="form-pagination">
              <input type="text" name="p" value="<?= $arrayInfo['p']; ?>" class="form-control input-pagination">
            </form>
          </li>

          <?php if($arrayInfo['p'] != $arrayInfo['p_count'] && !empty($arrayInfo['p_count'])): ?>
            <li class="page-item"><a class="page-link" href="<?=$base;?>/salesman?p=<?= ($arrayInfo['p']+1); ?><?= $arrayInfo['op']; ?>">></a></li>
          <?php endif; ?>

        </ul>
      </nav>
    </div>
    <script src="<?=$base;?>/assets/js/salesman.js"></script>
  </div>  		
</div>
<!-- /.content-system -->

<?=$render('footer');?>