<ul class="list-group">
	<li class="list-group-item">
		<ul class="nav nav-pills alt-pills">
			<li class="nav-item">
				<a class="nav-link py-1" href="/productos/impresion">Imprimir
				</a>
			</li>
		</ul>
		<ul class="nav nav-pills alt-pills float-right mini-labels mt-1">
			
			<form method="get">
				<?php /*
				<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>Cantidad</label>
					<select name ="cantidad" class="form-control select-cantidad" onchange="this.form.submit()">
						<?php
							$filtroCantidad = [
								'50' => '50',
								'100' => '100',
								'200' => '200',
								'-1' => 'Todos',
							];

							foreach($filtroCantidad as $k => $v) {
								$selected = '';
								if ($filtros['cantidad'] == $k) {
									$selected =' selected="selected"';
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
				<li class="nav-item float-left mr-3">
					<label>Código de barra</label>
					<select name ="codigo" class="form-control select-codigo" onchange="this.form.submit()">
						<?php
							$filtroCodigos = [
								'0' => 'Sin Código',
								'1' => 'Con Código',
								'-1' => 'Todos'
							];

							foreach($filtroCodigos as $k => $v) {
								$selected = '';
								if ($filtros['codigo'] == $k) {
									$selected =' selected="selected"';
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
				<li class="nav-item float-left mr-3">
					<label>Existencia</label>
					<select name ="existencia" class="form-control select-existencia" onchange="this.form.submit()">
						<?php
							$existencias = [
								'1' => 'Disponibles',
								'0' => 'Sin Stock',
								'-1' => 'Todos'
							];
							foreach($existencias as $k => $v) {
								$selected = '';
								if ($filtros['existencia'] == $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 ($filtros['categoria'] == $k) {
									$selected =' selected="selected"';
								}
								if (!in_array($k, [7, 10, 11])){
									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 ($filtros['proveedor'] == $k) {
									$selected =' selected="selected"';
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
				<li class="nav-item float-left mr-3">
					<label>Busqueda</label>
					<input type="text" name ="busqueda" class="form-control input-busqueda-codigo" onchange="this.form.submit()" value="" />
				</li>
				<?php /*
				<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($resultados)) {
		?>
		<li class="list-group-item">
			<h4>Productos - Mostrando <?php echo count($resultados)?> registros</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">Código de barra</th>
							<th class="text-center">Acciones</th>
						</tr>
					</thead>
					<tbody>
						<?php
						foreach($resultados 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>
									<?php /*<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']]; ?></span></td>
								<td class="text-center"><?php echo $proveedores[$p['id_proveedor']]; ?></span></td>
								<td class="text-center stock-producto"><?php echo $p['disponibles_online']; ?></td>
								<td class="text-center">
									<?php
									if (!empty($p['codigo_barra'])) {
										echo $p['codigo_barra'];
									}
									else {
										echo '<input type="text" class="form-control input-codigo-barra-autosave" name="codigo_barra" data-id-producto="' . $p['id'] . '" value="" />';
									}
								?>
								</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>
