<ul class="list-group">
    <?php
    if(!empty($faltantes)) {
        foreach($faltantes as $key => $categoria) {
            if(!empty($categoria)) { 
                ?>
                    <li class="list-group-item">
                        <h4 class="proveedor clickable" data-toggle="collapse" href="#collapse<?php echo $key; ?>">
                            <?php 
                                echo $categorias[$key] ?? 'Sin Categoría';
                            ?>
                            <span class="badge badge-pill badge-primary"><?php echo count($categoria)?></span>
                        </h4>
                        <div class="collapse" id="collapse<?php echo $key; ?>">
                            <div class="table-responsive">
                                <table class="table table-striped">
                                    <thead>
                                        <tr>
                                            <th class="text-center">Prestashop</th>
                                            <th>Producto</th>
                                            <th class="text-center">Disponibles</th>
                                            <th class="text-center">Disponibles Tienda</th>
                                            <th class="text-center">Acciones</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        foreach($categoria 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>
                                                </td>
                                                <td class="text-center stock-producto"><?php echo $p['disponibles']; ?></td>
                                                <td class="text-center"><span class="badge badge-pill badge-danger suma-stock-almacenes"><?php echo $p['disponibles_almacen']; ?></span></td>
                                                <td class="text-center">
                                                    <button type="button" class="btn btn-primary btn-xs d-none 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>
                        </div>
                    </li>
                <?php
            }
        }
    }
    else {
        ?>
        <li class="list-group-item">No hay descuadres</li>
        <?php
    }
    ?>
</ul>

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

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