<main>
    <script>
    window.addEventListener('load', (event) => {
        setTimeout(function() {
            $("#fiyyat").removeClass("active");
        }, 200);
    });
    </script>
    <!-- Trending Products Start -->
    <section id="product" <?php if(json_decode(settings("renk"))->urun=="normal"){ echo ' class="not_slider"'; } ?>>
        <div class="container">
            <div class="title">
                <h2>
                    <svg width="15" height="1" viewBox="0 0 15 1" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <line y1="0.5" x2="15" y2="0.5" stroke="#2E4468" />
                    </svg>
                    <?php echo explode("~",$sayfa["Fiyatlandırma Başlık Bölüm"])[0];?>
                </h2>
                <p><?php echo explode("~",$sayfa["Fiyatlandırma Başlık Bölüm"])[1];?></p>
            </div>
            <div class="row">
                <div class="col-lg-3">
                    <div class="card-body catbody">
                    <div class="card">
                    <a class="menukate <?php if($page=="kategori" || $page=="urunler"){ echo "active"; } ?>" href="/urunler">Tüm Ürünler</a>
                    </div>
                    
                        <?php 				$query =  $db->query("SELECT * FROM kategori ORDER BY id DESC");; 
                                                        while ($data = $query->fetch(PDO::FETCH_OBJ)) {
                   ?>
                    <div class="card" style="border-radius:0px !important;">
                        <a href="<?=$site.settings("kategori_url");?>/<?=$data->url;?>" class="menukate">
                            <div class="card-body">
                                <?php echo $data->ad; ?>
                            </div>
                        </a>
                    </div>
                    <?php } ?>
                    </div>
                </div>
       
            <div class="col-lg-9 mb-4 mb-xl-0 mb-lg-0">
                <div
                    class="product_box  <?php if(json_decode(settings("renk"))->urun=="slider"){ echo ' row" '; } else{ echo ' row"';} ?>">
                    <?php 					 $query = $db->query("SELECT * FROM urun ORDER BY sira ASC");
					
$urunlerkategori=moduller("urunlerkategori");
                        while ($data = $query->fetch(PDO::FETCH_OBJ)) {
                            if($data->url==Null){
                                $data->url=$data->id;
                            }
							if($urunlerkategori["durum"]=="1"){ 
								$kat =  $db->query("SELECT * FROM kategori where id='".$data->kate."' ORDER BY id DESC");; 
                                $kat = $kat->fetch(PDO::FETCH_OBJ);
								$data->kate_ad=$kat->ad;
							}
                        ?>
                    <div
                        class="product <?php if(json_decode(settings("renk"))->urun=="slider"){ echo ' col-sm-6 col-lg-6 col-xl-4" '; } else{ echo 'col-sm-6 col-lg-6 col-xl-4"';} ?>">
                        <div class="product-card">
                            <div class="product-img">
                            <?php if($data->durum=="0"){
                                echo '
                                <a >
                                    <img class="lazy" width="285" height="200"
                                        src="'.$site.'upload/urun/'.$data->resim.'"
                                        data-src="'.$site.'upload/urun/'.$data->resim.'" alt="">
                                </a>
                                ';
                                }
                                else { ?>  
                                 <?php if($urunsayfa["durum"]=="1"){  
?>
                                   <a href="<?=$site.settings("urun_url");?>/<?=$data->url;?>">
<?php } else{ ?>
                                <a href="#" data-toggle="modal" data-target="#product<?php echo $data->id;?>">
<?php } ?>
                                    <img class="lazy" width="285" height="200"
                                        src="<?=$site;?>upload/urun/<?php echo $data->resim;?>"
                                        data-src="<?=$site;?>upload/urun/<?php echo $data->resim;?>" alt="">
                                </a>
                                <?php } ?>
                                <?php if($data->indirim!=Null){ ?> <div class="discount">
                                    <?php echo $data->indirim; ?>%
                                </div><?php } ?>
                            </div>
                            <div class="product_body">
                                <div class="product-caption">
                                    <div class="card-tag">
                                    <?php if($data->durum=="0"){
                                    echo '
                                    <a>'.$data->kate_ad.'</a>';
                                    }
                                    else { ?>    
                                 <?php if($urunsayfa["durum"]=="1"){  
?>
                                   <a href="<?=$site.settings("urun_url");?>/<?=$data->url;?>">
<?php } else{ ?>
                                <a href="#" data-toggle="modal" data-target="#product<?php echo $data->id;?>">
<?php } ?><?php echo $data->kate_ad;?></a>
                                    <?php } ?>
                                      <!--  <a href="#" data-toggle="modal"
                                            data-target="#product<?php echo $data->id;?>"><?php echo $data->kate_ad;?></a>-->
                                    </div>
                                    <div class="product-title">
                                    <?php if($data->durum=="0"){
                                        echo '
                                        <a>'.$data->ad.'</a>';
                                        }
                                        else { ?>  
                                 <?php if($urunsayfa["durum"]=="1"){  
?>
                                   <a href="<?=$site.settings("urun_url");?>/<?=$data->url;?>">
<?php } else{ ?>
                                <a href="#" data-toggle="modal" data-target="#product<?php echo $data->id;?>">
<?php } ?>
                                            <?php echo $data->ad;?>
                                        </a>
                                        <?php } ?>
                                       <!-- <a href="#" data-toggle="modal" data-target="#product<?php echo $data->id;?>">
                                            <?php echo $data->ad;?>
                                        </a>-->
                                    </div>
                                </div>
                                <div class="price-box">
                                    <div class="price_inner">
                                        <div class="d-flex flex-column price">
                                            <?php if($data->fiyat_indirim!=Null){ ?> <span
                                                class="old-price"><del><?php echo $data->fiyat;?> TL</del></span>
                                            <span class="new-price"><?php echo $data->fiyat_indirim;?> TL</span>
                                            <?php } else{ ?><span class="old-price" style="display: none;">&nbsp;</span>
                                            <span class="new-price"><?php echo $data->fiyat;?> TL</span>
                                            <?php } ?>
                                        </div>
                                        <div class="product-rating d-flex flex-column">
                                            <span>5 YILDIZ</span>
                                            <div class="star">
                                                <i class="star">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                                        fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
                                                        <path
                                                            d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                                                    </svg>
                                                </i>
                                                <i class="star">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                                        fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
                                                        <path
                                                            d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                                                    </svg>
                                                </i>
                                                <i class="star">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                                        fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
                                                        <path
                                                            d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                                                    </svg>
                                                </i>
                                                <i class="star">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                                        fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
                                                        <path
                                                            d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                                                    </svg>
                                                </i>
                                                <i class="star">
                                                    <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16"
                                                        fill="currentColor" class="bi bi-star-fill" viewBox="0 0 16 16">
                                                        <path
                                                            d="M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z" />
                                                    </svg>
                                                </i>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="buying_button">
                                           <?php if($urunsayfa["durum"]=="1"){  
?>
                                   <a href="<?=$site.settings("urun_url");?>/<?=$data->url;?>"> <button type="button">ŞİMDİ SATIN AL </button></a>
<?php
} else{ if($data->durum=="0"){ 
echo '
<button type="button" style="background: var(--bg_1);">TÜKENDİ </button>';
}
else { ?>
 <button type="button" data-toggle="modal" data-target="#product<?php echo $data->id;?>">ŞİMDİ SATIN AL </button>
<?php } } ?>
                                        
                                        <!-- <button type="button" data-toggle="modal"
                                                data-target="#product<?php echo $data->id;?>">ŞİMDİ
                                                SATIN AL </button>-->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php
                        } ?>
                </div>
                <?php $query = urunler();
                    while ($data = $query->fetch(PDO::FETCH_OBJ)) {
                    ?>
                <div class="modal fade product_view" id="product<?php echo $data->id;?>" role="dialog">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <i aria-hidden="true" class="ri-close-line"></i>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="modal-inner d-flex">
                                    <div class="product_inner">
                                        <?php
                                                $img=json_decode($data->resimler,true);
                                                $say=0;
                                                while(isset($img[$say])){
                                                    echo '<img width="395" height="500" src="'.$site.'upload/urunler/'.$img[$say].'">';
                                                    $say++;
                                                }
                                                ?>
                                    </div>
                                    <div class="product_content">
                                        <h4 class="product_name"><?php echo $data->ad;?></h4>
                                        <div
                                            class="price_box d-flex align-items-center justify-content-between flex-wrap">
                                            <h3 class="price">
                                                <?php if($data->fiyat_indirim!=Null){ ?> <span
                                                    class="old-price"><del><?php echo $data->fiyat;?> TL</del></span>
                                                <span class="new-price"><?php echo $data->fiyat_indirim;?> TL</span>
                                                <?php } else{ ?>
                                                <span class="new-price"><?php echo $data->fiyat;?> TL</span>
                                                <?php } ?>
                                            </h3>
                                            <div class="star">
                                                <i class="ri-star-fill"></i>
                                                <i class="ri-star-fill"></i>
                                                <i class="ri-star-fill"></i>
                                                <i class="ri-star-fill"></i>
                                                <i class="ri-star-fill"></i>
                                            </div>
                                        </div>
                                        <?php if(!strstr(html_entity_decode($data->aciklama), "<p"))
                                            {  ?>
                                        <p class="product_info">
                                            <?php } ?>
                                            <?php echo str_replace("<p", '<p class="product_info" ',html_entity_decode($data->aciklama));?>
                                            <?php if(!strstr(html_entity_decode($data->aciklama), "<p"))
                                            {  ?> </p><?php } ?>
                                        <form method="post" action="<?php echo $site.settings("sepet_url");?>">
                                            <?php 	$liste=array();				 $opt = opsiyonlar($data->id);
                                                        while ($opsiyon = $opt->fetch(PDO::FETCH_OBJ)) {
                                                                if (in_array($opsiyon->id,$liste)){
                                                                continue;
                                                            }
                                                            array_push($liste,$opsiyon->id);
                                                        ?>
                                            <div id="selector" class="body-swatch">
                                                <select name="opsiyon[]" class="selectpicker" data-width="100%">
                                                    <option value=""><?php echo $opsiyon->ad;?>: İstemiyorum</option>
                                                    <option value="<?php echo $opsiyon->id; ?>">
                                                        <?php echo $opsiyon->secenek; ?>
                                                        (<?php echo $opsiyon->fiyat; ?>TL)</option>
                                                    <?php 					 $opta = opsiyonlar($data->id);
                                                                        while ($ops = $opta->fetch(PDO::FETCH_OBJ)) {
                                                                            if (in_array($ops->id,$liste)){
                                                                                continue;
                                                                            }
                                                                            if($ops->ad!=$opsiyon->ad){
                                                                                continue;
                                                                            }
                                                                            array_push($liste,$ops->id);
                                                                        ?>
                                                    <option value="<?php echo $ops->id; ?>">
                                                        <?php echo $ops->secenek; ?>
                                                        (<?php echo $ops->fiyat; ?>TL)</option>
                                                    <?php } ?>
                                                </select>
                                                <i class="ri-arrow-down-s-line"></i>
                                            </div>
                                            <?php  ?>
                                            <?php } ?>
                                            <div class="content_bottom d-flex flex-column">
                                            <?php  if($data->urun_stok!=Null && $data->urun_stok<=0){ 
                                echo '<div class="alert alert-danger">Stok bulunamadı</div>';
                                }  elseif($data->durum=="0"){ 
                                            echo '<div class="alert alert-danger">Stok bulunamadı</div>';
                                            } else{?>
                                                <div class="btn-group">
                                                    <div class="quantity-box">
                                                        <span class="input-number-decrement">–</span>
                                                        <input class="input-number" type="number" value="1" name="adet"
                                                            min="1"  <?php if($data->urun_stok!=Null){ ?>max="<?=$data->urun_stok;?>"<?php } ?>>
                                                        <span class="input-number-increment">+</span>
                                                    </div>
                                                    <div class="btn-ground">
                                                        <button type="submit" name="product"
                                                            value="<?php echo $data->id;?>">
                                                            <i class="ri-shopping-cart-line"></i>
                                                            Şimdi Satın Al
                                                        </button>
                                                    </div>
                                                </div>
                                                <?php $eklenti=eklenti("whatsappsatinal");
                                                                if($eklenti["durum"]=="1"){
                                                                $json=json_decode($eklenti["deger"],true);
                                                                ?>
                                                <a href="<?php echo $json["Whatsapp Linki"];?>" target="_blank">
                                                    <div class="wpbtn">
                                                        <button type="button">
                                                            <i class="ri-whatsapp-line"></i> WhatsApp ile Satın Al
                                                        </button>
                                                    </div>
                                                </a>
                                                <?php } ?>
                                                <?php } ?>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <?php } ?>
            </div>
        </div>
        </div>
    </section>
    <!-- Trending Products End -->
    <div class="modal product-modal fade" id="loadimg">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body d-flex align-items-center">
                    <img src="" id="imgs" style="width:100%;">
                </div>
            </div>
        </div>
    </div>
    <!-- Instagram Post Start -->
    <?php if(@$_GET["i"]=="bas"){
	?>
    <script>
    Swal.fire({
        icon: 'success',
        title: 'Talebiniz Gönderildi',
        text: 'Talebiniz en kısa sürede incelenip, yetkili yanıtı mailinize gönderilecektir.',
        confirmButtonText: '<i class="fa fa-thumbs-up"></i> Tamam'
    })
    </script>
    <?php
}
?>
    <?php if(@$_GET["banka"]=="bas"){
	?>
    <script>
    Swal.fire({
        icon: 'success',
        title: 'Ödeme Bildirildi',
        text: 'Ödeme bildiriminiz onaylandıktan sonra ürününüz teslim edilecektir.',
        confirmButtonText: '<i class="fa fa-thumbs-up"></i> Tamam'
    })
    </script>
    <?php
}
?>
    <?php if(@$_GET["sip"]=="0"){
	?>
    <script>
    Swal.fire({
        icon: 'error',
        title: 'Ödeme Başarısız',
        text: 'Ödeme işlemi başarısız oldu. Lütfen tekrar deneyiniz.',
        confirmButtonText: '<i class="fa fa-thumbs-up"></i> Tamam'
    })
    </script>
    <?php
}
?>
    <?php if(@$_GET["sip"]=="1"){
	?>
    <script>
    Swal.fire({
        icon: 'success',
        title: 'Ödeme Başarılı',
        text: 'Ödeme başarıyla yapıldı. Sipariş detaylarına mailinizden ulaşabilirsiniz.',
        confirmButtonText: '<i class="fa fa-thumbs-up"></i> Tamam'
    })
    </script>
    <?php
}
?>