<?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><?= $title; ?></h3>
    <div class="users">
    <div class="bar-top">
      <a href="<?= $base; ?>/addprovider" class="btn btn-primary mr" style="width:160px;" >Adicionar Fornecedor</a>

      <div class="right">
        <!-- Busca por status -->
        <div class="right one">
            <form method="POST" action="<?= $base; ?>/<?= $linkPagination; ?>">
              <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'] == 'company_name')?'selected':''; ?>  value="company_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]" value="<?= (!empty($arrayInfo['filter']['tag']))?$arrayInfo['filter']['tag']:''; ?>"  class="form-control" 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/Razão Social</th>
            <th scope="col">CPF/CNPJ</th>
            <th scope="col">Cidade-UF</th>
            <th scope="col">Contato</th>
            <th scope="col">Fone celular</th>
            <th scope="col">Fone fixo</th>
            <th scope="col">Ações</th>
          </tr>
          <?php foreach($providersList as $provider): ?>
            <tr>
              <td>
                <?= ($provider['status'] == 1)?'Ativo':'Inativo'; ?>
              </td>
              <td><?= ($provider['type'] == 1)?'PF':'PJ' ?></td>
              <td><?= $provider['company_name']; ?></td>
              <td><?= ($provider['type'] == 1)?$provider['cpf']:$provider['cnpj']; ?></td>
              <td><?= $provider['city_name']; ?> - <?= $provider['state']; ?></td>
              <td><?= $provider['contact_name']; ?></td>
              <td><?= $provider['first_phone']; ?></td>
              <td><?= $provider['second_phone']; ?></td>
              <td>
                <a href="editprovider?p=<?= $provider['id'].$linkEdit?>" class="btn btn-info mbt">Editar</a>
                <button data-of="<?= $provider['provider_of']?>" data-button="<?= $provider['id']?>" data-status="<?= $provider['status']?>" class="btn btn-<?= ($provider['status'] == 1)?'danger':'success';?> white"><?= ($provider['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; ?>/<?= $linkPagination; ?>?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; ?>/<?= $linkPagination; ?>?p=<?= ($arrayInfo['p']+1); ?><?= $arrayInfo['op']; ?>">></a></li>
          <?php endif; ?>

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

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