<?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>Produtos</h3>
    <div class="users">
    <div class="bar-top">
      <a href="<?=$base?>/addproducts" class="btn btn-primary mr">Adicionar Produto</a>

      <div class="right">
        <!-- Busca por status -->
        <div class="right one">
          <input type="hidden" name="pro_selected" value="<?= (!empty($arrayInfo['filter']['searchProvider']))?$arrayInfo['filter']['searchProvider']:''; ?>">
          <form method="POST" action="<?=$base;?>/products">

            <label class="onlystock">
              Apenas com estoque
              <input type="checkbox" name="filter[onlystock]" <?= (!empty($arrayInfo['filter']['onlystock']) && $arrayInfo['filter']['onlystock'] == 'on')?'checked':''; ?> >
            </label>

            <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>
              <option value="3" <?= (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 3)?'selected':''; ?> >Descrição</option>
              <option value="4" <?= (!empty($arrayInfo['filter']['searchType']) && $arrayInfo['filter']['searchType'] == 4)?'selected':''; ?> >Fornecedor</option>
            </select>
            <input type="text" id="prod_search" class="form-control" name="filter[searchTerm]" value="<?= (!empty($arrayInfo['filter']['searchTerm']))?$arrayInfo['filter']['searchTerm']:''; ?>">
            <select class="form-control" name="filter[searchProvider]" id="providerList">              
            </select>

            <!-- Busca por digitação -->
            <div class="right two">
              <!--Blue select-->
              <select class="form-control" name="filter[opt]" id="opt">
                <option value="id">Código</option>
              </select>
              <input type="text" name="filter[tag]" value="<?= (!empty($arrayInfo['filter']['tag']))?$arrayInfo['filter']['tag']:'' ?>" class="form-control" placeholder="Digite aqui..." id="busca">
            </div>
            <!-- End Busca por digitação -->

            <input type="submit" class="proccess" value="PROCESSAR">
          </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">Produto</th>
            <th scope="col">Fornecedor</th>
            <th scope="col">Grupo</th>
            <th scope="col">Unidade</th>
            <th scope="col">Tipo</th>
            <th scope="col">Estoque</th>
            <th scope="col">Custo R$</th>
            <th scope="col">Venda R$</th>
            <th scope="col">Ações</th>
          </tr>
          <?php foreach($arrayInfo['listProducts'] as $product): ?>
            <tr>
              <td><?= ($product['status'] == 1)?'Ativo':'Inativo'; ?></td>
              <td><?= $product['name']?></td>
              <td><?= $product['provider']?></td>          
              <td><?= $product['group_p']['name']?></td>
              <td><?= $product['unity']['name']?></td>
              <td><?= $product['presentation']['name']?></td>
              <td><?= $product['amount']?></td>
              <td><?= $product['cost_price']?></td>
              <td><?= $product['price']?></td>
              <td>
                <a href="<?=$base;?>/editproduct&p=<?= $product['id']?>" class="btn btn-info mbt">Editar</a>
                <button data-button="<?= $product['id']?>" data-status="<?= $product['status']?>" class="btn btn-<?= ($product['status'] == 1)?'danger':'success';?> white"><?= ($product['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; ?>/products?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; ?>/products?p=<?= ($arrayInfo['p']+1); ?><?= $arrayInfo['op']; ?>">></a></li>
          <?php endif; ?>

        </ul>
      </nav>

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

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