<?php 
session_start(); 

// Veritabanı bağlantısını yapın
include '../inc/database.php'; 

// Kullanıcının oturum açıp açmadığını kontrol edin
$isLoggedIn = isset($_SESSION['loggedin']) && $_SESSION['loggedin'] === true;
$username = $isLoggedIn ? $_SESSION['username'] : ''; // Kullanıcı adını al
$email = ''; // E-posta adresi için bir değişken tanımlayın
$firstName = ''; // Kullanıcının ismi için bir değişken
$surname = ''; // Kullanıcının soyismi için bir değişken

// Kullanıcı giriş yapmamışsa yönlendirme yap
if (!$isLoggedIn) {
    header('Location: /'); // Giriş sayfasına yönlendir
    exit();
}

// Kullanıcının baş harfini al
$initial = strtoupper(substr($username, 0, 1)); // İlk karakteri al ve büyük harfe çevir

// E-posta adresi ve kullanıcı bilgilerini sorgula
$sql = "SELECT email, first_name, surname FROM kullanicilar WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($email, $firstName, $surname);
$stmt->fetch();
$stmt->close();
?>

<?php include '../inc/head.php'; ?>
<?php include '../inc/header.php'; ?>
<style>
html,body{margin:0;padding:0;background:#000}
.centerWrap.porfileWrap, body{color:#fff}
.centerWrap.porfileWrap{background:#000 !important;display:flex;align-items:flex-start;margin-top:0 !important;padding-top:5px !important}
.centerWrap.porfileWrap .sidebarMain.playersidebarMain{margin-left:0 !important;left:0}
.container-fluid{margin:0;padding:0 12px;background:#000}
.breadcrumb{margin:0 !important;padding:10px 0 !important}
.profileRow{background:#1a1a1a !important;border:1px solid #333;border-radius:10px;padding:18px;color:#fff;margin-top:0 !important}
.mt-theme{display:flex;align-items:center;gap:10px;padding:8px 0}
.mt-theme .breadcrumb{display:flex;flex-wrap:wrap;gap:6px;background:transparent !important;margin:0 !important;padding:0 !important}
.breadcrumb-item, .breadcrumb-item a{color:#fff !important;text-decoration:none}
.breadcrumb-item + .breadcrumb-item::before{color:rgba(255,255,255,.6) !important}
.backBtn{margin-right:8px;border:1px solid rgba(255,255,255,.2);border-radius:8px;padding:8px 12px;color:#fff;background:transparent}
@media (max-width: 768px){
  .mt-theme{flex-wrap:wrap}
  .backBtn{width:36px;height:36px;padding:0;display:inline-flex;align-items:center;justify-content:center}
  .breadcrumb{font-size:14px}
  .centerWrap.porfileWrap{padding-top:56px !important}
}
</style>



<div _ngcontent-ouf-c21="" class="centerWrap porfileWrap">
    <aside _ngcontent-ouf-c27="" class="sidebarMain playersidebarMain">
        <div _ngcontent-ouf-c27="" class="profile-content">
            <div _ngcontent-ouf-c27="" class="edit-user"><!----><!---->                <span class="avatar-holder ng-tns-c27-2 ng-star-inserted"><?php echo $initial; ?></span>

                <div _ngcontent-ouf-c27="" class="user-right"><!----><!---->                    <span class="username ng-tns-c27-2 ng-star-inserted"><?php echo htmlspecialchars($username); ?></span>
</div>
            </div>
            
            
<script>
                document.addEventListener('DOMContentLoaded', function() {
                    const isLoggedIn = <?php echo json_encode($isLoggedIn); ?>;

                    if (isLoggedIn) {
                        // Kullanıcı giriş yapmışsa API'den ana bakiyeyi çek
                        fetch('../api/balanceapi')
                            .then(response => response.json())
                            .then(data => {
                                const balanceText = document.querySelector('.amount'); // .amount sınıfını hedef alıyoruz

                                if (data.status === 'success') {
                                    // Bakiye başarılı bir şekilde çekildiyse span'a yaz
                                    balanceText.textContent = data.ana_bakiye + ' '; // Para birimini ekleyerek yaz
                                } else {
                                    // Hata durumunda kullanıcıya bilgi ver
                                    alert("Hata: " + data.message); // Hata mesajını kullanıcıya göster
                                    console.error(data.message); // Hata mesajını konsola yazdır
                                }
                            })
                            .catch(error => {
                                console.error('Hata:', error);
                                alert("Bir hata oluştu. Lütfen tekrar deneyin."); // Genel hata mesajı
                            });
                    }
                });
            </script>


            
            
            <div _ngcontent-ouf-c27="" class="main-balance">
                <div _ngcontent-ouf-c27="" class="total-balance">
                    <div _ngcontent-ouf-c27="" class="user-balance"><span _ngcontent-ouf-c27="" class="balance-title">Ana Baki̇ye</span><!---->  <span class="amount ng-tns-c27-2 ng-star-inserted">0 
                    </span><!----></div><!----><i _ngcontent-ouf-c27="" class="fa-solid fa-eye eye-icon ng-tns-c27-2 ng-star-inserted"></i>
                </div>
                
                
<div _ngcontent-ouf-c27="" class="buttons-bottom">
    <a _ngcontent-ouf-c27="" class="btn deposit-bc" href="/profile/deposit-withdraw">
        <i _ngcontent-ouf-c27="" class="fa-solid fa-wallet"></i> Para Yatır
    </a>
    <a _ngcontent-ouf-c27="" class="btn withdraw-bc" href="/profile/deposit-withdraw">
        <img _ngcontent-ouf-c27="" class="ng-tns-c27-2" alt="" src="assets/images/withdraw-icon.png"> Para Çekme
    </a>
</div>

            </div>
            <div _ngcontent-ouf-c27="" class="main-balance bonus">
                <div _ngcontent-ouf-c27="" class="user-balance"><span _ngcontent-ouf-c27="" class="balance-title">Bonus Bakiyesi</span><!----><span _ngcontent-ouf-c27="" class="amount ng-tns-c27-2 ng-star-inserted">0 ₺</span><!----></div>
            </div>
        </div>
        <div _ngcontent-ouf-c27="" class="sideSports">
            <ul _ngcontent-ouf-c27="" class="ng-tns-c27-2"><!----><!----><!----><!---->
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2 select active" style="cursor: pointer" type="GROUP">Profilim</a></li><!----><!----><!----><!----><!----><!---->
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/account-statement">İşlem Geçmişi</a></li><!----><!----><!----><!----><!----><!---->
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/bet-history">Casino Geçmişi</a></li><!----><!----><!----><!----><!----><!----><!---->
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/invite">Davet Linki</a></li>
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/referral">Referans Programı</a></li>
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/responsible_gaming">Sorumlu Oyun</a></li>
                
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted">
    <span _ngcontent-ouf-c27="" class="ng-tns-c27-2" aria-disabled="true" style="cursor: default;" type="GROUP"></span>
</li>
                
<li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted">
    <a _ngcontent-ouf-c27="" class="ng-tns-c27-2" href="/promotions.php" style="cursor: pointer;" type="GROUP">Promosyonlar</a>
</li>







                
                
                
                
                
                
                
                
                
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/deposit-withdraw">Para Yatırma/para Çekme</a></li><!----><!----><!----><!----><!----><!----><!---->
                <li _ngcontent-ouf-c27="" style="display: list-item;" class="ng-tns-c27-2 ng-star-inserted"><a _ngcontent-ouf-c27="" class="ng-tns-c27-2" style="cursor: pointer" type="GROUP" href="/profile/kyc">Kyc</a></li><!----><!---->
            </ul>
        </div>
    </aside>




    <app-all-player-account-details _ngcontent-ouf-c46="" _nghost-ouf-c47="" class="ng-star-inserted">
        <div _ngcontent-ouf-c47="" class="container-fluid">
            <div _ngcontent-ouf-c47="" class="row"><app-g1-downline-navigation _ngcontent-ouf-c47="" _nghost-ouf-c48="">
                    <div _ngcontent-ouf-c48="" class="col-12 mt-theme"><button _ngcontent-ouf-c48="" class="btn backBtn"><i _ngcontent-ouf-c48="" class="fa-solid fa-angle-left"></i></button>
                        <ul _ngcontent-ouf-c48="" class="breadcrumb">
<li _ngcontent-ouf-c48="" class="breadcrumb-item">
    <a _ngcontent-ouf-c48="" href="/">Ana Sayfa</a>
</li>
                            <li _ngcontent-ouf-c48="" aria-current="page" class="breadcrumb-item">Profilim</li>
                        </ul>
                    </div>
                </app-g1-downline-navigation>
                <div _ngcontent-ouf-c47="" class="col-12">
                    <div _ngcontent-ouf-c47="" class="profileRow">
                        <form _ngcontent-ouf-c47="" novalidate="" class="ng-untouched ng-pristine ng-valid">
                            <div _ngcontent-ouf-c47="" class="row">
                                <div _ngcontent-ouf-c47="" class="col-lg-9 col-xl-7">
                                    <div _ngcontent-ouf-c47="" class="row">
                                        <div _ngcontent-ouf-c47="" class="col-md-6">
                                            <div _ngcontent-ouf-c47="" class="form-group">
                                                <label _ngcontent-ouf-c47="" class="col-form-label" for="exampleInputEmail1">Kullanıcı Adı</label>                    <input class="form-control cursor-not-allowed" value="<?php echo htmlspecialchars($username); ?>" id="user_name" placeholder="Enter Username" type="text" readonly>
                                        </div>

                                        </div>
                                        <div _ngcontent-ouf-c47="" class="col-md-6">
                                            <div _ngcontent-ouf-c47="" class="form-group">
                                                <label class="col-form-label" for="user_mail">E-Posta</label>
                    <input class="form-control cursor-not-allowed" value="<?php echo htmlspecialchars($email); ?>" id="user_mail" type="email" placeholder="" readonly>
                                                
</div>
                                        </div>
                                        <div _ngcontent-ouf-c47="" class="col-md-6">
                                            <div _ngcontent-ouf-c47="" class="form-group"><label class="col-form-label" for="name2">İsim</label>
    <input class="form-control" formcontrolname="name" id="name2" value="<?php echo htmlspecialchars($firstName); ?>" disabled placeholder="">
                                        </div></div>
                                        
                                        <div _ngcontent-ouf-c47="" class="col-md-6">
                                            <div _ngcontent-ouf-c47="" class="form-group">
                                                <label _ngcontent-ouf-c47="" class="col-form-label" for="exampleInputPassword1">Soy isim</label>
        <input _ngcontent-ouf-c47="" class="form-control ng-untouched ng-pristine" formcontrolname="lastName" id="lastName" value="<?php echo htmlspecialchars($surname); ?>" disabled placeholder="">

                                                   </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form><!----><!---->
                        <div _ngcontent-ouf-c47="" class="row ng-star-inserted"><!---->
                            <div _ngcontent-ouf-c47="" class="col-lg-9 col-xl-7 ng-star-inserted">
                                <div _ngcontent-ouf-c47="" class="secTitle mt-3">
                                    <h5 _ngcontent-ouf-c47="">Şifreyi Değiştir</h5>
                                </div>
                         <form id="changePasswordForm" autocomplete="off" novalidate="" class="ng-untouched ng-pristine ng-invalid">
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-form-label">Yeni Şifre</label>
                <input autocomplete="nope" class="form-control" id="newPwd" required="" type="password" placeholder="Yeni Şifre" readonly="" onfocus="$(this).removeAttr('readonly');">
                <span class="eyeIcon fa fa-fw fa-eye" onclick="togglePassword('newPwd', this)"></span>
                <span class="longError"></span>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-form-label">Şifreyi Doğrula</label>
                <input autocomplete="nope" class="form-control" id="confirmPass" required="" type="password" placeholder="Şifreyi Doğrula" readonly="" onfocus="$(this).removeAttr('readonly');">
                <span class="eyeIcon fa fa-fw fa-eye" onclick="togglePassword('confirmPass', this)"></span>
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                <label class="col-form-label">Eski Şifre</label>
                <input autocomplete="false" class="form-control" id="oldPwd" required="" type="password" placeholder="Eski Şifre" readonly="" onfocus="$(this).removeAttr('readonly');">
                <span class="eyeIcon fa fa-fw fa-eye" onclick="togglePassword('oldPwd', this)"></span>
            </div>
        </div>
        <div class="col-12 d-flex justify-content-end">
            <button class="btn btn-primary" type="button" id="changePwdBtn">Şifreyi Değiştir</button>
        </div>
    </div>
</form>
<script>function togglePassword(fieldId, icon) {
    var passwordField = document.getElementById(fieldId);
    if (passwordField.type === "password") {
        passwordField.type = "text"; // Şifreyi göster
        icon.classList.remove("fa-eye");
        icon.classList.add("fa-eye-slash"); // Göster ikonu değiştir
    } else {
        passwordField.type = "password"; // Şifreyi gizle
        icon.classList.remove("fa-eye-slash");
        icon.classList.add("fa-eye"); // Gizleme ikonu değiştir
    }
}
</script>
<script>
$(document).ready(function() {
    $('#changePwdBtn').click(function() {
        var newPwd = $('#newPwd').val();
        var confirmPass = $('#confirmPass').val();
        var oldPwd = $('#oldPwd').val();

        // Şifrelerin aynı olup olmadığını kontrol et
        if (newPwd !== confirmPass) {
            Swal.fire({
                icon: 'error',
                title: 'Hata',
                text: 'Yeni şifreler uyuşmuyor!',
                confirmButtonText: 'Tamam'
            });
            return;
        }

        // Eski şifre ve yeni şifrelerin boş olup olmadığını kontrol et
        if (oldPwd === "" || newPwd === "") {
            Swal.fire({
                icon: 'error',
                title: 'Hata',
                text: 'Lütfen tüm alanları doldurun!',
                confirmButtonText: 'Tamam'
            });
            return;
        }

        // Backend'e AJAX ile veri gönderme
        $.ajax({
            type: "POST",
            url: "../profile/changePassword.php", // Backend dosyanız
            data: { 
                oldPwd: oldPwd, 
                newPwd: newPwd 
            },
            success: function(response) {
                var result = JSON.parse(response);
                if (result.status === "success") {
                    Swal.fire({
                        icon: 'success',
                        title: 'Başarılı',
                        text: 'Şifre başarıyla değiştirildi!',
                        confirmButtonText: 'Tamam'
                    });
                } else if (result.status === "error") {
                    Swal.fire({
                        icon: 'error',
                        title: 'Hata',
                        text: result.message,
                        confirmButtonText: 'Tamam'
                    });
                }
            },
            error: function() {
                Swal.fire({
                    icon: 'error',
                    title: 'Hata',
                    text: 'Sunucu hatası. Lütfen tekrar deneyin.',
                    confirmButtonText: 'Tamam'
                });
            }
        });
    });
});

</script>
                    

        </div><app-exposure-limit _ngcontent-ouf-c47="" _nghost-ouf-c50="">
            <div _ngcontent-ouf-c50="" aria-hidden="true" aria-labelledby="admin-add-user" class="modal fade" id="exposure-limit" role="dialog" tabindex="-1">
                <div _ngcontent-ouf-c50="" class="modal-dialog" role="document" style="width: 300px;">
                    <div _ngcontent-ouf-c50="" class="modal-content">
                        <div _ngcontent-ouf-c50="" class="modal-header"><button _ngcontent-ouf-c50="" aria-label="Close" class="close" data-dismiss="modal" style="color: #fff; opacity: 1;" type="button"><span _ngcontent-ouf-c50="" aria-hidden="true">×</span></button>
                            <h4 _ngcontent-ouf-c50="" class="modal-title">Change Exposure Limit</h4>
                        </div>
                        <div _ngcontent-ouf-c50="" class="modal-body">
                            <div _ngcontent-ouf-c50="" class="row margin-0">
                                <div _ngcontent-ouf-c50="" class="col-sm-6 username pl-0">
                                    <div _ngcontent-ouf-c50="" class="form-group">
                                        <div _ngcontent-ouf-c50="" class="box-text">Exposure Limit: <span _ngcontent-ouf-c50="">&nbsp;</span><span _ngcontent-ouf-c50=""></span></div>
                                    </div>
                                </div>
                            </div>
                            <form _ngcontent-ouf-c50="" novalidate="" class="ng-untouched ng-pristine ng-invalid">
                                <div _ngcontent-ouf-c50="" class="row margin-0 ">
                                    <div _ngcontent-ouf-c50="" class="col-sm-12 username pl-0">
                                        <div _ngcontent-ouf-c50="" class="form-group">
                                            <div _ngcontent-ouf-c50="" class="box-text">New</div><input _ngcontent-ouf-c50="" autocomplete="off" class="form-control ng-untouched ng-pristine ng-invalid" formcontrolname="exposureLimit" id="exposure" onfocus="this.removeAttribute('readonly');" readonly="" type="text"><app-validation-message _ngcontent-ouf-c50="" _nghost-ouf-c49=""><span _ngcontent-ouf-c49="" class="validation-message">
                                                </span></app-validation-message>
                                        </div>
                                    </div>
                                </div>
                                <div _ngcontent-ouf-c50="" class="row margin-0">
                                    <div _ngcontent-ouf-c50="" class="col-sm-12 username pl-0">
                                        <div _ngcontent-ouf-c50="" class="form-group">
                                            <div _ngcontent-ouf-c50="" class="box-text">Password</div><input _ngcontent-ouf-c50="" autocomplete="current-password" class="form-control ng-untouched ng-pristine ng-invalid" formcontrolname="password" id="password" onfocus="this.removeAttribute('readonly');" readonly="" type="password" value="password"><app-validation-message _ngcontent-ouf-c50="" _nghost-ouf-c49=""><span _ngcontent-ouf-c49="" class="validation-message">
                                                </span></app-validation-message>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div _ngcontent-ouf-c50="" class="modal-footer" style="padding: 0;"><button _ngcontent-ouf-c50="" class="btn btn-default" data-dismiss="modal" style="border-radius: 0 0 0 10px; width: 50%; padding: 16px 12px;" type="button">Close</button><button _ngcontent-ouf-c50="" class="btn btn-primary" style="width: 50%; margin: 0; border-radius: 0 0 10px 0; padding: 16px 12px;" type="button">Save changes</button></div>
                    </div>
                </div>
            </div>
        </app-exposure-limit><app-confirm-box _ngcontent-ouf-c47="" _nghost-ouf-c51="">
            <div _ngcontent-ouf-c51="" aria-hidden="true" aria-labelledby="exampleModalLabel" class="modal fade" data-backdrop="static" data-keyboard="false" id="confirmbox" role="dialog" tabindex="-1">
                <div _ngcontent-ouf-c51="" class="modal-dialog" role="document">
                    <div _ngcontent-ouf-c51="" class="modal-content" style="width: 320px !important;">
                        <div _ngcontent-ouf-c51="" class="modal-header">
                            <h5 _ngcontent-ouf-c51="" class="modal-title" id="exampleModalLabel">Confirm</h5>
                        </div>
                        <div _ngcontent-ouf-c51="" class="modal-body"> Are you sure you want to apply this change? </div>
                        <div _ngcontent-ouf-c51="" class="modal-footer" style="float: right;"><button _ngcontent-ouf-c51="" class="btn btn-primary" type="button">Yes</button><button _ngcontent-ouf-c51="" class="btn btn-secondary" data-dismiss="modal" type="button">No</button></div>
                    </div>
                </div>
            </div>
        </app-confirm-box>
    </app-all-player-account-details>