<ul class="list-group">
	<?php
	if(!empty($rows['sin_remover'])) {
	?>
	<li class="list-group-item">
		<h2 data-toggle="collapse" href="#collapse_sin_remover" class="clickable">Productos con Stock Crítico Online que se encuentran con stock publicado en <?= $linkActivo['section']; ?> (<?= count($rows['sin_remover']); ?> productos)</h2>
		<div id="collapse_sin_remover" class="table-responsive collapse show">
			<table class="table table-striped">
				<thead>
					<tr>
					<th class="text-center">Prestashop</th>
						<th>Producto</th>
						<th class="text-center">Disponibilidad</th>
						<th class="text-center">Disponibles Online</th>
						<th class="text-center">PS</th>
						<?php
							if (!empty($marketplaces_detalles)) {
								foreach($marketplaces_detalles as $mp) {
									echo '<th class="text-center">' . $mp['abreviacion'] . '</th>';
								}
							}
						?>
						<th class="text-center">Editar</th>
					</tr>
				</thead>
				<tbody>
					<?php
					foreach($rows['sin_remover'] as $p) {
						?>
						<tr>
							<td class="text-center">
								<?php 
									if ($p['ps_id'] > 0) {
										?>
										<span class="badge badge-pill badge-primary ps-id-product ver-ps" data-ps-id="<?php echo $p['ps_id']; ?>">
											<?php echo $p['ps_id']; ?>
										</span>
										<?php
									}
								?>
							</td>
							<td>
								<?php
								if (!empty($ps_imagenes[$p['ps_id']])) {
									echo ps_image($ps_imagenes[$p['ps_id']]);
								} 
								?>
								<a target="_blank" href="/productos/detalle/<?php echo $p['id']; ?>">
									<span class="nombre"><?php echo $p['nombre']; ?></span>
								</a>
								<span class="badge badge-pill badge-primary"><?php echo $rankings[$p['id_ranking']]?></span>
								
							</td>
							<td class="text-center">
								<?php
									if ($p['disponibles'] > 0) {
										echo '<span class="badge badge-pill badge-success">Disponible</span>';
										$badgeDisponibles = 'success';
									}
									else {
										if (!empty($p['available_now'])) {
											echo '<span class="badge badge-pill badge-warning">Preventa</span>';
											$badgeDisponibles = 'warning';
										}
										else {
											echo '<span class="badge badge-pill badge-danger">Agotado</span>';
											$badgeDisponibles = 'danger';
										}
									}
								?>
							</td>
							<td class="text-center"><span class="badge badge-pill badge-<?php echo $badgeDisponibles;?>"><?php echo $p['disponibles_online']; ?></span></td>
							<td class="text-center"><?php echo danger_badge($p['ps_disponibles'], 'mayor', $p['disponibles_online']); ?></td>
							<?php
								if (!empty($marketplaces_detalles)) {
									foreach($marketplaces_detalles as $mp) {
										if (isset($p['marketplaces'][$mp['id']]['stock'])) {
											echo '<td class="text-center"><span class="tt" title="Disponibles ' . $marketplaces_detalles[$mp['id']]['abreviacion'] . '">' . danger_badge($p['marketplaces'][$mp['id']]['stock'], 'mayor', $p['disponibles']) . '</td>';
										}
										else {
											echo '<td class="text-center"></td>';
										}
									}
								}
							?>
							<td class="text-center">
								<button type="button" class="btn btn-primary btn-xs d-lg-inline" data-toggle="modal" data-target="#modalProducto" data-id="<?php echo $p['id']; ?>">
									<i class="fas fa-pencil-alt"></i>
								</button>
							</td>
						</tr>
					<?php
					}
					?>
				</tbody>
			</table>
		</div>
	</li>
	<?php
}
else {
	?>
	<li class="list-group-item">
		<h2>Productos Sin Stock <?= $linkActivo['section']; ?> (0 productos)</h2>
		<p><strong>No se encontraron productos</strong></p>
	</li>
	<?php
}
if(!empty($rows['sin_recargar'])) {
?>
	<li class="list-group-item">
		<h2 data-toggle="collapse" href="#collapse_sin_recargar" class="clickable">Productos Sin Recargar <?= $linkActivo['section']; ?> (<?= count($rows['sin_recargar']); ?> productos)</h2>
		<div  id="collapse_sin_recargar" class="table-responsive collapse show">
			<table class="table table-striped">
				<thead>
					<tr>
					<th class="text-center">Prestashop</th>
						<th>Producto</th>
						<th class="text-center">Disponibilidad</th>
						<th class="text-center">Disponibles Online</th>
						<th class="text-center">PS</th>
						<?php
							if (!empty($marketplaces_detalles)) {
								foreach($marketplaces_detalles as $mp) {
									echo '<th class="text-center">' . $mp['abreviacion'] . '</th>';
								}
							}
						?>
						<th class="text-center">Editar</th>
					</tr>
				</thead>
				<tbody>
					<?php
					foreach($rows['sin_recargar'] as $p) {
						?>
						<tr>
							<td class="text-center">
								<?php 
									if ($p['ps_id'] > 0) {
										?>
										<span class="badge badge-pill badge-primary ps-id-product ver-ps" data-ps-id="<?php echo $p['ps_id']; ?>">
											<?php echo $p['ps_id']; ?>
										</span>
										<?php
									}
								?>
							</td>
							<td>
								<?php
								if (!empty($ps_imagenes[$p['ps_id']])) {
									echo ps_image($ps_imagenes[$p['ps_id']]);
								} 
								?>
								<a target="_blank" href="/productos/detalle/<?php echo $p['id']; ?>">
									<span class="nombre"><?php echo $p['nombre']; ?></span>
								</a>
								<span class="badge badge-pill badge-primary"><?php echo $rankings[$p['id_ranking']]?></span>
								
							</td>
							<td class="text-center">
								<?php
									if ($p['disponibles'] > 0) {
										echo '<span class="badge badge-pill badge-success">Disponible</span>';
										$badgeDisponibles = 'success';
									}
									else {
										if (!empty($p['available_now'])) {
											echo '<span class="badge badge-pill badge-warning">Preventa</span>';
											$badgeDisponibles = 'warning';
										}
										else {
											echo '<span class="badge badge-pill badge-danger">Agotado</span>';
											$badgeDisponibles = 'danger';
										}
									}
								?>
							</td>
							<td class="text-center"><span class="badge badge-pill badge-<?php echo $badgeDisponibles;?>"><?php echo $p['disponibles_online']; ?></span></td>
							<td class="text-center"><?php echo danger_badge($p['ps_disponibles'], 'mayor', $p['disponibles_online']); ?></td>
							<?php
								if (!empty($marketplaces_detalles)) {
									foreach($marketplaces_detalles as $mp) {
										if (isset($p['marketplaces'][$mp['id']]['stock'])) {
											echo '<td class="text-center"><span class="tt" title="Disponibles ' . $marketplaces_detalles[$mp['id']]['abreviacion'] . '">' . danger_badge($p['marketplaces'][$mp['id']]['stock'], 'mayor', $p['disponibles']) . '</td>';
										}
										else {
											echo '<td class="text-center"></td>';
										}
									}
								}
							?>
							<td class="text-center">
								<button type="button" class="btn btn-primary btn-xs d-lg-inline" data-toggle="modal" data-target="#modalProducto" data-id="<?php echo $p['id']; ?>">
									<i class="fas fa-pencil-alt"></i>
								</button>
							</td>
						</tr>
					<?php
					}
					?>
				</tbody>
			</table>
		</div>
	</li>
	<?php
}
else {
	?>
	<li class="list-group-item">
		<h2>Productos Sin Recargar <?= $linkActivo['section']; ?> (0 productos)</h2>
		<p><strong>No se encontraron productos</strong></p>
	</li>
	<?php
}


echo '</ul>';
?>

<?php $this->load->view('productos/modal'); ?>
<script src="<?php echo js('productos.js'); ?>"></script>
