<ul class="list-group">
    <li class="list-group-item">
        <form method="get">
            <div class="row mini-labels">
            
                <div class="col-12 col-md-10">
                </div>

                <div class="col-12 col-md-2">
                    <label>Proveedor</label>
                    <select name ="p" class="form-control select-id-proveedor" onchange="this.form.submit()">
                    <option value="0">Todos</option>
                        <?php
                            foreach($distribuidores as $k => $v) {
                                $selected = '';
                                if (!empty($p)) {
                                    if ($p == $k) {
                                        $selected =' selected="selected"';
                                    }
                                }
                                echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
                            }
                        ?>
                    </select>
                </div>
            </div>
        </form>
    </li>
<?php
if(!empty($productos)) {
    ?>
    <li class="list-group-item">
        <h4 class="char">Productos agotados en los últimos 30 días</h4>
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th class="text-center">Prestashop</th>
                        <th>Producto</th>
                        <th class="text-center">Última Venta</th>
                        <th class="text-center">Stock PS</th>
                        <?php
							if (!empty($marketplaces_detalles)) {
								foreach($marketplaces_detalles as $mp) {
									echo '<th class="text-center">' . $mp['abreviacion'] . '</th>';
								}
							}
						?>
                        <th class="text-center">Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    foreach($agotados 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 echo fecha($p['ultima_venta']); ?></td>
                            <td class="text-center"><?php echo danger_badge($p['quantity'], 'mayor', 0); ?></td>
                            <?php
								if (!empty($marketplaces_detalles)) {
									foreach($marketplaces_detalles as $mp) {
										if (isset($p['marketplaces'][$mp['id']]['stock'])) {
											echo '<td class="text-center">' . danger_badge($p['marketplaces'][$mp['id']]['stock'], 'mayor', 0) . '</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>No hay productos agotados en el último mes</li>
    <?php
}
?>
</ul>

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

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