<div class="page-title">
    <div class="container">
        <div class="banner-full-wrap">
            <div class="row g-0">
                <div class="col-md-4">
                    <div class="text-center banner-right-wrap">
                        <h1 class="main-title">Shop</h1>
                    </div>
                </div>
                <div class="col-md-8">
                    <img src="<?php echo base_url(); ?>assets/user/img/shop-banner.webp" alt="shop" class="w-100">
                </div>
            </div>
        </div>
    </div>
</div>
<!-- page-title end -->
<?php  
   $sidebarcat = $this->common->getData('category',array('show'=>1,'parent'=>0),array(),array('field'=>'item_order','by'=>'asc'));
   // $brand = $this->common->getData('brand',array(),array(),array('field'=>'id','by'=>'asc'));
?>
<!-- produt start -->
<div class="shop">
    <div class="container">
        <div class="row  g-3">
            <div class="col-lg-3 col-md-4 col-12  shop-sidebar">
                <div class="sidebox mb-0 pe-md-5 pb-4">
                    <div class="title-wrap">
                        <h1 class="side-title"> Category </h1>
                    </div>
                    <div class="accordion" id="accordionExample">
                        <div class="accordion-item">
                            <p class="accordion-header">
                                <a href="<?php echo base_url(); ?>shop" class="category-name <?php echo(!isset($_GET['catid']))?'active':''; ?>">
                                    All
                                </a>
                            </p>
                        </div>
                        <?php if(isset($sidebarcat) && $sidebarcat){ foreach($sidebarcat as $key => $value){ 
                            $subcat = $this->common->getData('category',array('parent'=>$value['c_id'],'show'=>1),array(),array('field'=>'item_order','by'=>'asc'));
                        ?>
                            <div class="accordion-item">
                                <p class="accordion-header" id="headingOne">
                                    <a href="<?php echo base_url('shop/'.url_title(strtolower($value['category'])).'/pr?catid='.$value['c_id']); ?>" class="category-name <?php echo(isset($_GET['catid']) && $_GET['catid']==$value['c_id'])?'active':''; ?>">
                                        <?php echo $value['category']; ?>
                                    </a>
                                    <?php if(isset($subcat) && $subcat){ 
                                        $sub = array_column($subcat, 'c_id');
                                    ?>
                                        <button class="accordion-button <?php echo(isset($_GET['catid']) && in_array($_GET['catid'],$sub))?'':'collapsed'; ?>" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne<?php echo $value['c_id']; ?>" aria-expanded="true" aria-controls="collapseOne"></button>
                                    <?php } ?>
                                </p>
                                <?php if(isset($subcat) && $subcat){ ?>
                                    <div id="collapseOne<?php echo $value['c_id']; ?>" class="accordion-collapse collapse <?php echo(isset($_GET['catid']) && in_array($_GET['catid'],$sub))?'show':''; ?>" aria-labelledby="headingOne<?php echo $value['c_id']; ?>" data-bs-parent="#accordionExample">
                                        <div class="accordion-body">
                                            <ul class="list-unstyled">
                                                <?php foreach ($subcat as $key1 => $value1){ ?>
                                                    <li>
                                                        <a href="<?php echo base_url('shop/'.url_title(strtolower($value1['category'])).'/pr?catid='.$value1['c_id']); ?>" class="<?php echo(isset($_GET['catid']) && $_GET['catid']==$value1['c_id'])?'active':''; ?>"> <?php echo $value1['category']; ?> </a>
                                                    </li>
                                                <?php } ?>
                                            </ul>
                                        </div>
                                    </div>
                                <?php } ?>
                            </div>
                        <?php } } ?>
                    </div>
                    <?php /*if(isset($brand) && $brand){ ?>
                        <div class="brand">
                            <h4 class="esmond-title">Brands</h4>
                            <form id="filterForm" action="<?php echo base_url(); ?>shop" method="get">
                                <?php if(isset($_GET['catid']) && $_GET['catid']!=''){ ?>
                                    <input type="hidden" name="catid" value="<?php echo $_GET['catid']; ?>">
                                <?php } ?>
                                <ul class="list-unstyled">
                                    <?php foreach($brand as $key => $value){ ?>
                                        <li><label><input type="checkbox" class="form-check-input changeFilter" name="brand[]" value="<?php echo $value['brandid'] ?>" <?php echo(isset($_GET['brand']) && in_array($value['brandid'], $_GET['brand']))?'checked':''; ?> /> <?php echo $value['brand_name']; ?></label></li>
                                    <?php } ?>
                                </ul>
                            </form>
                        </div>
                    <?php }*/ ?>
                </div>
            </div>
            <div class="col-lg-9 col-md-8 col-12">
                <div class="row g-md-5 g-3">
                    <?php if (isset($products) && !empty($products)){
                        foreach ($products as $key => $value) {
                    ?>
                        <div class="col-lg-4 col-md-4 col-sm-6 col-12">
                            <div class="product">
                                <div class="product-wrap">
                                    <div class="product-img">
                                        <a href="<?php echo base_url('shop-detail/'.strtolower($value['product_slug']).'/'.$value['productid']); ?>">
                                            <?php if($value['product_image']!=''){ $pimg = base_url($value['product_image']); ?>
                                                <img src="<?php echo base_url($value['product_image']); ?>" alt="<?php echo substr($value['product_name'],0, 15); ?>" class="img-fluid pro-img">
                                            <?php }else{ $pimg = base_url('assets/user/img/product-item.webp'); ?>
                                                <img src="<?php echo base_url('assets/user/img/product-item.webp'); ?>" alt="<?php echo substr($value['product_name'],0, 15); ?>" class="img-fluid pro-img">
                                            <?php } ?>
                                        </a>
                                        <div class="product-btn">
                                            <?php if($value['product_sale_price']>0){ $price = $value['product_sale_price']; }else{ $price = $value['product_price']; } ?>
                                            <a href="javascript:void(0);" class="btn-view mb-0 addToCartP" data-pid="<?php echo $value['productid']; ?>" data-pimg="<?php echo $pimg; ?>" data-price="<?php echo $price; ?>" data-pname="<?php echo $value['product_name']; ?>">
                                                <img src="<?php echo base_url(); ?>assets/user/img/addcart.webp" class="img-fluid" alt="product view">
                                            </a>
                                        </div>
                                    </div>
                                    <div class="btn-wrap">
                                        <a href="<?php echo base_url('shop-detail/'.strtolower($value['product_slug']).'/'.$value['productid']); ?>">
                                            <div class="btn btn-primary-outline mb-0">
                                                <span> View Product
                                                    <img src="<?php echo base_url(); ?>assets/user/img/Aerrow-t.webp" class="img ms-2" width="14" alt="right">
                                                </span>
                                            </div>
                                        </a>
                                    </div>
                                </div>
                                <div class="product-inner">
                                    <a href="<?php echo base_url('shop-detail/'.strtolower($value['product_slug']).'/'.$value['productid']); ?>">
                                        <p class="product-title" style="min-height:30px;"><?php echo substr($value['product_name'], 0,40); ?><?php echo(strlen($value['product_name'])>40)?'...':''; ?></p>
                                        <p class="price">
                                            <?php if($value['product_sale_price']>0){ ?>
                                                <del>$<?php echo $value['product_price']; ?></del> &nbsp;
                                                $<?php echo $value['product_sale_price']; ?> 
                                            <?php }else{ ?>
                                                $<?php echo $value['product_price']; ?>
                                            <?php } ?>
                                        </p>
                                    </a>
                                </div>
                            </div>
                        </div>
                    <?php } }else{ ?>
                        <div class="col-md-12">
                           <h1 class="text-center"><strong>No products found...</strong></h1>
                        </div>
                    <?php } ?>
                </div>

                <div class="text-center">
                    <nav aria-label="Page navigation example">
                        <!-- <ul class="pagination justify-content-center mt-md-5 mt-4 mb-4">
                            <li class="page-item"><a class="page-link active" href="#">1</a></li>
                            <li class="page-item"><a class="page-link" href="#">2</a></li>
                            <li class="page-item"><a class="page-link" href="#">3</a></li>
                            <li class="page-item"><a class="page-link" href="#">4</a></li>
                        </ul> -->
                        <?php echo $this->pagination->create_links(); ?>
                    </nav>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- produt end -->
<script>
    $('.changeFilter').on('click', function () {
        $('#filterForm').submit();
    });
</script>