<ul class="list-group">
<?php
if(!empty($productos)) {
	?>
	<li class="list-group-item">
		Costo total preventas no pagadas: <?php echo clp($costos['total']); ?><br>
		<table>
			<tr><th>Proveedor</th><th>Total</th></tr>
			<?php foreach ($costos['proveedores'] as $kp => $total) {
				echo '<tr><td>' . $proveedores[$kp] . '</td><td class="text-right">' . clp($total) . '</td></tr>';
			}
			?>
		</table>
	</li>
	<li class="list-group-item">
		<div class="table-responsive">
			<?php /*
			<div class="row border rounded pt-2 pb-2 mb-1">
				<div class="col-3 col-lg-4"><h5>Producto</h5></div>
				<div class="col-3 col-lg-2"><h5>Proveedor</h5></div>
				<div class="col-2 col-lg-2"><h5>Fecha Publicada</h5></div>
				<div class="col-1 col-lg-1 text-right"><h5>Prevendidos</h5></div>
				<div class="col-1 col-lg-1 text-right"><h5>Disponibles</h5></div>
				<div class="col-2 col-lg-2 text-right"><h5>Costo</h5></div>
			</div>
			*/
			?>
			<table class="table">
				<thead>
					<tr>
						<th>Producto</th>
						<th>Proveedor</th>
						<th>Fecha Publicada</th>
						<th class="text-right">Prevendidos</th>
						<th class="text-right">Disponibles</th>
						<th class="text-right">Costo</th>
					</tr>
				</thead>
				<tbody>
					<?php
					foreach($productos as $p) {
						?>
						<tr">
							<td>
								<a target="_blank" href="/productos/detalle/<?php echo $p['id']; ?>">
									<span class="nombre"><?php echo $p['nombre']; ?></span>
								</a>
							</td>
							<td><?php echo $proveedores[$p['id_proveedor']]; ?></td>

							<?php
							$availableTime = strtotime($p['available_date']);
							$todayTime = strtotime(date("Y-m-d"));
							$monthTime = strtotime(date("Y-m-d") . "+ 1 months");
							if ($p['available_date'] == '0000-00-00') {
								$labelClass = 'secondary'; // Red
							}
							elseif ($availableTime < $todayTime) {
								$labelClass = 'danger'; // Red
							}
							elseif ($availableTime < $monthTime) {
								$labelClass = 'warning'; // Yellow
							}
							else {
								$labelClass = 'success'; // Green
							}
							?>
							<td><?php echo '<span class="badge badge-' . $labelClass . '">' . fecha($p['available_date']) . '</span>'; ?></td>
							<td class="text-right"><?php echo $p['prevendidos']; ?></td>
							<td class="text-right"><?php echo $p['disponibles']; ?></td>
							<td class="text-right"><?php echo !empty($costos[$p['id']]) ? clp($costos[$p['id']]) : '0'; ?></td>
						</tr>
						<?php
					}
					?>
				</tbody>
			</table>
		</div>
	</li>
	<?php
}
else {
	?>
	<li>A&uacute;n no hay productos con preventas</li>
	<?php
}
echo '</ul>';
?>

<?php /*
<script src="<?php echo js('productos.js'); ?>"></script>
<script src="<?php echo base_url(); ?>js/productos.js"></script>
*/ ?>
