<?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>Transportadoras</h3>
	<div class="users">
	<div class="bar-top">
		<a href="<?= $base; ?>/addshippingcompany" class="btn btn-primary mr" style="width: 180px;" >Adicionar Transportadora</a>

		<div class="right">
			<!-- Busca por status -->
			<div class="right one">
					<form method="POST" action="<?= $base; ?>/shippingcompany">
						<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'] == 'cpf')?'selected':''; ?> value="cpf">CPF</option>
							  <option <?= ($arrayInfo['filter']['opt'] == 'cnpj')?'selected':''; ?> value="cnpj">CNPJ</option>
							</select>
							<input type="text" name="filter[tag]" value="<?= $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">Razão Social</th>
					<th scope="col">CPF/CNPJ</th>
					<th scope="col">Cidade-UF</th>
					<th scope="col">Nome Contato</th>
					<th scope="col">Fone celular</th>
					<th scope="col">Ações</th>
				</tr>
				<?php foreach($shippingList as $shippingcompany): ?>
					<tr>
						<td><?= ($shippingcompany['status'] == 1)?'Ativo':'Inativo'; ?></td>
						<td><?= ($shippingcompany['type'] == 1)?'PF':'PJ' ?></td>
						<td><?= $shippingcompany['company_name']; ?></td>
						<td><?= ($shippingcompany['type'] == 1)?$shippingcompany['cpf']:$shippingcompany['cnpj']; ?></td>
						<td>
							<?= (!empty($shippingcompany['city']))?$shippingcompany['city_name'].'-':''; ?>
							<?= (!empty($shippingcompany['state']))?$shippingcompany['state']:''; ?>
						</td>
						<td><?= $shippingcompany['contact_name']; ?></td>
						<td><?= $shippingcompany['first_phone']; ?></td>
						<td>
							<a href="<?=$base;?>/editshippingcompany&s=<?= $shippingcompany['id']?>" class="btn btn-info mbt">Editar</a>
							<button data-button="<?= $shippingcompany['id']?>" data-status="<?= $shippingcompany['status']?>" class="btn btn-<?= ($shippingcompany['status'] == 1)?'danger':'success';?> white"><?= ($shippingcompany['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; ?>/shippingcompany?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; ?>/shippingcompany?p=<?= ($arrayInfo['p']+1); ?><?= $arrayInfo['op']; ?>">></a></li>
		  	<?php endif; ?>

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

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