<?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>Cliente: <?= $client['name']; ?></h3>
		<div class="users">
			<!-- Message -->

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

			<!-- /Message -->
			<div class="oculted">
				<span>
					<i>
						<div>
							<input type="hidden" name="id_client" value="<?= $client['id']; ?>">
						</div>
					</i>
				</span>
			</div>
			<!-- Lista Fazendas -->
			<h4 class="center">Fazenda(s) do Cliente</h4>

			<table class="table table-bordered" id="upStatus">
				<tbody>
					<tr>
						<th scope="col">Status</th>
						<th scope="col">Nome da Fazenda</th>
						<th scope="col">Cidade - Estado</th>
						<th scope="col">Insc. Estadual</th>
						<th scope="col">Responsável</th>
						<th scope="col">Celular</th>			
						<th scope="col">Ações</th>
					</tr>
					<?php foreach($farmsList as $farm): ?>
						<tr>
							<td><?= ($farm['status'] == 1)?'Ativo':'Inativo'; ?></td>
							<td><?= $farm['name']; ?></td>
							<td><?= $farm['city_name']; ?> - <?= $farm['state']; ?></td>
							<td><?= $farm['state_registration']; ?></td>
							<td><?= $farm['responsible']; ?></td>
							<td><?= $farm['phone']; ?></td>					
							<td>
									<a href="<?= $base; ?>/editfarms&f=<?= $farm['id']?>" class="btn btn-info">Editar</a>
									<button data-button="<?= $farm['id']?>" data-where="farms" data-status="<?= $farm['status']?>" class="btn btn-<?= ($farm['status'] == 1)?'danger':'success';?> white"><?= ($farm['status'] == 1)?'Inativar':'Ativar';?></button>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>

			<div class="form-row">
				<a href="<?= $base; ?>/addfarms&c=<?= $client['id']; ?>" class="btn btn-success mr">Adicionar Fazenda</a>
				<a href="<?= $base; ?>/clients" class="btn btn-info">Voltar</a>
			</div>

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

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