<script type="text/javascript">
    
$(document).ready(function() {

var urloc = window.location.pathname;

console.log(urloc)

if(urloc == "/index.php" || urloc == "/"){
$("#index").addClass("active");
}else if(urloc == "/finder.php"){
$("#finder").addClass("active");
}else if(urloc == "/mesajlar.php"){
$("#mesajlar").addClass("active");
}else if(urloc == "/hesabim.php"){
$("#hesabim").addClass("active");
}


});

function yolland(){

Android.yapDene("deneme");

}

function menuGizle(){
    $("#sidebarPanel").modal('hide')
}


function iletisimGonder(){
     var aciklamasi = $('#iletisimAciklama').val();

    var url = "assets/api.php";
    var bilgi = {
      type: 'iletisimGonder',
      icerik: aciklamasi
    }
    $.post(url,bilgi,function(response) {
      var json = JSON.parse(response);

      if(json.result==1){



toastbox('toast-gonderildi', 5000)
     $("#sidebarPanel").modal('hide');
     $("#aramaDialog").modal("hide");
     var aciklamasi = $('#iletisimAciklama').val("");
}else{
   toastbox('toast-hata', 5000)
     $("#sidebarPanel").modal('hide');
     $("#aramaDialog").modal("hide"); 
}

   })

}


function bildirimAyar(){

    var url = "assets/api.php";
    var bilgi = {
      type: 'bildirimAyar',
      type2: $('#bildirimCheck').val()
    }
    $.post(url,bilgi,function(response) {
      var json = JSON.parse(response);

      if(json.result==0){

$('#bildirimCheck').prop('checked', false);
$('#ackapa').html("Kapalı");
$('#bildirimCheck').val(0);


      }else if(json.result==1){

$('#bildirimCheck').prop('checked', true);
$('#ackapa').html("Açık");
$('#bildirimCheck').val(1);

      }

})
}


function aramaizin(){

    var url = "assets/api.php";
    var bilgi = {
      type: 'aramaizin',
      type2: $('#aramaCheck').val()
    }
    $.post(url,bilgi,function(response) {
      var json = JSON.parse(response);

      if(json.result==0){

$('#aramaCheck').prop('checked', false);
$('#ackapa2').html("<font color='red'><b>Arayamasın</b></font>");
$('#aramaCheck').val(0);


      }else if(json.result==1){

$('#aramaCheck').prop('checked', true);
$('#ackapa2').html("<font color='green'><b>Arayabilsin</b></font>");
$('#aramaCheck').val(1);

      }

})
}


</script>

<?php 
$check = $db->query("SELECT COUNT(*) FROM mesajlar WHERE alan_id = '".$myUser['user_id']."' AND okundu = 0")->fetchColumn();
/*
if($check>=100){
    $check = "99+";
}*/

$check2 = $db->query("SELECT COUNT(*) FROM aramalar WHERE u_to = '".$myUser['user_id']."'")->fetchColumn();
?>

<style>

.fa-solid{
    color: #df247b !important;
}

.appBottomMenu .item .col {
    color: #df247b !important;
}

.appBottomMenu .item.active i.icon, .appBottomMenu .item.active .col, .appBottomMenu .item.active strong {
    color: #1E74FD !important;
}

.fa-2x {
    font-size: 2.5em !important;
}

</style>

    <!-- App Bottom Menu -->
<div class="appBottomMenu" id="altmenu">
                <a href="index.php" class="item" id="index">
                    <div class="col">
                        <i class="fa-solid fa-people-group fa-2x"></i>
                        <strong>Keşfet</strong>
                    </div>
                </a>
                <a href="finder.php" class="item" id="finder">
                    <div class="col">
                        <i class="fa-solid fa-heart-pulse fa-2x"></i>
                        <strong>Eşleş</strong>
                    </div>
                </a>
<?php if($user_id != 663793): ?> <!-- 663793 ID'li kullanıcı değilse göster -->
    <a href="javascript:void(0)" data-toggle="modal" data-target="#aramaListview" class="item">
        <div class="col">
            <i class="fa-solid fa-phone fa-2x"></i>
            <strong>Aramalar</strong>
            <span id="okunmamis2" class="badge badge-danger"><?=$check2?></span>
        </div>
    </a>
<?php endif; ?>

<?php $displayCount = ($myUser['user_id'] == 663793) ? 0 : $check; ?>
                <a href="mesajlar.php" class="item" id="mesajlar">
                    <div class="col">
                        <i class="fa-solid fa-envelope fa-2x"></i>
                        <strong>Mesajlar</strong>
                        <span id="okunmamis" class="badge badge-success"><?=$displayCount?></span>
                    </div>
                </a>
                <a href="hesabim.php" class="item" id="hesabim">
                    <div class="col">
                        <i class="fa-solid fa-user-group fa-2x"></i>
                        <strong>Hesabım</strong>
                    </div>
                </a>
            </div>
    <!-- * App Bottom Menu -->




        <!-- DialogIconedSuccess -->
        <div class="modal fade dialogbox" id="jetonAl" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-icon text-warning">
                       <i class="fa-solid fa-gem fa-xs"></i>
                    </div>
                    <div class="modal-header">
                        <h5 class="modal-title">Jetonun Bitti 🥲</h5>
                    </div>
                    <div class="modal-body">
                        Sohbete kaldığın yerden devam etmek için jeton satın alabilirsin.
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="javascript:void(0);" class="btn" data-toggle="modal" data-target="#jetonPaketleri" data-dismiss="modal">Paketleri İncele</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * DialogIconedSuccess -->

                <!-- DialogIconedSuccess -->
        <div class="modal fade dialogbox" id="bjetonAl" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-icon text-warning">
                        <i class="fa-solid fa-money-bill-wave fa-xs"></i>
                    </div>
                    <div class="modal-header">
                        <h5 class="modal-title">Günlük Beğeni Hakkın Bitti</h5>
                    </div>
                    <div class="modal-body">
                        Yeni arkadaşlıklar edinmeye devam edebilmek için hemen Jeton satın alın, hangi paketi alırsanız alın günlük beğeni hakkınız 50 adete yükselecektir.
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="javascript:void(0);" class="btn" data-toggle="modal" data-target="#jetonPaketleri" data-dismiss="modal">Paketleri İncele</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * DialogIconedSuccess -->



<!-- ARAMALARRRRRRRRRRRRRRRRRRRRRRRRRRRRR -->


<!-- DialogIconedSuccess -->
        <div class="modal fade dialogbox" id="DialogIconedSuccess2" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-icon text-danger">
                        <i class="fa-solid fa-triangle-exclamation fa-xs"></i>
                    </div>
                    <div class="modal-header">
                        <h5 class="modal-title">Arama Yapılamıyor</h5>
                    </div>
                    <div class="modal-body">
                    <b><c id="kfullname">Bu kullanıcı</c> sadece izin verdiği kişiler tarafından gelen sesli aramaları kabul ediyor.</b>
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="component-dialog.html#" class="btn" data-dismiss="modal">Tamam</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * DialogIconedSuccess -->    


    <!-- Modal Listview -->
<div class="modal fade modalbox" id="aramaListview" data-backdrop="static" tabindex="-1" role="dialog">
   <div class="modal-dialog" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <h5 class="modal-title">Arama Geçmişiniz</h5>
            <a href="javascript:;" data-dismiss="modal">Kapat</a>
         </div>

<?php 

$aramaizin = $myUser['user_aramaizin'];

if($aramaizin == 1){
    $val12 = "1";
    $chck2 = "checked";
    $ackapa2 = "<font color='green'><b>Arayabilsin</b></font>";
}else{
    $val12 = "0";
    $chck2 = "";
    $ackapa2 = "<font color='red'><b>Arayamasın</b></font>";
}

// Eğer user_call = 0 ise switch'i disabled yap
$disabled = ($myUser['user_call'] == 0) ? 'disabled' : '';
$disabledStyle = ($myUser['user_call'] == 0) ? 'style="opacity: 0.5; pointer-events: none;"' : '';
$clickEvent = ($myUser['user_call'] != 0) ? 'onclick="aramaizin();"' : '';

?>

            <ul class="listview image-listview flush">
<li>
                            <div class="item">
  <div class="in" <?=$clickEvent?> <?=$disabledStyle?>>
 <div>Kullanıcılar Beni <c id="ackapa2"><?=$ackapa2?></c></div>

                                    <div class="custom-control custom-switch">
                                        <input type="checkbox" class="custom-control-input"
                                            id="aramaCheck" value="<?=$val12?>" <?=$chck2?> <?=$disabled?>>
                                        <label class="custom-control-label"></label>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </ul>
             

         <div class="modal-body p-0" <?=$oncl2?>>
            <ul class="listview image-listview flush mb-2 mt-1">



<?php



if(isset($user_id)){

$query = $db->query("SELECT * FROM aramalar WHERE u_to = {$user_id} ORDER BY id DESC LIMIT 30", PDO::FETCH_ASSOC);
if ($query->rowCount()>0){


foreach ($query as $veri) {
    // code...
$kBilgisi = $db->query("SELECT * FROM kullanicilar WHERE user_id = '{$veri['u_from']}'")->fetch(PDO::FETCH_ASSOC);
$zamanim = date('Y-m-d H:i:s', $veri['zaman']);


echo '<li class="'.$blurla2.'">
                <div class="item">
                    <img src="/'.$kBilgisi['user_picture'].'" alt="image" class="image">
                    <div class="in">
                        <div>'.$kBilgisi['user_fullname'].'<footer>Gelen Arama: '.time_ago($zamanim).'</footer></div>
                        <span class="text-danger">Cevapsız</span>
                    </div>
                    <div onclick="yogunUyari();" class="icon-box ml-1 bg-whatsapp" style="margin-right: 0px !important;">
                        <i class="fa-solid fa-phone fa-xs"></i>
                    </div>
                </div>
            </li>';


}

}else{

echo '<li>
<div class="error-page">
            <div class="mb-2">
                <img src="assets/img/check.png" alt="alt" class="imaged square w200">
            </div>
            <h1 class="title">Arama Geçmişiniz Boş!</h1>
            <div class="text mb-3">
                Henüz bir aramanız yok.
            </div>

      
        </div>
               </li>';

}

}

?>

            </ul>
         </div>
      </div>
   </div>
</div>
    <!-- Modal Listview -->

<!-- ARAMALARRRRRRRRRRRRRRRRRRRRRRRRRRRRR -->











        <!-- SİKAYET MODAL -->

        <div class="modal fade dialogbox" id="DialogForm2" data-backdrop="static" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title btn-text-danger">Bizimle İletişime Geçin</h5>
                    </div>
                    <div class="modal-body">
                        
<div class="form-group boxed">
                        <div class="input-wrapper">
                            <label class="label" for="address5">Mesajınızı Girin:</label>
                            <textarea id="iletisimAciklama" rows="2" class="form-control"></textarea>
                            <i class="clear-input">
                                <i class="fa-solid fa-circle-xmark"></i>
                            </i>
                        </div>

                    </div>
                   <!--  <br />
                        <center>Mail Adresimiz: <strong>hupto@yandex.com</strong></center> -->
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a href="component-dialog.html#" class="btn btn-text-secondary" data-dismiss="modal">Vazgeç</a>
                            <a onclick="iletisimGonder(<?=$user_id?>)" href="component-dialog.html#" class="btn btn-text-primary" data-dismiss="modal">Gönder</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
<!-- SİKAYET MODAL -->


<div id="toast-gonderildi" class="toast-box toast-center">
            <div class="in">
              <i class="fa-solid fa-circle-check text-success fa-3x"></i>
                <div class="text">
                  Mesajınız bize ulaştı. <br><br> En kısa sürede "<b><?=$myUser['user_email']?></b>" mail adresinize dönüş yapılacaktır.
                </div>
            </div>
        </div>


        <div id="toast-hata" class="toast-box toast-center">
            <div class="in">
               <i class="fa-solid fa-circle-xmark text-danger fa-3x"></i>
                <div class="text">
                  Mesajınız çok kısa. <br><br> Lütfen daha detaylı bir mesaj yazınız.
                </div>
            </div>
        </div>



    <!-- App Sidebar -->
    <div class="modal fade panelbox panelbox-left" id="sidebarPanel" tabindex="-1" role="dialog">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-body p-0">

                    <!-- profile box -->
                    <div class="profileBox">
                        <div class="image-wrapper">
                            <img src="<?=$myUser['user_picture']?>" alt="image" class="imaged rounded myResim">
                        </div>
                        <div class="in">
                            <strong><?=$myUser['user_fullname']?></strong>
                            <div class="text-muted">
                               <i class="fa-solid fa-location-dot"></i>
                               <?=$myUser['user_sehir']?>
                            </div>
                        </div>
                        <a href="javascript:;" class="close-sidebar-button" data-dismiss="modal">
                            <i class="fa-solid fa-circle-xmark"></i>
                        </a>
                    </div>
                    <!-- * profile box -->

                    <ul class="listview flush transparent no-line image-listview mt-2">
                        <li>
                <div class="item">
                    <div class="icon-box bg-warning">
                    
                    <i class="fa-solid fa-coins"></i>
                    </div>
                    <div class="in">
                        <div>Jeton Sayısı</div>
                        <span class="badge badge-warning jetonSayi"><?=$myUser['user_jeton']?></span>
                    </div>
                </div>
                        </li>

                        <li>
                <div class="item">
                    <div class="icon-box bg-danger">
                        <i class="fa-solid fa-heart-circle-plus"></i>
                    </div>
                    <div class="in">
                        <?php 
                            $today = strtotime('today');
    $tomorrow = strtotime('+1 day', $today);
    $bugunBegeni = $db->query("SELECT COUNT(*) FROM begeniler where begenen_id = '{$user_id}' AND zaman >= $today AND zaman <= $tomorrow")->fetchColumn();

    $jetonSayi = $myUser['user_jeton'];

if($jetonSayi>10){
    $begeni_limit = 50;
}else{
    $begeni_limit = 10;
}

    ?>
                        <div>Günlük Beğeni Hakkı</div>
                        <span class="badge badge-danger jetonSayi"><?=$begeni_limit-$bugunBegeni?></span>
                    </div>
                </div>
                        </li>

                                                <li>
                            <a href="javascript:void(0);" data-toggle="modal" data-target="#jetonPaketleri" data-dismiss="modal" class="item">
                                <div class="icon-box bg-success">
                                   <i class="fa-solid fa-shop"></i>
                                </div>
                                <div class="in">
                                    Jeton Marketi
                                </div>
                            </a>
                        </li>

                        <!-- 🎁 PLAY STORE DEĞERLENDİRME - ÜCRETSİZ 5 JETON -->
                        <?php 
                        // IP kontrolü - config.php'deki isTurkeyIP() fonksiyonunu kullan
                        $user_ip = $_SERVER['REMOTE_ADDR'];
                        $is_turkey = isTurkeyIP();
                        
                        // Onaylanmış başvuru kontrolü - 1 kere kullandıysa bir daha gösterme
                        $has_approved_application = false;
                        if (isset($user_id)) {
                            try {
                                $checkApproved = $db->query("SELECT id FROM play_degerlendirme WHERE user_id = '$user_id' AND durum = 1 LIMIT 1");
                                if ($checkApproved && $checkApproved->rowCount() > 0) {
                                    $has_approved_application = true;
                                }
                            } catch (Exception $e) {
                                // Tablo yoksa hata vermesin
                            }
                        }
                        
                        // Sadece Türkiye IP, jeton < 10, yasaklı değil VE daha önce onaylanmamış
                        $excluded_users = [663793]; // Bu ID'ler göremez
                        $has_low_jeton = (isset($myUser) && isset($myUser['user_jeton']) && $myUser['user_jeton'] < 10);
                        $is_allowed = (!isset($user_id) || !in_array($user_id, $excluded_users));
                        
                        $should_show_menu = ($is_turkey && $has_low_jeton && $is_allowed && !$has_approved_application);
                        
                        if ($should_show_menu): 
                        ?>
                        <li>
                            <a href="javascript:void(0);" onclick="playJetonModalAc(); menuGizle();" class="item">
                                <div class="icon-box bg-warning">
                                   <i class="fa-solid fa-gift"></i>
                                </div>
                                <div class="in">
                                    <div>Ücretsiz 5 Jeton Kazan 🎁</div>
                                </div>
                            </a>
                        </li>
                        <?php endif; ?>
                        <!-- * PLAY STORE DEĞERLENDİRME -->

<!--                         <li>
                            <a href="app-components.html" class="item">
                                <div class="icon-box bg-info">
                                    <ion-icon name="color-filter-outline"></ion-icon>
                                </div>
                                <div class="in">
                                    Eşleşme Filtresi
                                </div>
                            </a>
                        </li> -->
                        
                        


<li>
                            <a href="javascript:void(0);" data-toggle="modal" data-target="#ModalBasic" data-dismiss="modal" class="item">
                                <div class="icon-box bg-info">
                                    <i class="fa-solid fa-eye"></i>
                                </div>
                                <div class="in">
                                    <div>Ziyaretçileriniz</div>
                                </div>
                            </a>
                        </li>

                        <li>
                            <a href="javascript:void(0);" data-toggle="modal" data-target="#ModalListviewx" data-dismiss="modal" class="item">
                                <div class="icon-box bg-danger">
                                    <i class="fa-solid fa-thumbs-up"></i>
                                </div>
                                <div class="in">
                                    <div>Sizi Beğenenler</div>
                                </div>
                            </a>
                        </li>
                        <li>
                            <div class="item">
                                <div class="icon-box bg-success">
                                    <i class="fa-solid fa-bell"></i>
                                </div>
                                <div class="in" onclick="bildirimAyar();">
                                   
<?php 

$bildirimim = strpos($myUser['user_onesignal'], "#");

if($bildirimim === false){
    $val1 = "1";
    $chck = "checked";
    $ackapa = "Açık";
}else{
    $val1 = "0";
    $chck = "";
    $ackapa = "Kapalı";
}

?>
 <div>Bildirimler <c id="ackapa"><?=$ackapa?></c></div>

                                    <div class="custom-control custom-switch">
                                        <input type="checkbox" class="custom-control-input"
                                            id="bildirimCheck" value="<?=$val1?>" <?=$chck?>>
                                        <label class="custom-control-label"></label>
                                    </div>
                                </div>
                            </div>
                        </li>
                        <li>
                            <div class="item">
                                <div class="icon-box bg-dark">
                                    <i class="fa-solid fa-moon"></i>
                                </div>
                                <div class="in">
                                    <div>Karanlık Mod</div>
                                    <div class="custom-control custom-switch">
                                        <input type="checkbox" class="custom-control-input dark-mode-switch"
                                            id="darkmodesidebar">
                                        <label class="custom-control-label" for="darkmodesidebar"></label>
                                    </div>
                                </div>
                            </div>
                        </li>


                        <li>
                            <a href="javascript:void(0)" onclick="menuGizle();" data-toggle="modal" data-target="#DialogForm2" class="item">
                                <div class="icon-box bg-primary">
                                   <i class="fa-solid fa-envelope-circle-check"></i>
                                </div>
                                <div class="in">
                                    <div>Bizimle İletişim'e Geç</div>
                                  <!--   <span class="badge badge-danger"></span> -->
                                </div>
                            </a>
                        </li>


<!--                         <li>
                            <a href="https://hupto.cntapi.com/profil.php?id=942197" class="item">
                                <div class="icon-box bg-danger">
                                    <ion-icon name="happy-outline"></ion-icon>
                                </div>
                                <div class="in">
                                    <div>Yönetici Profili</div>
                                </div>
                            </a>
                        </li> -->

                        <li>
                            <a href="https://app.heysen.net/privacy_policy_heysen.html" class="item">
                                <div class="icon-box bg-primary">
                                    <i class="fa-solid fa-fingerprint"></i>
                                </div>
                                <div class="in">
                                    <div>Gizlilik Sözleşmesi</div>
                                  <!--   <span class="badge badge-danger"></span> -->
                                </div>
                            </a>
                        </li>


                    </ul>



                </div>

                <!-- sidebar buttons -->
                <!-- <div class="sidebar-buttons">
                    <a href="javascript:;" class="button">
                        <ion-icon name="person-outline"></ion-icon>
                    </a>
                    <a href="javascript:;" class="button">
                        <ion-icon name="archive-outline"></ion-icon>
                    </a>
                    <a href="javascript:;" class="button">
                        <ion-icon name="settings-outline"></ion-icon>
                    </a>
                    <a href="javascript:;" class="button">
                        <ion-icon name="log-out-outline"></ion-icon>
                    </a>
                </div> -->
                <!-- * sidebar buttons -->
            </div>
        </div>
    </div>
    <!-- * App Sidebar -->
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-110488191-7"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-110488191-7');
</script>








    <!-- ///////////// Js Files ////////////////////  -->
    <!-- Jquery -->
    <script src="assets/js/lib/jquery-3.4.1.min.js"></script>
 <!-- Ionicons -->
<!-- <script type="module" src="https://unpkg.com/ionicons@5.5.2/dist/ionicons/ionicons.js"></script> -->

<!-- <script type="module" src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/5.5.2/ionicons/ionicons.esm.js"></script>
<script nomodule src="https://cdnjs.cloudflare.com/ajax/libs/ionicons/5.5.2/ionicons/ionicons.js"></script> -->

  <script src="assets/fontawesome/js/all.min.js" data-auto-replace-svg="nest"></script>


<!-- <script src="https://kit.fontawesome.com/6d748ebdb5.js" crossorigin="anonymous"></script>
 -->
    <!-- Bootstrap-->
    <script src="assets/js/lib/popper.min.js"></script>
    <script src="assets/js/lib/bootstrap.min.js"></script>
    
    <!-- Owl Carousel -->
    <script src="assets/js/plugins/owl-carousel/owl.carousel.min.js"></script>
    <!-- jQuery Circle Progress -->
    <script src="assets/js/plugins/jquery-circle-progress/circle-progress.min.js"></script>
    <!-- Base Js File -->
    <script src="assets/js/base.js"></script>


<!-- Firebase header.php'de yükleniyor ve initialize ediliyor -->

<script type="text/javascript">

// firebase'e insert ediyoruz
function aramaGonder(gonderici_id, user_id, icerik) {

    const database = firebase.database();
    const ref = database.ref('aramalar');

    var sezerref = ref.child("arama_" + user_id);
    var x = sezerref.set({
        gonderici: gonderici_id,
        alici: user_id,
        msj: icerik
    });

    var useridx = parseInt(user_id);
    var gondericiidx = parseInt(gonderici_id);

    
    setTimeout(function() {
        sezerref.remove();
    }, 500);

}




function gelenArama(alici_id) { // firebase çekme işlemi de burda

    const database = firebase.database();
    ref = database.ref('aramalar');
    ref.on("value", function(snap) {

        if (snap.val()) {

            var msj_id = "arama_" + alici_id;

            // Arama silinmişse çık
            if(!snap.val()[msj_id]) return;

            var yollayan = snap.val()[msj_id].gonderici;
            var alan = snap.val()[msj_id].alici;
            var mesaj = snap.val()[msj_id].msj;

            var cankat = msj_id + " ARAMA = " + yollayan + " BOTUNDAN " + alan + " KULLANICISINA GİDEN " + mesaj;
            aramaPenceresi(yollayan,alan);

//firebase.database().ref('aramalar').off()

        }
    })
}





function aramaPenceresi(u_from, u_to){

  $("#aramaDialog, #garamaDialog").modal("hide");


    var url = "assets/api.php";
    var bilgi = {
      type: 'callapi',
      userid: u_from
    }
    $.post(url,bilgi,function(response) {
      var json = JSON.parse(response);




var aramaEkrani = '<div class="modal fade dialogbox" id="garamaDialog" data-backdrop="static" tabindex="-1" role="dialog" aria-modal="true" style="display: block;"> <div class="modal-dialog" role="document"> <div class="modal-content" style="background: #3e4651; display: contents;"> <div class="Cards"> <div class="Card js-card"> <div class="Card-image"> <div class="Card-imageCallEffect"></div> <div class="Card-imageCallEffect"></div> <div class="Card-imageCallEffect"></div> <div class="Card-imageContent"> <img src="'+json.resim+'"> </div> </div> <div class="Card-content mt-2"> <h3 class="js-callDetail">Gelen Sesli Arama</h3> <h2>'+json.isim+'</h2> <p> <span class="js-callInfo">Yaş: '+json.yas+' = <?=$myUser['user_sehir']?></span> </p> </div> <div class="Card-actions"> <div class="Card-action js-decline"> <div class="Card-actionButton Card-actionButton--decline" onclick="decline1()"> <i class="fa-solid fa-phone-slash fa-xl"></i> </div> <p>Reddet</p> </div> <div class="Card-action js-accept"> <div class="Card-actionButton Card-actionButton--accept" onclick="accept1()">  <i class="fa-solid fa-phone fa-xl"></i> </div> <p>Kabul Et</p> </div> </div> </div> </div> </div> </div> </div>';


$("#gelenAramalar").html(aramaEkrani);

$("#garamaDialog").modal("show");
      
      setTimeout(function(){ 
decline1();
 }, 30000);


   })


}

$( document ).ready(function() {

<?php 
if($myUser['user_call']==0 AND $myUser['user_aramaizin']==1 AND $myUser['user_cinsiyet']=="erkek"){ ?>
   gelenArama(<?=$myUser['user_id']?>);
  
<?php } ?>

});


  function decline1() {
$("#garamaDialog").modal("hide");
  }

  function accept1() {

$("#garamaDialog").modal("hide");
$("#arama_kilit").modal("show");

  }

function buyJeton2(value){
        Android.javaFuncs(value+"-"+"<?=$myUser['user_id']?>")
      }

</script>

  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
  <link rel="stylesheet" href="assets/call/style.css">
<!--     <script  src="assets/call/script.js"></script> -->
<div id="gelenAramalar">
</div>

        <!-- Dialog Iconed Inline -->
        <div class="modal fade dialogbox" id="arama_kilit" data-backdrop="static" tabindex="-1"
            role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                     <div class="modal-icon text-danger">
                        <i class="fa-solid fa-phone-slash fa-xs"></i>
                    </div>
                    <div class="modal-header">
                        <h5 class="modal-title">Aramalar Kilitli!</h5>
                    </div>
                    <div class="modal-body">
                        HeySen içerisinde dilediğiniz gibi arama yapıp sesli görüşebilmek için arama kilidini kaldırın!
                    </div>
                    <div class="modal-footer">
                        <div class="btn-inline">
                            <a onclick="buyJeton2('aramapaket');" href="javascript:void(0)" class="btn btn-text-success" data-dismiss="modal">
                                <i class="fa-solid fa-unlock-keyhole mr-1"></i>
                                Kilidi Aç
                            </a>
                            <a href="component-dialog.html#" class="btn btn-text-secondary" data-dismiss="modal">
                                <i class="fa-solid fa-hourglass mr-1"></i>
                                Sonra
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- * Dialog Iconed Inline -->


<!-- Şans Çarkı Butonu Stili (Global) -->
<style>
@keyframes gentle-shake {
    0%, 50%, 100% { transform: rotate(0deg); }
    55% { transform: rotate(-2deg); }
    60% { transform: rotate(2deg); }
    65% { transform: rotate(-2deg); }
    70% { transform: rotate(2deg); }
    75% { transform: rotate(0deg); }
}

.cark-button {
    animation: gentle-shake 6s ease-in-out infinite;
}

.cark-button:hover {
    animation: none;
    transform: scale(1.05);
    transition: transform 0.2s ease;
}
</style>

<!-- Şans Çarkı Modal (Her Sayfada Kullanılabilir) -->
<div class="modal fade modalbox" id="carkModal" data-backdrop="static" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">🎡 Şans Çarkı</h5>
                <a href="javascript:;" data-dismiss="modal">Kapat</a>
            </div>
            <div class="modal-body">
                <?php include 'assets/cark.php'; ?>
            </div>
        </div>
    </div>
</div>

<script>
// Modal kapanmaya BAŞLARKEN fokusü kaldır (aria-hidden uyarısını önler)
// Event delegation - dinamik modallar için de çalışır
$(document).on('hide.bs.modal', '.modal', function () {
    // Fokus modal'ın kendisinde veya içindeki bir elementte ise blur yap
    if(document.activeElement && (document.activeElement === this || $.contains(this, document.activeElement))) {
        document.activeElement.blur();
    }
});
</script>

</body>

</html>