<?php
session_start();
include('conexion.php');
?>
<!doctype html>
<html lang="en" onclick="cerrar();cerrar2()">

<head>
    <?php
    include('./include/sesiones.php');
    include('include/head.php');
    ?>
    <div id="div_buscador"></div>
    <?php include('php_menu/menu_categorias.php');
    include('php_menu/menu_izquierdo.php');

    $fam_id = $_GET['fam_id'];
    ?>
</head>

<body>
    <br>
    <section class="home_product_area mb-50">
        <div class="container">
            <div class="row">
                <div class="col-12">
                    <?php
                    $centrar5 = mysqli_query($con, "SELECT * FROM familias where fam_id='$fam_id' and empresa='$emp_id' ") or die(mysqli_error($con));
                    $cero5 = mysqli_fetch_array($centrar5);
                    $fam_nombre = ucfirst($cero5['fam_nombre']);
                    $fam_id = $cero5['fam_id'];
                    ?>
                    <div class="section_title" id="categoria_productos">
                        <h2> <span><?php echo $fam_nombre; ?></span></h2>
                    </div>
                    <div class="shop_area shop_sidebar mb-50">
                        <div class="row">
                            <div class="col-lg-9 col-md-12">
                                <div class="shop_toolbar_wrapper">
                                    <div class="shop_toolbar_btn">
                                        <button data-role="grid_3" type="button" class="active btn-grid-3" data-bs-toggle="tooltip" title="3"></button>
                                        <button data-role="grid_4" type="button" class=" btn-grid-4" data-bs-toggle="tooltip" title="4"></button>
                                       <!-- <button data-role="grid_list" type="button" class="btn-list" data-bs-toggle="tooltip" title="List"></button> --->
                                    </div>
                                </div>
                                <div class='filter_data'></div>
                                <div class='resulta'></div>
                            </div>
                            <div class="col-lg-3 col-md-12">
                                <div class="widget_list widget_filter">
                                    <aside class="sidebar_widget">
                                        <div class="widget_list widget_categories">
                                            <h2>marcas</h2>
                                            <ul>
                                                <?php
                                                $can1 = mysqli_query($con, "SELECT * from articulos where familias_fam_id='$fam_id' and art_estado='Activo' and art_online='Activo' and art_tipo='articulo' group by marca_mar_id") or die(mysqli_error($con));
                                                while ($row = mysqli_fetch_array($can1)) {
                                                    $marca_mar_id = $row['marca_mar_id'];
                                                    $mar1 = mysqli_query($con, "SELECT * from marca where mar_id='$marca_mar_id' and empresa='$emp_id' ") or die(mysqli_error($con));
                                                    while ($mar = mysqli_fetch_array($mar1)) {
                                                        $mar_id = $mar['mar_id'];
                                                ?>
                                                        <div class="list-group-item">
                                                            <input type="checkbox" class="common_selector mar_id checkbox" value="<?php echo $mar['mar_id']; ?>">
                                                            <label><?php echo $mar['mar_nombre']; ?></label>
                                                        </div>
                                                <?php }
                                                } ?>
                                            </ul>
                                        </div>
                                    </aside>
                                </div>
                            </div>  
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <div id="resultados"></div>
    <?php include('include/footer.php') ?>
    <script src="assets/js/plugins.js"></script>
    <script src="assets/js/main.js"></script>
    <div id="resultados"></div>
    <script>
        function buscador() {
            $.get("./php_menu/buscador.php", "", function(data) {
                $("#div_buscador").html(data);
            })
        }
        buscador();

        $(document).ready(function() {
            load(1);
        });


        function load(page) {
            $('.filter_data').html('');
            var fam_id = '<?php echo $cero5['fam_id']; ?>';
            var mar_id = get_filter('mar_id');

            $.ajax({
                url: "./php_tienda/tabla_resultados_categoria.php",
                method: "GET",
                data: {
                    fam_id: fam_id,
                    mar_id: mar_id,
                    page: page
                },
                success: function(data) {
                    $('.filter_data').html(data);
                    buscador();
                }
            });
        }


        function get_filter(class_name) {
            var filter = [];
            $('.' + class_name + ':checked').each(function() {
                filter.push($(this).val());
            });
            return filter;
        }

        $('.common_selector').click(function() {
            load(1);
        });
    </script>