<?php include_once dirname(__FILE__) . '/functions/functions.php';?>

<?php $this->load->view('adv/category_adv1', array('adv_position' => 1));?>

<div class="container py-4">
    <div class="row">
        <!-- <div class="<?php echo (!empty($after_search) ? 'col-md-3' : 'col-md-3') ?> d-none d-lg-block leftSidebar mb-3 pr-xl-4">



            <?php $this->load->view('adv/category_adv2', array('adv_position' => 3));?>


        </div> -->

        <!-- added search row -->
        <div class="col-12 text-center mb-2">
             <div class="col-0 col-md-3">
             </div>
             <div class="d-inline-block main-search input-group-overlay col-11 col-md-6 mx-4 ui-widget">
                <?php echo form_open('category_product_search', array('method' => 'GET')) ?>
                <div >
                    <div class="input-group-prepend-overlay">
                        <span class="input-group-text"><i data-feather="search"></i></span>
                    </div>
                    <input class="form-control search-input prepended-form-control appended-form-control"  name="product_name" id="search_product_item" type="text" placeholder="<?php echo display('search_for_product'); ?>" />
                    <div class="input-group-append-overlay">
                        <button type="submit" class="btn btn-warning search_btn color4 color46 text-white"><span class="lnr
                        lnr-magnifier"></span><?php echo display('search'); ?>
                        </button>
                    </div>
                </div>
                 <?php echo form_close() ?>
            </div>
            <div class="col-0 col-md-3">
            </div>
        </div>
        <!-- end added search row -->


        <div class="<?php echo (!empty($after_search) ? 'col-12' : 'col-12') ?> mainContent category-content">




            <div class="filter-row d-flex align-items-center justify-content-between mb-2">
                <div class="filter-title">
                    <?php if (!empty($after_search) && !empty($keyword)) {
	?>
                        <h1 class="fs-21 mb-0 d-inline-block">
                            <?php echo html_escape($total) . " " . display('search_items') . '"' . $keyword . '"';
	?>
                    </h1>
                    <?php } elseif (empty($after_search)) {?>
                    <h1 class="fs-21 mb-0 d-inline-block"><?php echo html_escape($category_name); ?></h1>
                    <span class="text-black-50">- <?php echo html_escape($total); ?> <?php echo display('items') ?></span>
                    <?php }?>
                </div>

              <!--   <a class="btn btn-warning color4 color46 text-white" href="<?php echo base_url() ?>"><i class="far fa-hand-point-left"></i> <?php echo display('back_to_home') ?></a> -->
            </div>
            <div class="row">
                <?php
if (!empty($category_product)) {
	foreach ($category_product as $product) {
		?>

                <div class="col-6 col-sm-3 col-md-3 col-lg-3 col-xl-3 px-md-2 px-1">
                    <div class="feature-card card mb-3" style="border-radius: 15px;position: relative;">

                        <!-- onsale image -->
                          <?php if ($product->onsale == 1 && !empty($product->onsale_price)) {
			?>
                        <div class="" style="position: absolute;z-index: 2;">
                             <?php
if ($this->session->userdata('language') == "english") {
				?>
                            <img src="<?php echo base_url("my-assets/image/product/sale_image/sale.png"); ?>">

                             <?php
}
			if ($this->session->userdata('language') == "chinese") {
				?>
                <img src="<?php echo base_url("my-assets/image/product/sale_image/sale_ch.png"); ?>">
        <?php
}
			if ($this->session->userdata('language') == "indonesian") {
				?>
                 <img src="<?php echo base_url("my-assets/image/product/sale_image/sale.png"); ?>">
        <?php
}

			?>

                </div>
                        <?php
} // if ($product->onsale == 1 && !empty($product->onsale_price)) {
		?>

                        <!-- end onsale image -->

                        <div class="card-body text-center">
                            <a href="<?php echo base_url('product/' . remove_space($product->product_name) . '/' . $product->product_id) ?>" class="product-img d-block">
                                <?php if (@getimagesize($product->image_thumb) === false) {?>
                                <img src="<?php echo base_url() . '/my-assets/image/no-image.jpg' ?>" class="media-object img-fluid"
                                     alt="<?php echo html_escape($product->product_name) ?>">
                                <?php } else {?>
                                    <img class="img-fluid" src="<?php echo base_url() . $product->image_thumb ?>" alt="<?php echo html_escape($product->product_name) ?>">
                                <?php }?>
                            </a>
                            <h3 class="product-name fs-15 font-weight-600 overflow-hidden mt-2">
                                <a href="<?php echo base_url('product/' . remove_space($product->product_name) . '/' . $product->product_id) ?>" class="text-black">
                                    <?php
if ($this->session->userdata('language') == "english") {
			echo html_escape($product->product_name);
		}
		if ($this->session->userdata('language') == "chinese") {
			echo html_escape($product->product_name_ch);
		}
		if ($this->session->userdata('language') == "indonesian") {
			echo html_escape($product->product_name_in);
		}

		?>


                                </a>
                            </h3>
                            <!-- <div class="star-rating"> -->
                                <?php
// $result = $this->db->select('IFNULL(SUM(rate),0) as t_rates, count(rate) as t_reviewer')
		// 			->from('product_review')
		// 			->where('product_id', $product->product_id)
		// 			->where('status', 1)
		// 			->get()
		// 			->row();
		// 		$p_review = (!empty($result->t_reviewer) ? $result->t_rates / $result->t_reviewer : 0);
		// 		for ($s = 1; $s <= 5; $s++) {

// 			if ($s <= floor($p_review)) {
		// 				echo '<i class="fas fa-star"></i>';
		// 			} else if ($s == ceil($p_review)) {
		// 				echo '<i class="fas fa-star-half-alt"></i>';
		// 			} else {
		// 				echo '<i class="far fa-star"></i>';
		// 			}
		// 		}
		?>
                            <!-- </div> -->
                            <!-- new price row -->
                            <div class="product-price text-center">
                            <?php if ($product->onsale == 1 && !empty($product->onsale_price)) {
			?>
                                    <!-- <del class="Price-discount fs-14 text-black-50 font-weight-600 pl-1 price_discount"> -->
                            <span class="amount regular_price strikediag categoryonsaleprice">
                                <?php echo (($position1 == 0) ? $currency1 . " " . number_format($product->price, 2, '.', ',') : number_format($product->price, 2, '.', ',') . " " . $currency1); ?>
                            </span>
                        <!-- </del> -->
                                    <!-- <ins class="fs-29 d-inline-block"> -->
                                        <span class="amount var_amount categoryprice">
                                            <?php

			if ($target_con_rate > 1) {
				$onsale_price = $product->onsale_price * $target_con_rate;
				echo (($position1 == 0) ? $currency1 . " " . number_format($onsale_price, 2, '.', ',') : number_format($onsale_price, 2, '.', ',') . " " . $currency1);
			}

			if ($target_con_rate <= 1) {
				$onsale_price = $product->onsale_price * $target_con_rate;
				echo (($position1 == 0) ? $currency1 . " " . number_format($onsale_price, 2, '.', ',') : number_format($onsale_price, 2, '.', ',') . " " . $currency1);
			}
			?>

                                    </span>
                                <!-- </ins> -->


                            <?php
} //if($product->onsale==1 && !empty($product->onsale_price)){
		else {
//not onsale
			?>
            <span class="amount var_amount categoryprice">
              <?php
if ($target_con_rate > 1) {
				$price = $product->price * $target_con_rate;
				echo (($position1 == 0) ? $currency1 . " " . number_format($product->price, 2, '.', ',') : number_format($product->price, 2, '.', ',') . " " . $currency1);
			}

			if ($target_con_rate <= 1) {
				$price = $product->price * $target_con_rate;
				echo (($position1 == 0) ? $currency1 . " " . number_format($price, 2, '.', ',') : number_format($price, 2, '.', ',') . " " . $currency1);
			}
			?>
    <?php
} //end not onsale
		?>
                                </span>
                            </div>
                            <!-- end new price row -->
                           <!--  <div class="product-price font-weight-bolder font-italic">
                            <?php

		if ($product->onsale == 1 && !empty($product->onsale_price)) {
			$price_val = $product->onsale_price * $target_con_rate;
		} else {
			$price_val = $product->price * $target_con_rate;
		}

		echo (($position1 == 0) ? $currency1 . number_format($price_val, 2, '.', ',') : number_format($price_val, 2, '.', ',') . $currency1);?> / <?php echo display('unit') ?></div> -->
                        </div>
                         <!-- added footer -->
                            <!-- <div className="card-footer border-0 rounded-bottom" style="background-color: #41e0fe;border-radius: 25px;">
            <small className="text-muted">Intermediate</small>
          </div> -->
                            <a href="<?php echo base_url('product/' . remove_space($product->product_name) . '/' . $product->product_id) ?>" class="text-black">
                            <!-- <div className="mt-auto col-12 " style="background-color: #41e0fe;border-bottom-left-radius: 15px;border-bottom-right-radius: 15px;"> -->
                            <div className="mt-auto col-12 " style="background-color: <?php echo $product->color; ?>;border-bottom-left-radius: 15px;border-bottom-right-radius: 15px;">
                            <p class="my-0 py-md-2 py-3 text-center categorytext"> <?php
if ($this->session->userdata('language') == "english") {
			echo html_escape("Quick View");
		}
		if ($this->session->userdata('language') == "chinese") {
			echo html_escape("快速查看");
		}
		if ($this->session->userdata('language') == "indonesian") {
			echo html_escape("Quick View");
		}

		?></p>
                            </div>
                            </a>
                            <!-- end added footer -->
                    </div>
                </div>
            <?php }} elseif (!empty($keyword)) {?>
                <div class="col-md-12 text-center">
                    <h3 class='text-muted mt-3'><?php echo display('category_product_not_found'); ?></h3>
                <?php }?>
                </div>
                <div class="pt-2">
                    <!-- Pagination-->
                    <div class="pagination d-flex align-items-center">
                        <div class="column">
                            <?php echo htmlspecialchars_decode($links); ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $this->load->view('adv/category_adv1', array('adv_position' => 2));?>

<!-- End OF category Mobile -->
<input type="hidden" name="category_id" id="category_id" value="<?php echo html_escape($category_id) ?>">
<input type="hidden" name="query_string" id="query_string" value="<?php echo $this->input->server('QUERY_STRING'); ?>">
<input type="hidden" name="brand_url_ids" id="brand_url_ids" value="<?php echo $this->input->get('brand') ?>">
</div>
<input type="hidden" name="price_min_value" id="price_min_value" value="<?php echo html_escape($min_value) ?>">
<input type="hidden" name="price_max_value" id="price_max_value" value="<?php echo (!empty($max_value) ? html_escape($max_value) : 10000) ?>">
<input type="hidden" name="from_price" id="from_price" value="<?php echo html_escape($from_price) ?>">
<input type="hidden" name="to_price" id="to_price" value="<?php echo html_escape($to_price) ?>">
<input type="hidden" name="default_currency_icon" id="default_currency_icon" value="<?php echo (!empty($default_currency_icon) ? html_escape($default_currency_icon) : $currency1) ?>">
