<?php

use Source\Helpers\Check;
?>
<!-- AD SECTION -->
<?php if (!empty($CONF_PAGE['files']['pagina_top'])): ?>
    <div class="looja-page-top">        
        <?php
        $local_page = $CONF_PAGE['files']['pagina_top'];
         $local_banner = 2;
        require "dist/page/setComponente.php";
        ?>         
    </div>
<?php endif; ?>
<!-- /AD SECTION -->
<!-- AD TWO COLS -->
<?php if (!empty($CONF_PAGE['files']['pagina_two_left']) || !empty($CONF_PAGE['files']['pagina_two_right'])): ?>  
    <div class="<?= $page_full ?>  looja-page-top-2">
        <div class="row">
            <div class="col-lg-8">
                <?php
                if (!empty($CONF_PAGE['files']['pagina_two_left'])):
                    $local_page = $CONF_PAGE['files']['pagina_two_left'];
                    $local_banner = 2;
                    require "dist/page/setComponente.php";
                endif;
                ?>
            </div> 
            <div class="col-lg-4">
                <?php
                if (!empty($CONF_PAGE['files']['pagina_two_right'])):
                    $local_page = $CONF_PAGE['files']['pagina_two_right'];
                 $local_banner = 2;
                    require "dist/page/setComponente.php";
                endif;
                ?>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>
<?php endif; ?>
<!-- /AD TWO COLS -->
<!-- Shop Category Area End -->
<div class="shop-category-area mt-30px">
    <div class="container">
        <div class="row">
            <div class="col-lg-9 order-lg-last col-md-12 order-md-first">
                <!-- Shop Top Area Start -->
                 <div class=" shop-top-bar">
                    <div class="header-shop-list d-flex">
                        <!-- Left Side start -->
                        <div class="header-open d-mobile">
                            <i class="fa fa-filter"></i> <span>Filtrar</span>
                        </div>  
                        
                        <!-- Left Side End -->
                        <!-- Right Side Start -->
                        <div class="select-shoing-wrap">
                            <div class="shot-product">
                                <p class="d-mobile"><i class="fa fa-list-ol"></i></p><p class="d-desktop">Ordenar</p>
                            </div>
                            <div class="shop-select">
                                <form method="post" action="?" id="form-filter" class="form-filter">
                                    <input name="filter_url" value="<?= $url_secao . $url_categoria . $url_link . $url_tag . $url_marca . $url_price ?>" type="hidden">
                                    <select name="filter_order">
                                        <option value="all" <?= ($select_order == 'all' ? 'selected="selected"' : "") ?>>Relevância</option>
                                        <option value="asc" <?= ($select_order == 'asc' ? 'selected="selected"' : "") ?>>De A a Z</option>
                                        <option value="desc" <?= ($select_order == 'desc' ? 'selected="selected"' : "") ?>>De Z a A</option>
                                        <option value="datedesc" <?= ($select_order == 'datedesc' ? 'selected="selected"' : "") ?>>Mais recente</option>
                                        <option value="dateasc" <?= ($select_order == 'dateasc' ? 'selected="selected"' : "") ?>>Mais antigo</option>
                                        <option value="pricedesc" <?= ($select_order == 'pricedesc' ? 'selected="selected"' : "") ?>>Maior preço</option>
                                        <option value="priceasc" <?= ($select_order == 'priceasc' ? 'selected="selected"' : "") ?>>Menor preço</option>
                                    </select>
                                </form>
                            </div>

                        </div>                   
                        <!-- Right Side End -->
                    </div>
                    <div class="shop-tab nav d-flex">
                        <a class="active" href="#shop-1" data-toggle="tab">
                            <i class="fa fa-th"></i>
                        </a>
                        <a href="#shop-2" data-toggle="tab">
                            <i class="fa fa-list"></i>
                        </a>
                        <div class="area-pagination">     
                            <p>Exibindo página <?= $DATA_PAGINACAO['atual_page'] ?> de <?= $DATA_PAGINACAO['total_page'] ?> com <?= $DATA_PAGINACAO['count_results'] ?> dos <?= $DATA_PAGINACAO['total_result'] ?> registros .</p>
                        </div>
                    </div>
                    <!-- Shop Top Area End -->
                </div>
                <!-- Shop Top Area End -->

                <!-- Shop Bottom Area Start -->
                <div class="shop-bottom-area mt-35">
                    <!-- Shop Tab Content Start -->
                    <div class="tab-content jump">
                        <!-- Tab One Start -->
                        <div id="shop-1" class="tab-pane active">
                            <div class="row responsive-md-class responsive-xl-class responsive-lg-class">
                                <?php
                                if ($RESULT_ALL):
                                    foreach ($RESULT_ALL as $produto):
                                      //  extract($produto);

                                       $class_col = "col-xl-3 col-md-4 col-sm-6 col-6";
                                        require "component/rozer/views/tpl-produto-col.php";


                                    endforeach;

                                endif;
                                ?> 
                            </div>
                        </div>
                        <!-- Tab One End -->
                        <!-- Tab Two Start -->
                        <div id="shop-2" class="tab-pane">
                            <?php
                            if ($RESULT_ALL):
                                foreach ($RESULT_ALL as $produto):
                                   // extract($produto);

                                      $class_col = "col-xl-3 col-md-4 col-sm-6";
                                    require "component/rozer/views/tpl-produto-row.php";


                                endforeach;

                            endif;
                            ?> 
                        </div>
                        <!-- Tab Two End -->
                    </div>
                    <!-- Shop Tab Content End -->
                    <!--  Pagination Area Start -->
                    <div class="pro-pagination-style text-center mb-60px mt-30px">
                        <?= $PAGINACAO ?>
                    </div>
                    <!--  Pagination Area End -->
                </div>
                <!-- Shop Bottom Area End -->
            </div>
           <div class="col-lg-3 order-lg-first col-md-12 order-md-last mb-md-60px mb-lm-60px">
              <div class="shop-sidebar-wrap">
                    <?php
                    if ($select_price || $select_marca):
                        ?>
                        <div class="sidebar-widget filter-aplicado padding-30px bg-light-gray-2 mb-30px">
                            <?php
                            if ($select_price):
                                $ranger = explode("-", $select_price);
                                $ranger_link = $url_secao . $url_categoria . $url_link . $url_tag . $url_marca;
                                echo "<a href='{$ranger_link}' ><i class='fa fa-times'></i> R$ {$ranger[0]} até R$ {$ranger[1]}</a>";
                            endif;
                           
                            if ($select_marca):
                                $marca = (new \Source\Models\Marcas)->find('brand_name=:name', "name={$select_marca}", "brand_title")->fetch();
                                $brand_link = $url_secao . $url_categoria . $url_link . $url_tag . $url_price;
                                echo "<a href='{$brand_link}' ><i class='fa fa-times'></i> {$marca->brand_title}</a>";
                            endif;
                            ?>
                        </div>
                        <?php
                    endif;
                    if ($produtosCategorySecao):
                        $csecao = $produtosCategorySecao[0];
                        ?>
                        <div class="sidebar-widget padding-30px bg-light-gray-2 mb-30px">

                            <h3 class="sidebar-title"><?= $csecao['secao_title'] ?></h3>

                            <div class="card">
                                <div class="card-body">
                                    <ul class="category-list">
                                        <?php
                                        $Read->ExeRead(DB_CATEGORY, "WHERE category_parent=:de AND (category_para IS NULL OR category_para='') ", "de={$csecao['secao_id']}");
                                        if ($Read->getResult()):
                                            foreach ($Read->getResult() as $categoria):
                                                $Read->FullRead("SELECT COUNT(produto_id) as 'count' FROM " . DB_PRODUTS . " WHERE produto_categoria=:ca", "ca={$categoria['category_id']}");
                                                $countPro = $Read->getResult()[0]['count'];
                                                ?>
                                                <li><a href="<?= SITE ?><?= $csecao['secao_name'] ?>/<?= $categoria['category_name'] ?>"><?= $categoria['category_title'] ?>  <span>(<?= $countPro ?>)</span></a></li> 
                                                <?php
                                            endforeach;
                                        endif;
                                        ?>
                                    </ul>
                                </div>
                            </div> 
                        </div>
                    <?php endif; ?>
                    <?php if ($produtosSecao): ?>
                        <div class="sidebar-widget padding-30px bg-light-gray-2 mb-30px">
                            <h3 class="sidebar-title">Departamentos</h3>
                            <div class="accordion" id="accordionExample">
                                <div class="card">
                                    <?php
                                    foreach ($produtosSecao as $secao):
                                        $Read->FullRead("SELECT COUNT(produto_id) as 'count' FROM " . DB_PRODUTS . " WHERE produto_secao=:ca AND produto_ativar=1", "ca={$secao['secao_id']}");
                                        $countPro = $Read->getResult()[0]['count'];
                                        $Read->ExeRead(DB_CATEGORY, "WHERE category_parent=:de AND (category_para IS NULL OR category_para='') ", "de={$secao['secao_id']}");
                                        if ($Read->getResult()) {
                                            ?>
                                            <div class="card-header" id="headingOne">
                                                <a href="<?= SITE ?><?= $secao['secao_name'] ?>" data-toggle="collapse" data-target="#<?= $secao['secao_name'] ?>" aria-expanded="false" aria-controls="<?= $secao['secao_name'] ?>" class="collapsed"><?= $secao['secao_title'] ?>  <span>(<?= $countPro ?>)</span></a>
                                            </div>
                                            <?php ?>
                                            <div id="<?= $secao['secao_name'] ?>" class="collapse" aria-labelledby="<?= $secao['secao_name'] ?>" data-parent="#accordionExample" style="">
                                                <div class="card-body">
                                                    <ul class="category-list">
                                                        <?php
                                                        if ($Read->getResult()):
                                                            foreach ($Read->getResult() as $categoria):
                                                                $Read->FullRead("SELECT COUNT(produto_id) as 'count' FROM " . DB_PRODUTS . " WHERE produto_categoria=:ca", "ca={$categoria['category_id']}");
                                                                $countPro = $Read->getResult()[0]['count'];
                                                                ?>
                                                                <li><a href="<?= SITE ?><?= $secao['secao_name'] ?>/<?= $categoria['category_name'] ?>"><?= $categoria['category_title'] ?>  <span>(<?= $countPro ?>)</span></a></li> 
                                                                <?php
                                                            endforeach;
                                                        endif;
                                                        ?>
                                                    </ul>
                                                </div>
                                            </div>
                                            <?php
                                        } else {
                                            ?>
                                            <div class="card-header" id="headingOne">
                                                <a href="<?= SITE ?><?= $secao['secao_name'] ?>" data-target="#<?= $secao['secao_name'] ?>"  aria-controls="<?= $secao['secao_name'] ?>" class="collapsed"><?= $secao['secao_title'] ?>  <span>(<?= $countPro ?>)</span></a>
                                            </div>
                                            <?php
                                        }
                                    endforeach;
                                    ?>
                                </div> <!-- card -->

                            </div>
                        </div>
                    <?php endif; ?>

                    <!-- Sidebar single item -->
                    <div class="sidebar-widget-group mt-20 padding-30px">
                        <h3 class="sidebar-title">Filtros</h3>
                        <div class="sidebar-widget mt-20">
                            <h4 class="pro-sidebar-title">Preço</h4>
                            <div class="price-filter mt-10">
                                <form method="post" action="?" id="form-filter">
                                    <input name="filter_url" value="<?= $url_secao . $url_categoria . $url_link . $url_order . $url_tag . $url_marca ?>" type="hidden">
                                    <div class="pricebox">
                                        <input class="form-control money" name="min" placeholder="R$ 100.00" required="">
                                        <span>até</span>
                                        <input class="form-control money" name="max" placeholder="R$ 1000.00" required="">
                                    </div> 
                                    <div class="separator">&nbsp;</div>
                                    <button class="btn btn-sm btn-block btn-primary">APLICAR</button>
                                </form>
                            </div>

                        </div>                      
                        <!-- Sidebar single item -->
                        <div class="sidebar-widget mt-30">

                            <?php
                            if (!empty($ProdutosMarcas)):
                                ?>
                                <h4 class="pro-sidebar-title">Marcas</h4>
                                <div class="sidebar-widget-list">
                                    <ul>
                                        <?php
                                        foreach ($ProdutosMarcas as $marca):

                                            $Read->FullRead("SELECT COUNT(produto_id) as 'count' FROM " . DB_PRODUTS . " WHERE produto_marca=:ca", "ca={$marca['brand_id']}");
                                            $countPro = $Read->getResult()[0]['count'];
                                            if ($countPro):
                                                ?>
                                                <li> 
                                                    <div class="sidebar-widget-list-left">
                                                        <input type="checkbox" value="" />  <a href="<?= SITE . $url_secao . $url_categoria . $url_link . $url_order . $url_price . $url_tag ?>&marca=<?= $marca['brand_name'] ?>"><?= $marca['brand_title'] ?> <span  >(<?= $countPro ?>)</span> </a>
                                                        <span class="checkmark"></span>
                                                    </div>                                    
                                                </li>
                                                <?php
                                            endif;
                                        endforeach;
                                        ?>
                                    </ul>
                                </div>
                            <?php endif; ?> 

                        </div> 
                    </div>
                    <!-- Sidebar single item -->
                    <!--                    <div class="sidebar-widget tag mt-30px">
                                            <div class="main-heading">
                                                <h3 class="sidebar-title">Tags</h3>
                                            </div>
                                            <div class="sidebar-widget-tag">
                                                <ul>
                                                    <li><a href="#">Electronics</a></li>
                                                    <li><a href="#">Audio & Video</a></li>
                                                    <li><a href="#">Video Games</a></li>
                                                    <li><a href="#">Camera & Photo</a></li>
                                                </ul>
                                            </div>
                                        </div>-->
                    <!-- Sidebar single item -->
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Shop Category Area End -->


<!-- AD SECTION -->
<?php if (!empty($CONF_PAGE['files']['pagina_botton'])): ?>
    <div class="looja-page-center-2">
        <div class="<?= $page_full ?> style-container">
            <?php
            $local_page = $CONF_PAGE['files']['pagina_botton'];
             $local_banner = 4;
            require "dist/page/setComponente.php";
            ?>    
        </div>
    </div>
<?php endif; ?>
<!--// AD SECTION -->
<!-- AD COLS -->
<div class="<?= $page_full ?>  looja-page-footer-2">
    <div class="row">
        <div class="col-lg-4">
            <?php
            if (!empty($CONF_PAGE['files']['pagina_bottom_col_left'])):
                $local_page = $CONF_PAGE['files']['pagina_bottom_col_left'];
                require "dist/page/setComponente.php";
            endif;
            ?>
        </div> 
        <div class="col-lg-4">
            <?php
            if (!empty($CONF_PAGE['files']['pagina_bottom_col_center'])):
                $local_page = $CONF_PAGE['files']['pagina_bottom_col_center'];
                require "dist/page/setComponente.php";
            endif;
            ?>
        </div>
        <div class="col-lg-4">
            <?php
            if (!empty($CONF_PAGE['files']['pagina_bottom_col_right'])):
                $local_page = $CONF_PAGE['files']['pagina_bottom_col_right'];
                require "dist/page/setComponente.php";
            endif;
            ?>
        </div>
        <div class="clearfix"></div>
    </div>
</div>
<!--// COLS --> 