<?php include 'includes/header.php';?>

<?php 
if($_SESSION['okeysepet']==1){
  echo "<script>
  const Toast = Swal.mixin({
    toast: true,
    position: 'top-end',
    showConfirmButton: false,
    timer: 6000,
    timerProgressBar: true,
    didOpen: (toast) => {
      toast.addEventListener('mouseenter', Swal.stopTimer)
      toast.addEventListener('mouseleave', Swal.resumeTimer)
    }
    })

    Toast.fire({
      icon: 'success',
      title: 'Sepete Eklendi.'
      })
      </script>";
    }

    unset($_SESSION['okeysepet']);



    $urun  =   $dbh->prepare("SELECT * FROM product where seo_name=? ");
    $urun  -> execute(array($_GET['id']));
    $urun  =   $urun  -> fetch(PDO::FETCH_ASSOC);


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



    if(!$urun){
      header("location:index.php");
      exit();
    }
    ?>

    <title><?=$urun->page_title?></title>
    <meta name="description" content="<?=$urun->page_description?>>">
    <meta name="keywords" content="<?=$urun->page_keywords?>">
    <meta name="author" content="ParsTech">


    <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">
            <a class="back-link" href="javascript:history.back(-1)"><i class="zmdi zmdi-arrow-left"></i><?php echo $dil['107'];?></a>
           
          </div>

          <div class="product_details">
            <div class="product_detail_title"><?=$urun->product_name?></div>
            <div class="product_img_gallery">
              <div class="proudct_detail_price"><?=$urun->product_price?> TL</div>
              <div class="owl-carousel owl-theme" id="product_img_gallery">
                <div class="item">
                  <img src="img/<?=$urun->foto?>" class="crop_img">
                </div>

                <?php 

                $urunres  =   $dbh->prepare("SELECT * FROM product_gallery where select_category=? ");
                $urunres  -> execute(array($urun->id));
                $urunres  =   $urunres  -> fetchAll(PDO::FETCH_OBJ);

                foreach ($urunres as $resim) { ?>

                  <div class="item">
                    <img src="img/<?=$resim->foto?>" class="crop_img">
                  </div>
                <?php }?>

              </div>
            </div>
            <form action="sepet.php" method="post" id="product_addtocart_form">
              <input type="hidden" name="tip" value="ekle">
              <input type="hidden"  id="urunid"  name="urunid" value="<?= $urun->id; ?>">

              <div class="cart_section_title"><?php echo $dil['108'];?></div>
              <div class="col-lg-12 urun_tabs">
                <!-- Nav tabs -->
                <ul class="nav nav-pills nav-justified" role="tablist">
                  <li class="nav-item waves-effect waves-light">
                    <a class="nav-link active" data-toggle="tab" href="#home-1" role="tab" aria-selected="true"><?php echo $dil['109'];?></a>
                  </li>
                  <li class="nav-item waves-effect waves-light">
                    <a class="nav-link" data-toggle="tab" href="#profile-1" role="tab" aria-selected="false"><?php echo $dil['110'];?></a>
                  </li>
                </ul>

                <!-- Tab panes -->
                <div class="tab-content">
                  <div class="tab-pane p-3 active" id="home-1" role="tabpanel">
                    <?=$urun->product_description?>
                  </div>
                  <div class="tab-pane p-3" id="profile-1" role="tabpanel">
                    <?php 
                    $alerji_bol=json_decode($urun->product_allergy);
                    foreach ($alerji_bol as  $say => $alerj) {

                     $alerji = $dbh -> prepare("SELECT * FROM allergy WHERE id = ?");
                     $alerji -> execute(array($alerj));

                     $row = $alerji -> fetch();
                     if ($alerji->rowCount() > 0) :
                      $row = cevir("allergy",$row,$_SESSION["dil"]);  
                      ?>     
                      <p><?= $row['title']; ?>,</p>

                      <?php
                    endif;
                  }

                  if(count($alerji_bol)==0){

                    echo '<div class="alert alert-warning mb-12" role="alert">
                    ' . $dil['177'] . '
                    </div>';
                  }

                  ?>
                </div> 
              </div>      
            </div><!--end col-->

            <br>
            <div class="cart_section_title"><?php echo $dil['111'];?></div>

            <div class="product_detail_quantity text-center mb-6">
              <h3><?php echo $dil['112'];?></h3>
              <div class="input-group mt-2 text-center increasenumber">
                <div class="input-group-prepend ">
                  <button class="btn btn-sm btn-outline-default px-3 remove"  onclick="azalt();" type="button">-</button>
                </div>
                <input type="number" name="qty" class="form-control form-control-sm text-center w-50px" id="qty" placeholder="" min="1"  value="1">
                <div class="input-group-append">
                  <button class="btn btn-sm btn-outline-default px-3 add" onclick="arttir();" type="button">+</button>
                </div>
              </div>
            </div>
            <style type="text/css">
              option{
                color: black;
              }
            </style>
            <?php 
            $porslar=json_decode($urun->product_portion);
            $porsf=json_decode($urun->product_portion_price);
            if(count($porslar)>0){
              ?>
              <div class="form-group w-fullx sm:w-fullx md:w-1/2 lg:w-1/2 xl:w-1/2 mb-4">
                <label><?php echo $dil['113'];?>:</label>
                <select class="form-control w-full" name="menu_porsiyon">
                 <option value=""><?php echo $dil['114'];?></option>

                 <?php 


                 foreach ($porslar as  $say => $pors) {

                   $porsd  =   $dbh->prepare("SELECT * FROM product_portion where id=? ");
                   $porsd  -> execute(array($pors));
                   $porsd  =   $porsd  -> fetch(PDO::FETCH_ASSOC);


                   $porsd = cevir("product_portion",$porsd,$_SESSION["dil"]);
                   $porsd = (object) $porsd;


                   ?>
                   <option value="<?=$porsd->id?>"><?=$porsd->portion?> + <?=$porsf[$say]?> TL</option>
                 <?php }?>

               </select>
             </div>
           <?php } ?>
           <?php 


           $ekstra=json_decode($urun->product_optionek);
           $ekstraf=json_decode($urun->product_optionek_price);
           if(count($ekstra)>0){
             ?>
             <div class="form-group w-fullx sm:w-fullx md:w-1/2 lg:w-1/2 xl:w-1/2 mb-4">
              <label><?php echo $dil['115'];?>:</label>
              <div class="row mt-4">

                <?php


                foreach ($ekstra as  $say => $eks) {

                 $ek  =   $dbh->prepare("SELECT * FROM selectable where id=? ");
                 $ek  -> execute(array($eks));
                 $ek  =   $ek  -> fetch(PDO::FETCH_ASSOC);

                 $ek = cevir("selectable",$ek,$_SESSION["dil"]);
                 $ek = (object) $ek;

                 ?>
                 <div class="form-group_child col-xs-6 mb-4">
                  <input type="checkbox" class="custom-control-input" <?php if($ekstraf[$say]==0){ echo "checked"; }?> name="ekstra[]" id="customCheck<?=$say?>" value="<?=$eks?>">
                  <label class="custom-control-label" for="customCheck<?=$say?>"><?=$ek->option?> <?php if($ekstraf[$say]>0){echo "+".$ekstraf[$say]." TL" ;} ?></label>
                </div>
              <?php } ?>

            </div>
            <div class="alert alert-warning " role="alert">
             <?php echo $dil['116'];?>
           </div>
         </div>
       <?php } ?>
       <div class="form-group w-fullx sm:w-fullx md:w-1/2 lg:w-1/2 xl:w-1/2 mb-4">
        <label><?php echo $dil['117'];?></label>
        <textarea name="icerik" id="icerik" class="form_control required w-full"    rows="" cols=""></textarea>
      </div>
      <div class="form-group text-center w-fullx sm:w-fullx md:w-1/2 lg:w-1/2 xl:w-1/2 mb-4">
        <button class="btn-success  m-auto rounded-3xl d-block py-2 px-5" type="submit" id="addmore"><i class="zmdi zmdi-plus"></i><?php echo $dil['118'];?></button>
      </div>
    </form>

  </div>

  <!-- Food Item Section End -->
</div>
<?php include 'includes/modal.php';?> 
<?php include 'includes/footer.php';?>

<script type="text/javascript">
  function arttir() {
    var deger= $('#qty').val();
    deger++;
    $('#qty').val(deger);

  }

  function azalt() {
    var deger= $('#qty').val();
    if(deger>1){
     deger--;
     $('#qty').val(deger);
   }
 }
</script>