<ul class="list-group">
	<li class="list-group-item">
		<ul class="nav nav-pills alt-pills float-right mini-labels">
			<form method="get">
				<li class="nav-item float-left mr-3">
					<label>Periodo</label>
					<select name ="periodo" class="form-control select-periodo" onchange="this.form.submit()">
						<?php
							$periodos = [
								15 => '15 días',
								30 => '30 días',
								60 => '60 días',
							];

							foreach($periodos as $k => $v) {
								$selected = '';
								if (!empty($periodo)) {
									if ($periodo == $k) {
										$selected =' selected="selected"';
									}
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
				<li class="nav-item float-left mr-3">
					<label>Rankings</label>
					<select name ="ranking" class="form-control select-ranking" onchange="this.form.submit()">
						<?php
							$filtroRankings = [
								'-1' => 'Deseados',
								'1' => 'S',
								'2' => 'A',
								'3' => 'B',
								'4' => 'C',
								'5' => 'D',
								'0' => 'Sin Ranking'
							];

							foreach($filtroRankings as $k => $v) {
								$selected = '';
								if ($ranking == $k) {
									$selected =' selected="selected"';
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
				<li class="nav-item float-left mr-3">
					<label>Categoría</label>
					<select name ="categoria" class="form-control select-id-categoria" onchange="this.form.submit()">
					<option value="0">Todas</option>
						<?php
							foreach($categorias as $k => $v) {
								$selected = '';
								if (!empty($categoria)) {
									if ($categoria == $k) {
										$selected =' selected="selected"';
									}
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
				<li class="nav-item float-left mr-3">
					<label>Proveedor</label>
					<select name ="proveedor" class="form-control select-id-proveedor" onchange="this.form.submit()">
					<option value="0">Todos</option>
						<?php
							foreach($distribuidores as $k => $v) {
								$selected = '';
								if (!empty($proveedor)) {
									if ($proveedor == $k) {
										$selected =' selected="selected"';
									}
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
			</form>
		</ul>
	</li>
	<?php
	if(!empty($sugeridos)) {
		?>
		<li class="list-group-item">
			<h4><?php echo $titulo; ?></h4>
			<div class="table-responsive">
				<table class="table table-striped">
					<thead>
						<tr>
							<th class="text-center">PS</th>
							<th>Producto</th>
							<th class="text-center">Categoría</th>
							<th class="text-center">Proveedor</th>
							<th class="text-center">Disponibles</th>
							<th class="text-center">Vendidos Periodo</th>
							<th class="text-center">Tipo Reposición</th>
							<th class="text-center">Compra sugerida</th>
							<th class="text-center">Acciones</th>
						</tr>
					</thead>
					<tbody>
						<?php
						$tiposReposicion = [
							0 => 'No definido',
							1  => 'Stock mínimo 1 mes',
							2  => 'Stock mínimo 2 meses',
							3  => 'Stock mínimo 3 meses'
						];

						foreach ($sugeridos as $p) {
							?>
							<tr class="descuadre<?php echo $p['id']; ?>">
								<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 echo $categorias[$p['id_categoria']]; ?></td>
								<td class="text-center"><?php echo $proveedores[$p['id_proveedor']]; ?></td>
								<td class="text-center stock-producto"><?php echo $p['disponibles']; ?></td>
								<td class="text-center"><?php echo $p['vendidos_periodo']; ?></td>
								<td class="text-center"><?php echo $tiposReposicion[$p['tipo_reposicion']]; ?></td>
								<td class="text-center"><?php echo $p['tipo_reposicion'] == 0 ? '' : $p['recomendado_compra']; ?></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">No hay productos</li>
		<?php
	}
	?>
</ul>

<?php $this->load->view('productos/modal'); ?>

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