
<?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>Clientes</h3>
    <div class="users">
    <div class="bar-top">
      <a href="<?=$base;?>/addclient" class="btn btn-primary mr">Adicionar Cliente</a>

      <div class="right">
        <!-- Busca por status -->
        <div class="right one">
          <form method="POST" action="<?=$base;?>/clients">
            <select class="form-control" name="filter[searchType]" id="option">
              <option value="clear">Limpar</option>
              <option value="1" <?php echo (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 1)?'selected':''; ?> >Ativo</option>
              <option value="2" <?php echo (!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 value="name" <?= ($arrayInfo['filter']['opt'] == 'name' ? 'selected' : '') ?> >Nome</option>
                <option value="email" <?= ($arrayInfo['filter']['opt'] == 'email' ? 'selected' : '') ?> >E-mail</option>
                <option value="cpf" <?= ($arrayInfo['filter']['opt'] == 'cpf' ? 'selected' : '') ?> >CPF</option>
                <option value="cnpj" <?= ($arrayInfo['filter']['opt'] == 'cnpj' ? 'selected' : '') ?> >CNPJ</option>
              </select>
              <input type="text" name="filter[tag]" class="form-control" placeholder="Digite aqui..." id="busca" value="<?= $arrayInfo['filter']['tag']; ?>">
            </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">
        <tbody>
          <tr>
            <th scope="col">Status</th>
            <th scope="col">Classe</th>
            <th scope="col">Tipo</th>
            <th scope="col">Nome</th>
            <th scope="col">Fone Cliente</th>
            <th scope="col">CPF/CNPJ</th>
            <th scope="col">Cidade-UF</th>
            <th scope="col">Comprador</th>
            <th scope="col">Fone Comprador</th>
            <th scope="col">Ações</th>
          </tr>
          <?php foreach($arrayInfo['clientsInfo'] as $client): ?>
            <tr>
              <td><?= ($client['status'] == 1)?'Ativo':'Inativo' ?></td>
              <td><?= $client['classification']; ?></td>
              <td><?= ($client['type'] == 1)?'PF':'PJ' ?></td>
              <td><?= $client['name']; ?></td>
              <td><?= $client['first_phone']; ?></td>
              <td><?= ($client['type'] == 1)? $client['cpf'] : $client['cnpj'] ?></td>
              <td><?= $client['city_name']; ?> - <?= $client['state']; ?></td>
              <td><?= $client['buyer']; ?></td>
              <td><?= $client['buyer_phone']; ?></td>
              <td>
                <a href="editclient&c=<?= $client['id']?>" class="btn btn-info mbt">Editar</a>
                <a href="<?=$base; ?>/farms&c=<?= $client['id']?>" class="btn btn-success">Fazendas</a>
              </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; ?>/clients?p=<?php echo ($arrayInfo['p']-1); ?><?php echo $arrayInfo['op']; ?>"><</a></li>
          <?php endif; ?>

          <li class="page-item">
            <form method="GET" id="form-pagination">
              <input type="text" name="p" value="<?php echo $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; ?>/clients?p=<?php echo ($arrayInfo['p']+1); ?><?php echo $arrayInfo['op']; ?>">></a></li>
          <?php endif; ?>

        </ul>
      </nav>

    </div>

  </div>  		
</div>
<!-- /.content-system -->

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