<?php include 'includes/header.php';?>
<title><?=$seo['menu_title'];?></title>
<meta name="description" content="<?=$seo['menu_description'];?>">
<meta name="keywords" content="<?=$seo['menu_keywords'];?>">
<meta name="author" content="ParsTech">
<?php
$i = 1;
?>
<body id="page_home" class="">
  <!-- Body Wrapper Start -->
  <div class="body_wrapper">

    <!-- Food Item Section Start -->
    <div class="item_section mt-4 mt-md-0">
      <div class="item_section_header">
        <div class="tab_btn_container">
          <div class="nav nav-pills" id="item_tab"  role="tablist">
            <?

            $kategoriler  =   $dbh->prepare("SELECT * FROM product_categories where parent IS NULL or parent=0  ");
            $kategoriler  -> execute(array());
            $kategoriler  =   $kategoriler  -> fetchAll(PDO::FETCH_ASSOC);
            foreach($kategoriler as $kategori):

              $kategori = cevir("product_categories",$kategori,$_SESSION["dil"]);
              $kategori = (object)$kategori;



              if($i == 1 && !$_GET['q']){$active_Class = "active";$active_Class2 = "true";}else{$active_Class = "";$active_Class2 = "false";}
              ?>
              <a class="nav-item nav-link <?=$active_Class?>" id="nav-product<?=$i?>" data-toggle="pill" href="#products<?=$i?>" role="tab" aria-controls="products<?=$i?>" aria-selected="<?=$active_Class2?>">
                <img src="img/<?=$kategori->img?>">
                <h5><?=$kategori->categories_name?></h5>
              </a>
              <? $i++; endforeach; ?>

              <a style="display: none" class="nav-item nav-link <?php if($_GET['q']){echo 'active';} ?>" id="nav-product99" data-toggle="pill" href="#products99" role="tab" aria-controls="products99" aria-selected="false">
                <img src="images/<?=$kategori->img?>">
                <h5><?=$kategori->categories_name?></h5>
              </a>
            </div>
          </div>

          <form class="search_box" action="">
            <div class="form-group d-flex">
              <div class="input-group-prepend">
                <div class="input-group-text"><i class="zmdi zmdi-search"></i></div>
              </div>
              <input type="search" name="q" class="form-control" placeholder="<?php echo $dil['054'];?>">
              <button type="submit" class="btn"><?php echo $dil['053'];?></button>
            </div>
          </form>
        </div>
        <div class="tab-content" id="item_tabContent" >
          <?
          $y = 1;

          $kategoriler  =   $dbh->prepare("SELECT * FROM product_categories where  parent IS NULL or parent=0  ");
          $kategoriler  -> execute(array());
          $kategoriler  =   $kategoriler  -> fetchAll(PDO::FETCH_ASSOC);
          foreach($kategoriler as $kategori2):

           $kategori2 = cevir("product_categories",$kategori2,$_SESSION["dil"]);
           $kategori2 = (object) $kategori2;

           $altkat  =   $dbh->prepare("SELECT * FROM product_categories where parent=? ");
           $altkat  -> execute(array($kategori2->id));
           $altkat  =   $altkat  -> fetchAll(PDO::FETCH_ASSOC);

           $urunler  =   $dbh->prepare("SELECT * FROM product where status=1 && parent=? ");
           $urunler  -> execute(array($kategori2->id));
           $urunler  =   $urunler  -> fetchAll(PDO::FETCH_ASSOC);


           if($y == 1  && !$_GET['q']){$active_Class = " show active";}else{$active_Class = "";}
           ?>
           <div class="tab-pane fade <?=$active_Class?>" id="products<?=$y?>" role="tabpanel" aria-labelledby="nav-product<?=$y?>">
            <div class="row product_items">

              <?php if($altkat){ ?>
                <?php   foreach ($altkat as $altt) { 

                  $altt = cevir("product_categories",$altt,$_SESSION["dil"]);
                  $altt = (object) $altt;

                  ?>
                  <div class="col-12 col-lg-6 col-xl-3 col-md-12 col-sm-6 ">
                    <div class="item" data-id="1" data-qty="0" data-title="Veg Cheese Burger" data-price="12.00">
                      <a href="kategori-<?=$altt->seo_name?>">
                        <div class="item_img center_img">
                          <img src="img/<?=$altt->foto?>" class="crop_img">
                        </div>
                        <div class="text_box" (click)="item_detail()">
                         <h2><?=$altt->categories_name?></h2>
                         <!--   <h3>₺12.00</h3> -->
                       </div>
                     </a>
                   </div>
                 </div>
               <?php } ?>



             <?php }else{ ?>
              <?php   foreach ($urunler as $urun) {

                $urun = cevir("product",$urun,$_SESSION["dil"]);
                $urun = (object) $urun;
                ?>
                <div class="col-12 col-lg-6 col-xl-3 col-md-12 col-sm-6 ">
                  <div class="item" data-id="1" data-qty="0" data-title="Veg Cheese Burger" data-price="12.00">
                    <a href="urun-<?=$urun->seo_name?>" >
                      <div class="item_img center_img">
                        <img src="img/<?=$urun->foto?>" class="crop_img">
                      </div>
                      <div class="text_box" (click)="item_detail()">
                        <h2><?=$urun->product_name?> <br><?=$kategorii->categories_name?></h2>
                        <h3>₺<?=$urun->product_price?></h3>
                      </div>
                    </a>
                  </div>
                </div>
              <?php }
            } ?>
            <?php if(count($urunler)==0 && count($altkat)==0){echo "Ürün Bulunamadı";} ?>
          </div>

        </div>
        <? $y++; endforeach;  ?>


        <?php if($_GET['q']){ 


          $urunlerr  =   $dbh->prepare("SELECT * FROM product where status=1 && product_name like ? ");
          $urunlerr  -> execute(array("%".$_GET['q']."%"));
          $urunlerr  =   $urunlerr  -> fetchAll(PDO::FETCH_ASSOC);

          ?>
          <div class="tab-pane fade show active" id="products99" role="tabpanel" aria-labelledby="nav-product99">
            <div class="row product_items">

              <?php if($urunlerr){ ?>

                <?php   foreach ($urunlerr as $urun) {  

                  $urun = cevir("product",$urun,$_SESSION["dil"]);
                  $urun = (object) $urun;

                  ?>
                  <div class="col-12 col-lg-6 col-xl-3 col-md-12 col-sm-6 ">
                    <div class="item" data-id="1" data-qty="0" data-title="Veg Cheese Burger" data-price="12.00">
                      <a href="urun-<?=$urun->seo_name?>" >
                        <div class="item_img center_img">
                          <img src="img/<?=$urun->foto?>" class="crop_img">
                        </div>
                        <div class="text_box" (click)="item_detail()">
                          <h2><?=$urun->product_name?> <br><?=$kategorii->categories_name?></h2>
                          <h3>₺<?=$urun->product_price?></h3>
                        </div>
                      </a>
                    </div>
                  </div>
                <?php } }  ?>
                <?php if(count($urunlerr)==0){echo '

                <div class="alert alert-warning mb-12" role="alert">
                ' . $dil['126'] . '
                </div> 


                ';} } ?>


              </div>
            </div>

            <?php include 'includes/modal.php';?>
            <?php include 'includes/footer.php';?>